LLVM  4.0.0
LowLevelType.cpp
Go to the documentation of this file.
1 //===-- llvm/CodeGen/GlobalISel/LowLevelType.cpp --------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file This file implements the more header-heavy bits of the LLT class to
11 /// avoid polluting users' namespaces.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "llvm/IR/DataLayout.h"
17 #include "llvm/IR/DerivedTypes.h"
19 using namespace llvm;
20 
21 LLT::LLT(Type &Ty, const DataLayout &DL) {
22  if (auto VTy = dyn_cast<VectorType>(&Ty)) {
23  SizeInBits = VTy->getElementType()->getPrimitiveSizeInBits();
24  ElementsOrAddrSpace = VTy->getNumElements();
25  Kind = ElementsOrAddrSpace == 1 ? Scalar : Vector;
26  } else if (auto PTy = dyn_cast<PointerType>(&Ty)) {
27  Kind = Pointer;
28  SizeInBits = DL.getTypeSizeInBits(&Ty);
29  ElementsOrAddrSpace = PTy->getAddressSpace();
30  } else if (Ty.isSized()) {
31  // Aggregates are no different from real scalars as far as GlobalISel is
32  // concerned.
33  Kind = Scalar;
34  SizeInBits = DL.getTypeSizeInBits(&Ty);
35  ElementsOrAddrSpace = 1;
36  assert(SizeInBits != 0 && "invalid zero-sized type");
37  } else {
38  Kind = Invalid;
39  SizeInBits = ElementsOrAddrSpace = 0;
40  }
41 }
42 
44  if (VT.isVector()) {
45  SizeInBits = VT.getVectorElementType().getSizeInBits();
46  ElementsOrAddrSpace = VT.getVectorNumElements();
47  Kind = ElementsOrAddrSpace == 1 ? Scalar : Vector;
48  } else if (VT.isValid()) {
49  // Aggregates are no different from real scalars as far as GlobalISel is
50  // concerned.
51  Kind = Scalar;
52  SizeInBits = VT.getSizeInBits();
53  ElementsOrAddrSpace = 1;
54  assert(SizeInBits != 0 && "invalid zero-sized type");
55  } else {
56  Kind = Invalid;
57  SizeInBits = ElementsOrAddrSpace = 0;
58  }
59 }
60 
61 void LLT::print(raw_ostream &OS) const {
62  if (isVector())
63  OS << "<" << ElementsOrAddrSpace << " x s" << SizeInBits << ">";
64  else if (isPointer())
65  OS << "p" << getAddressSpace();
66  else if (isValid()) {
67  assert(isScalar() && "unexpected type");
68  OS << "s" << getScalarSizeInBits();
69  } else
70  llvm_unreachable("trying to print an invalid type");
71 }
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:102
unsigned getSizeInBits() const
bool isPointer() const
Definition: LowLevelType.h:92
unsigned getScalarSizeInBits() const
Definition: LowLevelType.h:110
unsigned getAddressSpace() const
Definition: LowLevelType.h:114
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:254
unsigned getVectorNumElements() const
MVT - Machine Value Type.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
bool isVector() const
isVector - Return true if this is a vector value type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isScalar() const
Definition: LowLevelType.h:90
bool isValid() const
isValid - Return true if this is a valid simple valuetype.
bool isValid() const
Definition: LowLevelType.h:88
void print(raw_ostream &OS) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:533
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
MVT getVectorElementType() const
bool isVector() const
Definition: LowLevelType.h:94