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");
143 return IsPointer == RHS.IsPointer && IsVector == RHS.IsVector &&
144 RHS.RawData == RawData;
162 typedef int BitFieldInfo[2];
170 static const constexpr BitFieldInfo ScalarSizeFieldInfo{32, 0};
174 static const constexpr BitFieldInfo PointerSizeFieldInfo{16, 0};
175 static const constexpr BitFieldInfo PointerAddressSpaceFieldInfo{
176 23, PointerSizeFieldInfo[0] + PointerSizeFieldInfo[1]};
180 static const constexpr BitFieldInfo VectorElementsFieldInfo{16, 0};
181 static const constexpr BitFieldInfo VectorSizeFieldInfo{
182 32, VectorElementsFieldInfo[0] + VectorElementsFieldInfo[1]};
187 static const constexpr BitFieldInfo PointerVectorElementsFieldInfo{16, 0};
188 static const constexpr BitFieldInfo PointerVectorSizeFieldInfo{
190 PointerVectorElementsFieldInfo[1] + PointerVectorElementsFieldInfo[0]};
191 static const constexpr BitFieldInfo PointerVectorAddressSpaceFieldInfo{
192 23, PointerVectorSizeFieldInfo[1] + PointerVectorSizeFieldInfo[0]};
194 uint64_t IsPointer : 1;
195 uint64_t IsVector : 1;
196 uint64_t RawData : 62;
198 static uint64_t getMask(
const BitFieldInfo FieldInfo) {
199 const int FieldSizeInBits = FieldInfo[0];
200 return (((uint64_t)1) << FieldSizeInBits) - 1;
202 static uint64_t maskAndShift(uint64_t Val, uint64_t
Mask, uint8_t Shift) {
203 assert(Val <= Mask &&
"Value too large for field");
204 return (Val & Mask) << Shift;
206 static uint64_t maskAndShift(uint64_t Val,
const BitFieldInfo FieldInfo) {
207 return maskAndShift(Val, getMask(FieldInfo), FieldInfo[1]);
209 uint64_t getFieldValue(
const BitFieldInfo FieldInfo)
const {
210 return getMask(FieldInfo) & (RawData >> FieldInfo[1]);
213 void init(
bool IsPointer,
bool IsVector, uint16_t NumElements,
215 this->IsPointer = IsPointer;
216 this->IsVector = IsVector;
219 RawData = maskAndShift(SizeInBits, ScalarSizeFieldInfo);
221 RawData = maskAndShift(SizeInBits, PointerSizeFieldInfo) |
222 maskAndShift(AddressSpace, PointerAddressSpaceFieldInfo);
224 assert(NumElements > 1 &&
"invalid number of vector elements");
226 RawData = maskAndShift(NumElements, VectorElementsFieldInfo) |
227 maskAndShift(SizeInBits, VectorSizeFieldInfo);
230 maskAndShift(NumElements, PointerVectorElementsFieldInfo) |
231 maskAndShift(SizeInBits, PointerVectorSizeFieldInfo) |
232 maskAndShift(AddressSpace, PointerVectorAddressSpaceFieldInfo);
236 uint64_t getUniqueRAWLLTData()
const {
237 return ((uint64_t)RawData) << 2 | ((uint64_t)IsPointer) << 1 |
238 ((uint64_t)IsVector);
250 Invalid.IsPointer =
true;
255 Invalid.IsVector =
true;
259 uint64_t Val = Ty.getUniqueRAWLLTData();
269 #endif // LLVM_SUPPORT_LOWLEVELTYPEIMPL_H
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
static LLT vector(uint16_t NumElements, LLT ScalarTy)
Get a low-level vector of some number of elements and element type.
This class represents lattice values for constants.
unsigned getScalarSizeInBits() const
bool operator!=(const LLT &RHS) const
LLT(bool isPointer, bool isVector, uint16_t NumElements, unsigned SizeInBits, unsigned AddressSpace)
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
initializer< Ty > init(const Ty &Val)
unsigned getAddressSpace() const
static bool isEqual(const LLT &LHS, const LLT &RHS)
void print(raw_ostream &OS) const
static LLT getTombstoneKey()
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
static unsigned getHashValue(const LLT &Ty)
bool operator==(const LLT &RHS) 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).
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
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...
static LLT vector(uint16_t NumElements, unsigned ScalarSizeInBits)
Get a low-level vector of some number of elements and element width.