LLVM: include/llvm/CodeGenTypes/LowLevelType.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#ifndef LLVM_CODEGEN_LOWLEVELTYPE_H
27#define LLVM_CODEGEN_LOWLEVELTYPE_H
28
32#include
33
34namespace llvm {
35
37class raw_ostream;
38
40public:
41
42 static constexpr LLT scalar(unsigned SizeInBits) {
43 return LLT{false, false, true,
45 0};
46 }
47
48
50 return LLT{false, false,
52 0,
53 0};
54 }
55
56
58 assert(SizeInBits > 0 && "invalid pointer size");
59 return LLT{true, false, false,
61 }
62
63
65 assert(!EC.isScalar() && "invalid number of vector elements");
66 return LLT{false, true, false,
67 EC, ScalarSizeInBits, 0};
68 }
69
70
72 assert(!EC.isScalar() && "invalid number of vector elements");
73 assert(!ScalarTy.isVector() && "invalid vector element type");
75 true,
76 false,
77 EC,
80 }
81
82
83
86 }
87
88
91 }
92
93
96 }
97
98
99
101 unsigned ScalarSizeInBits) {
103 }
104
105
106
109 }
110
111
112
114 unsigned ScalarSizeInBits) {
116 }
117
118
119
122 }
123
125 return EC.isScalar() ? ScalarTy : LLT::vector(EC, ScalarTy);
126 }
127
129 assert(ScalarSize <= std::numeric_limits::max() &&
130 "Not enough bits in LLT to represent size");
132 }
133
137 : LLT() {
139 }
141 : IsScalar(false), IsPointer(false), IsVector(false), RawData(0) {}
142
144
145 constexpr bool isValid() const { return IsScalar || RawData != 0; }
146 constexpr bool isScalar() const { return IsScalar; }
147 constexpr bool isToken() const { return IsScalar && RawData == 0; };
150 return isValid() && IsPointer && !IsVector;
151 }
154 return IsPointer && isValid();
155 }
156
157
158
162 "Possible incorrect use of LLT::getNumElements() for "
163 "scalable vector. Scalable flag may be dropped, use "
164 "LLT::getElementCount() instead");
166 }
167
168
169
172 return getFieldValue(VectorScalableFieldInfo);
173 }
174
175
176
178
179
180
182
184 assert(IsVector && "cannot get number of elements on scalar/aggregate");
187 }
188
189
195 EC.isScalable());
196 }
197
198
199
203 }
204
207 }
208
209
210
213 }
214
215
216
217
220 "invalid to directly change element size for pointers");
223 }
224
225
226
229 }
230
231
232
233
237 "cannot divide scalar of size zero");
242 }
243
246 }
247
248
249
250
255 }
256
258 }
259
262 }
263
266 return getFieldValue(PointerSizeFieldInfo);
267 return getFieldValue(ScalarSizeFieldInfo);
268 }
269
272 "cannot get address space of non-pointer type");
273 return getFieldValue(PointerAddressSpaceFieldInfo);
274 }
275
276
278 assert(isVector() && "cannot get element type of scalar/aggregate");
279 if (IsPointer)
281 else
283 }
284
286
287#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
289#endif
290
292 return IsPointer == RHS.IsPointer && IsVector == RHS.IsVector &&
293 IsScalar == RHS.IsScalar && RHS.RawData == RawData;
294 }
295
297
300
301private:
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334 typedef int BitFieldInfo[2];
335
336
337
338
339
340
341
342 static const constexpr BitFieldInfo ScalarSizeFieldInfo{32, 29};
343
344
345
346 static const constexpr BitFieldInfo PointerSizeFieldInfo{16, 45};
347 static const constexpr BitFieldInfo PointerAddressSpaceFieldInfo{24, 21};
348
349
350
351
352 static const constexpr BitFieldInfo VectorElementsFieldInfo{16, 5};
353 static const constexpr BitFieldInfo VectorScalableFieldInfo{1, 0};
354
355
356
357
358
359
364
365 static constexpr uint64_t getMask(const BitFieldInfo FieldInfo) {
366 const int FieldSizeInBits = FieldInfo[0];
367 return (((uint64_t)1) << FieldSizeInBits) - 1;
368 }
371 assert(Val <= Mask && "Value too large for field");
372 return (Val & Mask) << Shift;
373 }
375 const BitFieldInfo FieldInfo) {
376 return maskAndShift(Val, getMask(FieldInfo), FieldInfo[1]);
377 }
378
379 constexpr uint64_t getFieldValue(const BitFieldInfo FieldInfo) const {
380 return getMask(FieldInfo) & (RawData >> FieldInfo[1]);
381 }
382
383 constexpr void init(bool IsPointer, bool IsVector, bool IsScalar,
384 ElementCount EC, uint64_t SizeInBits,
386 assert(SizeInBits <= std::numeric_limits::max() &&
387 "Not enough bits in LLT to represent size");
389 this->IsVector = IsVector;
390 this->IsScalar = IsScalar;
391 if (IsPointer) {
392 RawData = maskAndShift(SizeInBits, PointerSizeFieldInfo) |
393 maskAndShift(AddressSpace, PointerAddressSpaceFieldInfo);
394 } else {
395 RawData = maskAndShift(SizeInBits, ScalarSizeFieldInfo);
396 }
397 if (IsVector) {
398 RawData |= maskAndShift(EC.getKnownMinValue(), VectorElementsFieldInfo) |
399 maskAndShift(EC.isScalable() ? 1 : 0, VectorScalableFieldInfo);
400 }
401 }
402
403public:
405 return ((uint64_t)RawData) << 3 | ((uint64_t)IsScalar) << 2 |
407 }
408};
409
412 return OS;
413}
414
418 Invalid.IsPointer = true;
420 }
425 }
429 }
432 }
433};
434
435}
436
437#endif
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file defines DenseMapInfo traits for DenseMap.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static constexpr ElementCount getScalable(ScalarTy MinVal)
static constexpr ElementCount getFixed(ScalarTy MinVal)
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
static constexpr LLT float64()
Get a 64-bit IEEE double value.
void print(raw_ostream &OS) const
constexpr bool isScalableVector() const
Returns true if the LLT is a scalable vector.
static constexpr LLT scalarOrVector(ElementCount EC, uint64_t ScalarSize)
constexpr unsigned getScalarSizeInBits() const
constexpr LLT(bool isPointer, bool isVector, bool isScalar, ElementCount EC, uint64_t SizeInBits, unsigned AddressSpace)
constexpr bool isScalar() const
static constexpr LLT scalable_vector(unsigned MinNumElements, unsigned ScalarSizeInBits)
Get a low-level scalable vector of some number of elements and element width.
constexpr bool operator==(const LLT &RHS) const
constexpr LLT changeElementType(LLT NewEltTy) const
If this type is a vector, return a vector with the same number of elements but the new element type.
constexpr LLT multiplyElements(int Factor) const
Produce a vector type that is Factor times bigger, preserving the element type.
static constexpr LLT vector(ElementCount EC, unsigned ScalarSizeInBits)
Get a low-level vector of some number of elements and element width.
constexpr bool isPointerVector() const
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr bool isValid() const
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
constexpr bool operator!=(const LLT &RHS) const
constexpr bool isToken() const
constexpr bool isVector() const
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
constexpr bool isScalable() const
Returns true if the LLT is a scalable vector.
constexpr uint64_t getUniqueRAWLLTData() const
constexpr bool isByteSized() const
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
constexpr bool isPointer() const
constexpr LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
static constexpr LLT vector(ElementCount EC, LLT ScalarTy)
Get a low-level vector of some number of elements and element type.
constexpr ElementCount getElementCount() const
constexpr LLT changeElementSize(unsigned NewEltSize) const
If this type is a vector, return a vector with the same number of elements but the new element size.
static constexpr LLT fixed_vector(unsigned NumElements, LLT ScalarTy)
Get a low-level fixed-width vector of some number of elements and element type.
static constexpr LLT float16()
Get a 16-bit IEEE half value.
constexpr unsigned getAddressSpace() const
static constexpr LLT fixed_vector(unsigned NumElements, unsigned ScalarSizeInBits)
Get a low-level fixed-width vector of some number of elements and element width.
constexpr bool isPointerOrPointerVector() const
constexpr bool isFixedVector() const
Returns true if the LLT is a fixed vector.
static constexpr LLT token()
Get a low-level token; just a scalar with zero bits (or no size).
constexpr LLT changeElementCount(ElementCount EC) const
Return a vector or scalar with the same element type and the new element count.
LLVM_DUMP_METHOD void dump() const
constexpr LLT getScalarType() const
constexpr TypeSize getSizeInBytes() const
Returns the total size of the type in bytes, i.e.
static constexpr LLT scalable_vector(unsigned MinNumElements, LLT ScalarTy)
Get a low-level scalable vector of some number of elements and element type.
static constexpr LLT scalarOrVector(ElementCount EC, LLT ScalarTy)
static constexpr LLT float32()
Get a 32-bit IEEE float value.
constexpr LLT divide(int Factor) const
Return a type that is Factor times smaller.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
constexpr bool isKnownMultipleOf(ScalarTy RHS) const
This function tells the caller whether the element count is known at compile time to be a multiple of...
constexpr ScalarTy getFixedValue() const
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
void reportInvalidSizeRequest(const char *Msg)
Reports a diagnostic message to indicate an invalid size request has been done on a scalable vector.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
static LLT getTombstoneKey()
static bool isEqual(const LLT &LHS, const LLT &RHS)
static unsigned getHashValue(const LLT &Ty)
An information struct used to provide DenseMap with the various necessary components for a given valu...