27 #ifndef LLVM_SUPPORT_LOWLEVELTYPEIMPL_H
28 #define LLVM_SUPPORT_LOWLEVELTYPEIMPL_H
44 assert(SizeInBits > 0 &&
"invalid scalar size");
45 return LLT{
false,
false, 0,
51 assert(SizeInBits > 0 &&
"invalid pointer size");
52 return LLT{
true,
false, 0,
53 SizeInBits, AddressSpace};
58 static LLT vector(uint16_t NumElements,
unsigned ScalarSizeInBits) {
59 assert(NumElements > 1 &&
"invalid number of vector elements");
60 assert(ScalarSizeInBits > 0 &&
"invalid vector element size");
61 return LLT{
false,
true, NumElements,
67 assert(NumElements > 1 &&
"invalid number of vector elements");
76 init(isPointer, isVector, NumElements, SizeInBits, AddressSpace);
82 bool isValid()
const {
return RawData != 0; }
93 assert(IsVector &&
"cannot get number of elements on scalar/aggregate");
95 return getFieldValue(VectorElementsFieldInfo);
97 return getFieldValue(PointerVectorElementsFieldInfo);
108 assert(RawData != 0 &&
"Invalid Type");
111 return getFieldValue(ScalarSizeFieldInfo);
113 return getFieldValue(PointerSizeFieldInfo);
116 return getFieldValue(VectorSizeFieldInfo);
118 return getFieldValue(PointerVectorSizeFieldInfo);
123 assert(RawData != 0 &&
"Invalid Type");
124 assert(IsPointer &&
"cannot get address space of non-pointer type");
126 return getFieldValue(PointerAddressSpaceFieldInfo);
128 return getFieldValue(PointerVectorAddressSpaceFieldInfo);
133 assert(
isVector() &&
"cannot get element type of scalar/aggregate");
146 return LLT{
false, IsVector ?
true :
false,
155 assert(!IsPointer &&
"cannot change size of this type");
156 return LLT{
false, IsVector ?
true :
false,
170 return LLT{
false,
true,
180 return LLT{IsPointer ?
true :
false,
true,
188 return IsPointer == RHS.IsPointer && IsVector == RHS.IsVector &&
189 RHS.RawData == RawData;
206 typedef int BitFieldInfo[2];
214 static const constexpr BitFieldInfo ScalarSizeFieldInfo{32, 0};
218 static const constexpr BitFieldInfo PointerSizeFieldInfo{16, 0};
219 static const constexpr BitFieldInfo PointerAddressSpaceFieldInfo{
220 23, PointerSizeFieldInfo[0] + PointerSizeFieldInfo[1]};
224 static const constexpr BitFieldInfo VectorElementsFieldInfo{16, 0};
225 static const constexpr BitFieldInfo VectorSizeFieldInfo{
226 32, VectorElementsFieldInfo[0] + VectorElementsFieldInfo[1]};
231 static const constexpr BitFieldInfo PointerVectorElementsFieldInfo{16, 0};
232 static const constexpr BitFieldInfo PointerVectorSizeFieldInfo{
234 PointerVectorElementsFieldInfo[1] + PointerVectorElementsFieldInfo[0]};
235 static const constexpr BitFieldInfo PointerVectorAddressSpaceFieldInfo{
236 23, PointerVectorSizeFieldInfo[1] + PointerVectorSizeFieldInfo[0]};
238 uint64_t IsPointer : 1;
239 uint64_t IsVector : 1;
240 uint64_t RawData : 62;
242 static uint64_t getMask(
const BitFieldInfo FieldInfo) {
243 const int FieldSizeInBits = FieldInfo[0];
244 return (((uint64_t)1) << FieldSizeInBits) - 1;
246 static uint64_t maskAndShift(uint64_t Val, uint64_t
Mask, uint8_t Shift) {
247 assert(Val <= Mask &&
"Value too large for field");
248 return (Val & Mask) << Shift;
250 static uint64_t maskAndShift(uint64_t Val,
const BitFieldInfo FieldInfo) {
251 return maskAndShift(Val, getMask(FieldInfo), FieldInfo[1]);
253 uint64_t getFieldValue(
const BitFieldInfo FieldInfo)
const {
254 return getMask(FieldInfo) & (RawData >> FieldInfo[1]);
257 void init(
bool IsPointer,
bool IsVector, uint16_t NumElements,
259 this->IsPointer = IsPointer;
260 this->IsVector = IsVector;
263 RawData = maskAndShift(SizeInBits, ScalarSizeFieldInfo);
265 RawData = maskAndShift(SizeInBits, PointerSizeFieldInfo) |
266 maskAndShift(AddressSpace, PointerAddressSpaceFieldInfo);
268 assert(NumElements > 1 &&
"invalid number of vector elements");
270 RawData = maskAndShift(NumElements, VectorElementsFieldInfo) |
271 maskAndShift(SizeInBits, VectorSizeFieldInfo);
274 maskAndShift(NumElements, PointerVectorElementsFieldInfo) |
275 maskAndShift(SizeInBits, PointerVectorSizeFieldInfo) |
276 maskAndShift(AddressSpace, PointerVectorAddressSpaceFieldInfo);
289 Invalid.IsPointer =
true;
294 Invalid.IsVector =
true;
298 uint64_t Val = ((uint64_t)Ty.RawData) << 2 | ((uint64_t)Ty.IsPointer) << 1 |
299 ((uint64_t)Ty.IsVector);
309 #endif // LLVM_SUPPORT_LOWLEVELTYPEIMPL_H
LLT doubleElements() const
Get a low-level type with twice the size of the original, by doubling the number of vector elements o...
static LLT vector(uint16_t NumElements, LLT ScalarTy)
Get a low-level vector of some number of elements and element type.
bool operator!=(const LLT &RHS) const
LLT(bool isPointer, bool isVector, uint16_t NumElements, unsigned SizeInBits, unsigned AddressSpace)
unsigned getScalarSizeInBits() const
unsigned getAddressSpace() const
bool operator==(const LLT &RHS) const
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
LLT doubleScalarSize() const
Get a low-level type with twice the size of the original, by doubling the size of the scalar type inv...
Function Alias Analysis false
initializer< Ty > init(const Ty &Val)
static bool isEqual(const LLT &LHS, const LLT &RHS)
static LLT getTombstoneKey()
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
static unsigned getHashValue(const LLT &Ty)
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
LLT halfScalarSize() const
Get a low-level type with half the size of the original, by halving the size of the scalar type invol...
LLT halfElements() const
Get a low-level type with half the size of the original, by halving the number of vector elements of ...
void print(raw_ostream &OS) const
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static LLT pointer(uint16_t AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space (defaulting to 0).
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
This class implements an extremely fast bulk output stream that can only output to a stream...
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
static LLT vector(uint16_t NumElements, unsigned ScalarSizeInBits)
Get a low-level vector of some number of elements and element width.