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
33#include
34
35namespace llvm {
36
39
41public:
42
43 static constexpr LLT scalar(unsigned SizeInBits) {
44 return LLT{false, false, true,
46 0};
47 }
48
49
51 return LLT{false, false,
53 0,
54 0};
55 }
56
57
59 assert(SizeInBits > 0 && "invalid pointer size");
60 return LLT{true, false, false,
62 }
63
64
66 assert(!EC.isScalar() && "invalid number of vector elements");
67 return LLT{false, true, false,
68 EC, ScalarSizeInBits, 0};
69 }
70
71
73 assert(!EC.isScalar() && "invalid number of vector elements");
74 assert(!ScalarTy.isVector() && "invalid vector element type");
76 true,
77 false,
78 EC,
81 }
82
83
84
88
89
93
94
98
99
100
102 unsigned ScalarSizeInBits) {
104 }
105
106
107
111
112
113
115 unsigned ScalarSizeInBits) {
117 }
118
119
120
124
126 return EC.isScalar() ? ScalarTy : LLT::vector(EC, ScalarTy);
127 }
128
130 assert(ScalarSize <= std::numeric_limits::max() &&
131 "Not enough bits in LLT to represent size");
133 }
134
143
145
146 constexpr bool isValid() const { return IsScalar || RawData != 0; }
147 constexpr bool isScalar() const { return IsScalar; }
148 constexpr bool isToken() const { return IsScalar && RawData == 0; };
151 return isValid() && IsPointer && !IsVector;
152 }
155 return IsPointer && isValid();
156 }
157
158
159
163 "Possible incorrect use of LLT::getNumElements() for "
164 "scalable vector. Scalable flag may be dropped, use "
165 "LLT::getElementCount() instead");
167 }
168
169
170
173 return getFieldValue(VectorScalableFieldInfo);
174 }
175
176
177
179
180
181
183
185 assert(IsVector && "cannot get number of elements on scalar/aggregate");
188 }
189
190
196 EC.isScalable());
197 }
198
199
200
205
209
210
211
215
216
217
218
221 "invalid to directly change element size for pointers");
224 }
225
226
227
231
232
233
234
238 "cannot divide scalar of size zero");
243 }
244
247 }
248
249
250
251
260
264
267 return getFieldValue(PointerSizeFieldInfo);
268 return getFieldValue(ScalarSizeFieldInfo);
269 }
270
273 "cannot get address space of non-pointer type");
274 return getFieldValue(PointerAddressSpaceFieldInfo);
275 }
276
277
279 assert(isVector() && "cannot get element type of scalar/aggregate");
280 if (IsPointer)
282 else
284 }
285
287
288#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
290#endif
291
293 return IsPointer == RHS.IsPointer && IsVector == RHS.IsVector &&
294 IsScalar == RHS.IsScalar && RHS.RawData == RawData;
295 }
296
298
301
302private:
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
335 typedef int BitFieldInfo[2];
336
337
338
339
340
341
342
343 static constexpr BitFieldInfo ScalarSizeFieldInfo{32, 29};
344
345
346
347 static constexpr BitFieldInfo PointerSizeFieldInfo{16, 45};
348 static constexpr BitFieldInfo PointerAddressSpaceFieldInfo{24, 21};
349
350
351
352
353 static constexpr BitFieldInfo VectorElementsFieldInfo{16, 5};
354 static constexpr BitFieldInfo VectorScalableFieldInfo{1, 0};
355
356
357
358
359
360
361 uint64_t IsScalar : 1;
362 uint64_t IsPointer : 1;
363 uint64_t IsVector : 1;
364 uint64_t RawData : 61;
365
366 static constexpr uint64_t getMask(const BitFieldInfo FieldInfo) {
367 const int FieldSizeInBits = FieldInfo[0];
368 return (((uint64_t)1) << FieldSizeInBits) - 1;
369 }
370 static constexpr uint64_t maskAndShift(uint64_t Val, uint64_t Mask,
371 uint8_t Shift) {
372 assert(Val <= Mask && "Value too large for field");
373 return (Val & Mask) << Shift;
374 }
375 static constexpr uint64_t maskAndShift(uint64_t Val,
376 const BitFieldInfo FieldInfo) {
377 return maskAndShift(Val, getMask(FieldInfo), FieldInfo[1]);
378 }
379
380 constexpr uint64_t getFieldValue(const BitFieldInfo FieldInfo) const {
381 return getMask(FieldInfo) & (RawData >> FieldInfo[1]);
382 }
383
384 constexpr void init(bool IsPointer, bool IsVector, bool IsScalar,
385 ElementCount EC, uint64_t SizeInBits,
387 assert(SizeInBits <= std::numeric_limits::max() &&
388 "Not enough bits in LLT to represent size");
389 this->IsPointer = IsPointer;
390 this->IsVector = IsVector;
391 this->IsScalar = IsScalar;
392 if (IsPointer) {
393 RawData = maskAndShift(SizeInBits, PointerSizeFieldInfo) |
394 maskAndShift(AddressSpace, PointerAddressSpaceFieldInfo);
395 } else {
396 RawData = maskAndShift(SizeInBits, ScalarSizeFieldInfo);
397 }
398 if (IsVector) {
399 RawData |= maskAndShift(EC.getKnownMinValue(), VectorElementsFieldInfo) |
400 maskAndShift(EC.isScalable() ? 1 : 0, VectorScalableFieldInfo);
401 }
402 }
403
404public:
409};
410
412 Ty.print(OS);
413 return OS;
414}
415
419 Invalid.IsPointer = true;
421 }
428 uint64_t Val = Ty.getUniqueRAWLLTData();
430 }
434};
435
436}
437
438#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#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.
static std::pair< Value *, APInt > getMask(Value *WideMask, unsigned Factor, ElementCount LeafValueEC)
static constexpr ElementCount getScalable(ScalarTy MinVal)
static constexpr ElementCount getFixed(ScalarTy MinVal)
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
Definition LowLevelType.h:40
static constexpr LLT float64()
Get a 64-bit IEEE double value.
Definition LowLevelType.h:95
LLVM_ABI void print(raw_ostream &OS) const
constexpr bool isScalableVector() const
Returns true if the LLT is a scalable vector.
Definition LowLevelType.h:182
static constexpr LLT scalarOrVector(ElementCount EC, uint64_t ScalarSize)
Definition LowLevelType.h:129
constexpr unsigned getScalarSizeInBits() const
Definition LowLevelType.h:265
constexpr LLT(bool isPointer, bool isVector, bool isScalar, ElementCount EC, uint64_t SizeInBits, unsigned AddressSpace)
Definition LowLevelType.h:135
constexpr bool isScalar() const
Definition LowLevelType.h:147
static constexpr LLT scalable_vector(unsigned MinNumElements, unsigned ScalarSizeInBits)
Get a low-level scalable vector of some number of elements and element width.
Definition LowLevelType.h:114
constexpr bool operator==(const LLT &RHS) const
Definition LowLevelType.h:292
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.
Definition LowLevelType.h:212
constexpr LLT multiplyElements(int Factor) const
Produce a vector type that is Factor times bigger, preserving the element type.
Definition LowLevelType.h:252
static constexpr LLT vector(ElementCount EC, unsigned ScalarSizeInBits)
Get a low-level vector of some number of elements and element width.
Definition LowLevelType.h:65
constexpr bool isPointerVector() const
Definition LowLevelType.h:153
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
Definition LowLevelType.h:43
constexpr bool isValid() const
Definition LowLevelType.h:146
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
Definition LowLevelType.h:160
constexpr bool operator!=(const LLT &RHS) const
Definition LowLevelType.h:297
friend class GISelInstProfileBuilder
Definition LowLevelType.h:300
constexpr bool isToken() const
Definition LowLevelType.h:148
constexpr bool isVector() const
Definition LowLevelType.h:149
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
Definition LowLevelType.h:58
constexpr bool isScalable() const
Returns true if the LLT is a scalable vector.
Definition LowLevelType.h:171
constexpr uint64_t getUniqueRAWLLTData() const
Definition LowLevelType.h:405
constexpr bool isByteSized() const
Definition LowLevelType.h:261
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
Definition LowLevelType.h:191
constexpr bool isPointer() const
Definition LowLevelType.h:150
constexpr LLT()
Definition LowLevelType.h:141
constexpr LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
Definition LowLevelType.h:278
static constexpr LLT vector(ElementCount EC, LLT ScalarTy)
Get a low-level vector of some number of elements and element type.
Definition LowLevelType.h:72
constexpr ElementCount getElementCount() const
Definition LowLevelType.h:184
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.
Definition LowLevelType.h:219
static constexpr LLT fixed_vector(unsigned NumElements, LLT ScalarTy)
Get a low-level fixed-width vector of some number of elements and element type.
Definition LowLevelType.h:108
static constexpr LLT float16()
Get a 16-bit IEEE half value.
Definition LowLevelType.h:85
constexpr unsigned getAddressSpace() const
Definition LowLevelType.h:271
static constexpr LLT fixed_vector(unsigned NumElements, unsigned ScalarSizeInBits)
Get a low-level fixed-width vector of some number of elements and element width.
Definition LowLevelType.h:101
constexpr bool isPointerOrPointerVector() const
Definition LowLevelType.h:154
constexpr bool isFixedVector() const
Returns true if the LLT is a fixed vector.
Definition LowLevelType.h:178
static constexpr LLT token()
Get a low-level token; just a scalar with zero bits (or no size).
Definition LowLevelType.h:50
constexpr LLT changeElementCount(ElementCount EC) const
Return a vector or scalar with the same element type and the new element count.
Definition LowLevelType.h:228
LLVM_DUMP_METHOD void dump() const
constexpr LLT getScalarType() const
Definition LowLevelType.h:206
constexpr TypeSize getSizeInBytes() const
Returns the total size of the type in bytes, i.e.
Definition LowLevelType.h:201
static constexpr LLT scalable_vector(unsigned MinNumElements, LLT ScalarTy)
Get a low-level scalable vector of some number of elements and element type.
Definition LowLevelType.h:121
static constexpr LLT scalarOrVector(ElementCount EC, LLT ScalarTy)
Definition LowLevelType.h:125
static constexpr LLT float32()
Get a 32-bit IEEE float value.
Definition LowLevelType.h:90
constexpr LLT divide(int Factor) const
Return a type that is Factor times smaller.
Definition LowLevelType.h:235
static constexpr TypeSize getFixed(ScalarTy ExactSize)
The instances of the Type class are immutable: once they are created, they are never changed.
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.
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
static LLT getTombstoneKey()
Definition LowLevelType.h:422
static bool isEqual(const LLT &LHS, const LLT &RHS)
Definition LowLevelType.h:431
static unsigned getHashValue(const LLT &Ty)
Definition LowLevelType.h:427
static LLT getEmptyKey()
Definition LowLevelType.h:417
An information struct used to provide DenseMap with the various necessary components for a given valu...