LLVM 24.0.0git
LowLevelType.h
Go to the documentation of this file.
1//== llvm/CodeGenTypes/LowLevelType.h -------------------------- -*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9/// Implement a low-level type suitable for MachineInstr level instruction
10/// selection.
11///
12/// For a type attached to a MachineInstr, we care about total
13/// size, the number of vector lanes (if any)
14/// and the kind of the type (anyscalar, integer, float and etc).
15/// Floating point are filled with APFloat::Semantics to make them
16/// distinguishable.
17///
18/// Earlier other information required for correct selection was expected to be
19/// carried only by the opcode, or non-type flags. For example the distinction
20/// between G_ADD and G_FADD for int/float or fast-math flags.
21///
22/// Now we also able to rely on the kind of the type.
23/// This may be useful to distinguish different types of the same size used at
24/// the same opcode, for example, G_FADD with half vs G_FADD with bfloat16.
25///
26//===----------------------------------------------------------------------===//
27
28#ifndef LLVM_CODEGEN_LOWLEVELTYPE_H
29#define LLVM_CODEGEN_LOWLEVELTYPE_H
30
31#include "llvm/ADT/APFloat.h"
32#include "llvm/ADT/bit.h"
35#include "llvm/Support/Debug.h"
37#include <atomic>
38#include <cassert>
39
40namespace llvm {
41
42class raw_ostream;
43
44class LLT {
45public:
47
59
60 constexpr static Kind toVector(Kind Ty) {
61 if (Ty == Kind::POINTER)
63
64 if (Ty == Kind::INTEGER)
66
67 if (Ty == Kind::FLOAT)
68 return Kind::VECTOR_FLOAT;
69
70 return Kind::VECTOR_ANY;
71 }
72
73 constexpr static Kind toScalar(Kind Ty) {
74 if (Ty == Kind::VECTOR_POINTER)
75 return Kind::POINTER;
76
77 if (Ty == Kind::VECTOR_INTEGER)
78 return Kind::INTEGER;
79
80 if (Ty == Kind::VECTOR_FLOAT)
81 return Kind::FLOAT;
82
83 return Kind::ANY_SCALAR;
84 }
85
86 /// Get a low-level scalar or aggregate "bag of bits".
87 static constexpr LLT scalar(unsigned SizeInBits) {
88 return LLT{Kind::ANY_SCALAR, ElementCount::getFixed(0), SizeInBits};
89 }
90
91 static LLT integer(unsigned SizeInBits) {
92 if (!getUseExtended())
93 return LLT::scalar(SizeInBits);
94
95 return LLT{Kind::INTEGER, ElementCount::getFixed(0), SizeInBits};
96 }
97
106
107 /// Get a low-level token; just a scalar with zero bits (or no size).
108 static constexpr LLT token() {
110 /*SizeInBits=*/0};
111 }
112
113 /// Get a low-level pointer in the given address space.
114 static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits) {
115 assert(SizeInBits > 0 && "invalid pointer size");
116 return LLT{Kind::POINTER, ElementCount::getFixed(0), SizeInBits,
118 }
119
120 /// Get a low-level vector of some number of elements and element width.
121 static constexpr LLT vector(ElementCount EC, unsigned ScalarSizeInBits) {
122 assert(!EC.isScalar() && "invalid number of vector elements");
123 return LLT{Kind::VECTOR_ANY, EC, ScalarSizeInBits};
124 }
125
126 /// Get a low-level vector of some number of elements and element type.
127 static constexpr LLT vector(ElementCount EC, LLT ScalarTy) {
128 assert(!EC.isScalar() && "invalid number of vector elements");
129 assert(!ScalarTy.isVector() && "invalid vector element type");
130
131 Kind Info = toVector(ScalarTy.Info);
132 if (ScalarTy.isPointer())
133 return LLT{Info, EC, ScalarTy.getSizeInBits().getFixedValue(),
134 ScalarTy.getAddressSpace()};
135 if (ScalarTy.isFloat())
136 return LLT{Info, EC, ScalarTy.getSizeInBits().getFixedValue(),
137 ScalarTy.getFpSemantics()};
138
139 return LLT{Info, EC, ScalarTy.getSizeInBits().getFixedValue()};
140 }
141
142 // FIXME: Remove this builder
143 static LLT floatIEEE(unsigned SizeInBits) {
144 if (!getUseExtended())
145 return LLT::scalar(SizeInBits);
146
147 switch (SizeInBits) {
148 default:
149 llvm_unreachable("Wrong SizeInBits for IEEE Floating point!");
150 case 16:
151 return float16();
152 case 32:
153 return float32();
154 case 64:
155 return float64();
156 case 128:
157 return float128();
158 }
159 }
160
161 // Get a bfloat16 value.
162 static constexpr LLT bfloat16() {
164 FpSemantics::S_BFloat};
165 }
166 /// Get a 16-bit IEEE half value.
167 static constexpr LLT float16() {
169 FpSemantics::S_IEEEhalf};
170 }
171 /// Get a 32-bit IEEE float value.
172 static constexpr LLT float32() {
174 FpSemantics::S_IEEEsingle};
175 }
176 /// Get a 64-bit IEEE double value.
177 static constexpr LLT float64() {
179 FpSemantics::S_IEEEdouble};
180 }
181
182 /// Get a 80-bit X86 floating point value.
183 static constexpr LLT x86fp80() {
185 FpSemantics::S_x87DoubleExtended};
186 }
187
188 /// Get a 128-bit IEEE quad value.
189 static constexpr LLT float128() {
190 return LLT{Kind::FLOAT, ElementCount::getFixed(0), 128,
191 FpSemantics::S_IEEEquad};
192 }
193
194 /// Get a 128-bit PowerPC double double value.
195 static constexpr LLT ppcf128() {
196 return LLT{Kind::FLOAT, ElementCount::getFixed(0), 128,
197 FpSemantics::S_PPCDoubleDouble};
198 }
199
200 /// Get a low-level fixed-width vector of some number of elements and element
201 /// width.
202 static constexpr LLT fixed_vector(unsigned NumElements,
203 unsigned ScalarSizeInBits) {
204 return vector(ElementCount::getFixed(NumElements),
205 LLT::scalar(ScalarSizeInBits));
206 }
207
208 /// Get a low-level fixed-width vector of some number of elements and element
209 /// type.
210 static constexpr LLT fixed_vector(unsigned NumElements, LLT ScalarTy) {
211 return vector(ElementCount::getFixed(NumElements), ScalarTy);
212 }
213
214 /// Get a low-level scalable vector of some number of elements and element
215 /// width.
216 static constexpr LLT scalable_vector(unsigned MinNumElements,
217 unsigned ScalarSizeInBits) {
218 return vector(ElementCount::getScalable(MinNumElements),
219 LLT::scalar(ScalarSizeInBits));
220 }
221
222 /// Get a low-level scalable vector of some number of elements and element
223 /// type.
224 static constexpr LLT scalable_vector(unsigned MinNumElements, LLT ScalarTy) {
225 return vector(ElementCount::getScalable(MinNumElements), ScalarTy);
226 }
227
228 static constexpr LLT scalarOrVector(ElementCount EC, LLT ScalarTy) {
229 return EC.isScalar() ? ScalarTy : LLT::vector(EC, ScalarTy);
230 }
231
232 static constexpr LLT scalarOrVector(ElementCount EC, uint64_t ScalarSize) {
233 assert(ScalarSize <= std::numeric_limits<unsigned>::max() &&
234 "Not enough bits in LLT to represent size");
235 return scalarOrVector(EC, LLT::scalar(static_cast<unsigned>(ScalarSize)));
236 }
237
238 explicit constexpr LLT(Kind Info, ElementCount EC, uint64_t SizeInBits)
239 : LLT() {
240 init(Info, EC, SizeInBits);
241 }
242
243 explicit constexpr LLT(Kind Info, ElementCount EC, uint64_t SizeInBits,
244 unsigned AddressSpace)
245 : LLT() {
246 init(Info, EC, SizeInBits, AddressSpace);
247 }
248
249 explicit constexpr LLT(Kind Info, ElementCount EC, uint64_t SizeInBits,
250 FpSemantics Sem)
251 : LLT() {
252 init(Info, EC, SizeInBits, Sem);
253 }
254
255 LLVM_ABI explicit LLT(MVT VT);
256 explicit constexpr LLT() : RawData(0), Info(static_cast<Kind>(0)) {}
257
258 constexpr bool isToken() const {
259 return Info == Kind::ANY_SCALAR && RawData == 0;
260 }
261 constexpr bool isValid() const { return isToken() || RawData != 0; }
262 constexpr bool isAnyScalar() const { return Info == Kind::ANY_SCALAR; }
263 constexpr bool isInteger() const { return Info == Kind::INTEGER; }
264 constexpr bool isFloat() const { return Info == Kind::FLOAT; }
265 constexpr bool isPointer() const { return Info == Kind::POINTER; }
266 constexpr bool isAnyVector() const { return Info == Kind::VECTOR_ANY; }
267 constexpr bool isIntegerVector() const {
268 return Info == Kind::VECTOR_INTEGER;
269 }
270 constexpr bool isFloatVector() const { return Info == Kind::VECTOR_FLOAT; }
271 constexpr bool isPointerVector() const {
272 return Info == Kind::VECTOR_POINTER;
273 }
274 constexpr bool isPointerOrPointerVector() const {
275 return isPointer() || isPointerVector();
276 }
277 constexpr bool isFloatOrFloatVector() const {
278 return isFloat() || isFloatVector();
279 }
280
281 constexpr bool isScalar() const {
282 return Info == Kind::ANY_SCALAR || Info == Kind::INTEGER ||
283 Info == Kind::FLOAT;
284 }
285 constexpr bool isScalar(unsigned Size) const {
286 return isScalar() && getScalarSizeInBits() == Size;
287 }
288 constexpr bool isVector() const {
289 return Info == Kind::VECTOR_ANY || Info == Kind::VECTOR_INTEGER ||
290 Info == Kind::VECTOR_FLOAT || Info == Kind::VECTOR_POINTER;
291 }
292
293 constexpr bool isInteger(unsigned Size) const {
294 return isInteger() && getScalarSizeInBits() == Size;
295 }
296
297 constexpr bool isFloat(unsigned Size) const {
298 return isFloat() && getScalarSizeInBits() == Size;
299 }
300 constexpr bool isFloat(FpSemantics Sem) const {
301 return isFloat() && getFpSemantics() == Sem;
302 }
303 // FIXME: Remove or rework this predicate
310
311 bool isFloat16() const {
312 if (!getUseExtended())
313 return isAnyScalar() && getSizeInBits() == 16;
315 }
316 bool isFloat32() const {
317 if (!getUseExtended())
318 return isAnyScalar() && getSizeInBits() == 32;
320 }
321 bool isFloat64() const {
322 if (!getUseExtended())
323 return isAnyScalar() && getSizeInBits() == 64;
325 }
326 bool isFloat128() const {
327 if (!getUseExtended())
328 return isAnyScalar() && getSizeInBits() == 128;
330 }
331 bool isBFloat16() const {
332 if (!getUseExtended())
333 return false;
334 return isFloat(FpSemantics::S_BFloat);
335 }
336 bool isX86FP80() const {
337 if (!getUseExtended())
338 return false;
339 return isFloat(FpSemantics::S_x87DoubleExtended);
340 }
341 bool isPPCF128() const {
342 if (!getUseExtended())
343 return false;
344 return isFloat(FpSemantics::S_PPCDoubleDouble);
345 }
346
347 /// Returns the number of elements in a vector LLT. Must only be called on
348 /// vector types.
349 constexpr uint16_t getNumElements() const {
350 if (isScalable())
352 "Possible incorrect use of LLT::getNumElements() for "
353 "scalable vector. Scalable flag may be dropped, use "
354 "LLT::getElementCount() instead");
356 }
357
358 /// Returns true if the LLT is a scalable vector. Must only be called on
359 /// vector types.
360 constexpr bool isScalable() const {
361 assert(isVector() && "Expected a vector type");
362 return getFieldValue(VectorScalableFieldInfo);
363 }
364
365 /// Returns true if the LLT is a fixed vector. Returns false otherwise, even
366 /// if the LLT is not a vector type.
367 constexpr bool isFixedVector() const { return isVector() && !isScalable(); }
368
369 constexpr bool isFixedVector(unsigned NumElements,
370 unsigned ScalarSize) const {
371 return isFixedVector() && getNumElements() == NumElements &&
372 getScalarSizeInBits() == ScalarSize;
373 }
374
375 /// Returns true if the LLT is a scalable vector. Returns false otherwise,
376 /// even if the LLT is not a vector type.
377 constexpr bool isScalableVector() const { return isVector() && isScalable(); }
378
379 constexpr ElementCount getElementCount() const {
380 assert(isVector() && "cannot get number of elements on scalar/aggregate");
381 return ElementCount::get(getFieldValue(VectorElementsFieldInfo),
382 isScalable());
383 }
384
385 /// Returns the total size of the type. Must only be called on sized types.
386 constexpr TypeSize getSizeInBits() const {
387 if (isPointer() || isScalar())
389 auto EC = getElementCount();
390 return TypeSize(getScalarSizeInBits() * EC.getKnownMinValue(),
391 EC.isScalable());
392 }
393
394 /// Returns the total size of the type in bytes, i.e. number of whole bytes
395 /// needed to represent the size in bits. Must only be called on sized types.
396 constexpr TypeSize getSizeInBytes() const {
397 TypeSize BaseSize = getSizeInBits();
398 return {(BaseSize.getKnownMinValue() + 7) / 8, BaseSize.isScalable()};
399 }
400
401 LLT getScalarType() const { return isVector() ? getElementType() : *this; }
402
403 constexpr FpSemantics getFpSemantics() const {
404 assert((isFloat() || isFloatVector()) &&
405 "cannot get FP info for non float type");
406 return FpSemantics(getFieldValue(FpSemanticFieldInfo));
407 }
408
409 constexpr Kind getKind() const { return Info; }
410
411 /// Returns a vector with the same number of elements but the new element
412 /// type. Must only be called on vector types.
413 constexpr LLT changeVectorElementType(LLT NewEltTy) const {
414 return LLT::vector(getElementCount(), NewEltTy);
415 }
416
417 /// If this type is a vector, return a vector with the same number of elements
418 /// but the new element type. Otherwise, return the new element type.
419 constexpr LLT changeElementType(LLT NewEltTy) const {
420 return isVector() ? changeVectorElementType(NewEltTy) : NewEltTy;
421 }
422
423 /// If this type is a vector, return a vector with the same number of elements
424 /// but the new element size. Otherwise, return the new element type. Invalid
425 /// for pointer types. For these, use changeElementType.
426 LLT changeElementSize(unsigned NewEltSize) const {
428 "invalid to directly change element size for pointers");
429 if (isVector())
431 getElementType().changeElementSize(NewEltSize));
432
433 if (isInteger())
434 return LLT::integer(NewEltSize);
435
436 if (isFloatIEEE())
437 return LLT::floatIEEE(NewEltSize);
438
439 return LLT::scalar(NewEltSize);
440 }
441
442 /// Return a vector with the same element type and the new element count. Must
443 /// be called on vector types.
445 assert(isVector() &&
446 "cannot change vector element count of non-vector type");
447 return LLT::vector(EC, getElementType());
448 }
449
450 /// Return a vector or scalar with the same element type and the new element
451 /// count.
455
456 LLT changeElementCount(unsigned NumElements) const {
457 return changeElementCount(ElementCount::getFixed(NumElements));
458 }
459
460 /// Return a type that is \p Factor times smaller. Reduces the number of
461 /// elements if this is a vector, or the bitwidth for scalar/pointers. Does
462 /// not attempt to handle cases that aren't evenly divisible.
463 LLT divide(int Factor) const {
464 assert(Factor != 1);
465 assert((!isScalar() || getScalarSizeInBits() != 0) && !isFloat() &&
466 "cannot divide scalar of size zero and floats");
467 if (isVector()) {
468 assert(getElementCount().isKnownMultipleOf(Factor));
469 return scalarOrVector(getElementCount().divideCoefficientBy(Factor),
471 }
472
473 assert(getScalarSizeInBits() % Factor == 0);
474 if (isInteger())
475 return integer(getScalarSizeInBits() / Factor);
476
477 return scalar(getScalarSizeInBits() / Factor);
478 }
479
480 /// Produce a vector type that is \p Factor times bigger, preserving the
481 /// element type. For a scalar or pointer, this will produce a new vector with
482 /// \p Factor elements.
483 LLT multiplyElements(int Factor) const {
484 if (isVector()) {
485 return scalarOrVector(getElementCount() * Factor, getElementType());
486 }
487
488 return fixed_vector(Factor, *this);
489 }
490
491 constexpr bool isByteSized() const {
493 }
494
495 constexpr unsigned getScalarSizeInBits() const {
497 return getFieldValue(PointerSizeFieldInfo);
498 return getFieldValue(ScalarSizeFieldInfo);
499 }
500
501 constexpr unsigned getAddressSpace() const {
503 "cannot get address space of non-pointer type");
504 return getFieldValue(PointerAddressSpaceFieldInfo);
505 }
506
507 /// Returns the vector's element type. Only valid for vector types.
509 assert(isVector() && "cannot get element type of scalar/aggregate");
510 if (isPointerVector())
512
513 if (isFloatVector())
515
516 if (isIntegerVector())
518
519 return scalar(getScalarSizeInBits());
520 }
521
523 if (isPointer() || isPointerVector())
524 return *this;
525
526 if (isVector())
528
529 return integer(getSizeInBits());
530 }
531
532 LLVM_ABI void print(raw_ostream &OS) const;
533
534#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
535 LLVM_DUMP_METHOD void dump() const;
536#endif
537
538 bool operator==(const LLT &RHS) const {
539 if (Info == RHS.Info && RawData == RHS.RawData)
540 return true;
541
542 if (isAnyScalar() || RHS.isAnyScalar())
543 return isScalar() == RHS.isScalar() &&
544 getScalarSizeInBits() == RHS.getScalarSizeInBits();
545
546 if (isVector() && RHS.isVector())
547 return getElementType() == RHS.getElementType() &&
548 getElementCount() == RHS.getElementCount();
549
550 return false;
551 }
552
553 bool operator!=(const LLT &RHS) const { return !(*this == RHS); }
554
556
557private:
558 /// LLT is packed into 64 bits as follows:
559 /// RawData : 60
560 /// Info : 4
561 /// RawData remaining for Kind-specific data, packed in
562 /// bitfields as described below. As there isn't a simple portable way to pack
563 /// bits into bitfields, here the different fields in the packed structure is
564 /// described in static const *Field variables. Each of these variables
565 /// is a 2-element array, with the first element describing the bitfield size
566 /// and the second element describing the bitfield offset.
567 ///
568 /*
569 --- LLT ---
570
571 63 56 47 39 31 23 15 7 0
572 | | | | | | | | |
573 |xxxxxxxx|xxxxxxxx|xxxxxxxx|xxxxxxxx|xxxxxxxx|xxxxxxxx|xxxxxxxx|xxxxxxxx|
574 %%%% (1)
575 .... ........ ........ ........ .... (2)
576 **** ******** **** (3)
577 ~~~~ ~~~~~~~~ ~~~~~~~~ ~~~~ (4)
578 #### #### (5)
579 ^^^^ ^^^^^^^^ ^^^^ (6)
580 @ (7)
581
582 (1) Kind: [63:60]
583 (2) ScalarSize: [59:28]
584 (3) PointerSize: [59:44]
585 (4) PointerAddressSpace: [43:20]
586 (5) FpSemantics: [27:20]
587 (6) VectorElements: [19:4]
588 (7) VectorScalable: [0:0]
589
590 */
591
592 /// This is how the LLT are packed per Kind:
593 /// * Invalid:
594 /// Info: [63:60] = 0
595 /// RawData: [59:0] = 0;
596 ///
597 /// * Non-pointer scalar (isPointer == 0 && isVector == 0):
598 /// Info: [63:60];
599 /// SizeOfElement: [59:28];
600 /// FpSemantics: [27:20];
601 ///
602 /// * Pointer (isPointer == 1 && isVector == 0):
603 /// Info: [63:60];
604 /// SizeInBits: [59:44];
605 /// AddressSpace: [43:20];
606 ///
607 /// * Vector-of-non-pointer (isPointer == 0 && isVector == 1):
608 /// Info: [63:60]
609 /// SizeOfElement: [59:28];
610 /// FpSemantics: [27:20];
611 /// VectorElements: [19:4];
612 /// Scalable: [0:0];
613 ///
614 /// * Vector-of-pointer (isPointer == 1 && isVector == 1):
615 /// Info: [63:60];
616 /// SizeInBits: [59:44];
617 /// AddressSpace: [43:20];
618 /// VectorElements: [19:4];
619 /// Scalable: [0:0];
620
621 /// BitFieldInfo: {Size, Offset}
622 typedef int BitFieldInfo[2];
624 static constexpr BitFieldInfo VectorScalableFieldInfo{1, 0};
625 static constexpr BitFieldInfo VectorElementsFieldInfo{16, 4};
626 static constexpr BitFieldInfo FpSemanticFieldInfo{8, 20};
627 static constexpr BitFieldInfo PointerAddressSpaceFieldInfo{24, 20};
628 static constexpr BitFieldInfo ScalarSizeFieldInfo{32, 28};
629 static constexpr BitFieldInfo PointerSizeFieldInfo{16, 44};
630
631 uint64_t RawData : 60;
632 Kind Info : 4;
633
634 static constexpr uint64_t getMask(const BitFieldInfo FieldInfo) {
635 const int FieldSizeInBits = FieldInfo[0];
636 return (((uint64_t)1) << FieldSizeInBits) - 1;
637 }
638 static constexpr uint64_t maskAndShift(uint64_t Val, uint64_t Mask,
639 uint8_t Shift) {
640 assert(Val <= Mask && "Value too large for field");
641 return (Val & Mask) << Shift;
642 }
643 static constexpr uint64_t maskAndShift(uint64_t Val,
644 const BitFieldInfo FieldInfo) {
645 return maskAndShift(Val, getMask(FieldInfo), FieldInfo[1]);
646 }
647
648 constexpr uint64_t getFieldValue(const BitFieldInfo FieldInfo) const {
649 return getMask(FieldInfo) & (RawData >> FieldInfo[1]);
650 }
651
652 // Init for scalar and integer single or vector types
653 constexpr void init(Kind Info, ElementCount EC, uint64_t SizeInBits) {
654 assert(SizeInBits <= std::numeric_limits<unsigned>::max() &&
655 "Not enough bits in LLT to represent size");
656 assert((Info == Kind::ANY_SCALAR || Info == Kind::INTEGER ||
657 Info == Kind::VECTOR_ANY || Info == Kind::VECTOR_INTEGER) &&
658 "Called initializer for wrong LLT Kind");
659 this->Info = Info;
660 RawData = maskAndShift(SizeInBits, ScalarSizeFieldInfo);
661
662 if (Info == Kind::VECTOR_ANY || Info == Kind::VECTOR_INTEGER) {
663 RawData = maskAndShift(SizeInBits, ScalarSizeFieldInfo) |
664 maskAndShift(EC.getKnownMinValue(), VectorElementsFieldInfo) |
665 maskAndShift(EC.isScalable() ? 1 : 0, VectorScalableFieldInfo);
666 }
667 }
668
669 // Init pointer or pointer vector
670 constexpr void init(Kind Info, ElementCount EC, uint64_t SizeInBits,
671 unsigned AddressSpace) {
672 assert(SizeInBits <= std::numeric_limits<unsigned>::max() &&
673 "Not enough bits in LLT to represent size");
674 assert((Info == Kind::POINTER || Info == Kind::VECTOR_POINTER) &&
675 "Called initializer for wrong LLT Kind");
676 this->Info = Info;
677 RawData = maskAndShift(SizeInBits, PointerSizeFieldInfo) |
678 maskAndShift(AddressSpace, PointerAddressSpaceFieldInfo);
679
680 if (Info == Kind::VECTOR_POINTER) {
681 RawData |= maskAndShift(EC.getKnownMinValue(), VectorElementsFieldInfo) |
682 maskAndShift(EC.isScalable() ? 1 : 0, VectorScalableFieldInfo);
683 }
684 }
685
686 constexpr void init(Kind Info, ElementCount EC, uint64_t SizeInBits,
687 FpSemantics Sem) {
688 assert(SizeInBits <= std::numeric_limits<unsigned>::max() &&
689 "Not enough bits in LLT to represent size");
690 assert((Info == Kind::FLOAT || Info == Kind::VECTOR_FLOAT) &&
691 "Called initializer for wrong LLT Kind");
692 this->Info = Info;
693 RawData = maskAndShift(SizeInBits, ScalarSizeFieldInfo) |
694 maskAndShift((uint64_t)Sem, FpSemanticFieldInfo);
695
696 if (Info == Kind::VECTOR_FLOAT) {
697 RawData |= maskAndShift(EC.getKnownMinValue(), VectorElementsFieldInfo) |
698 maskAndShift(EC.isScalable() ? 1 : 0, VectorScalableFieldInfo);
699 }
700 }
701
702public:
703 constexpr uint64_t getUniqueRAWLLTData() const {
704 return ((uint64_t)RawData) | ((uint64_t)Info) << 60;
705 }
706
707 static bool getUseExtended() {
708 return ExtendedLLT.load(std::memory_order_relaxed);
709 }
710 static void setUseExtended(bool Enable) {
711 ExtendedLLT.store(Enable, std::memory_order_relaxed);
712 }
713
714private:
715 // Enabled during target construction, which may run concurrently. Relaxed
716 // ordering suffices because the flag publishes no other state.
717 //
718 // FIXME: Scope this per target rather than globally:
719 // https://github.com/llvm/llvm-project/issues/219517.
720 LLVM_ABI static std::atomic<bool> ExtendedLLT;
721};
722
723inline raw_ostream &operator<<(raw_ostream &OS, const LLT &Ty) {
724 Ty.print(OS);
725 return OS;
726}
727
728} // namespace llvm
729
730#endif // LLVM_CODEGEN_LOWLEVELTYPE_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
This file declares a class to represent arbitrary precision floating point values and provide a varie...
#define LLVM_ABI
Definition Compiler.h:211
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:702
static std::pair< Value *, APInt > getMask(Value *WideMask, unsigned Factor, ElementCount LeafValueEC)
Value * RHS
This file implements the C++20 <bit> header.
static LLVM_ABI const llvm::fltSemantics & EnumToSemantics(Semantics S)
Definition APFloat.cpp:451
static LLVM_ABI unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
Definition APFloat.cpp:673
static constexpr ElementCount getScalable(ScalarTy MinVal)
Definition TypeSize.h:309
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition TypeSize.h:306
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
Definition TypeSize.h:312
static constexpr LLT float64()
Get a 64-bit IEEE double value.
constexpr bool isFloatVector() const
LLT changeElementCount(ElementCount EC) const
Return a vector or scalar with the same element type and the new element count.
static constexpr Kind toVector(Kind Ty)
constexpr LLT(Kind Info, ElementCount EC, uint64_t SizeInBits, FpSemantics Sem)
LLVM_ABI void print(raw_ostream &OS) const
static constexpr LLT x86fp80()
Get a 80-bit X86 floating point value.
constexpr bool isScalableVector() const
Returns true if the LLT is a scalable vector.
constexpr bool isFixedVector(unsigned NumElements, unsigned ScalarSize) const
static constexpr LLT scalarOrVector(ElementCount EC, uint64_t ScalarSize)
bool operator==(const LLT &RHS) const
constexpr unsigned getScalarSizeInBits() const
constexpr bool isFloatOrFloatVector() const
static bool getUseExtended()
bool isX86FP80() const
constexpr bool isScalar() const
constexpr bool isAnyVector() 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 Kind getKind() const
LLT multiplyElements(int Factor) const
Produce a vector type that is Factor times bigger, preserving the element type.
APFloat::Semantics FpSemantics
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.
static constexpr LLT vector(ElementCount EC, unsigned ScalarSizeInBits)
Get a low-level vector of some number of elements and element width.
LLT getScalarType() const
constexpr bool isPointerVector() const
constexpr bool isInteger() const
static void setUseExtended(bool Enable)
constexpr bool isIntegerVector() const
constexpr FpSemantics getFpSemantics() const
bool operator!=(const LLT &RHS) const
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr bool isValid() const
bool isBFloat16() const
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
constexpr bool isFloat() const
friend class GISelInstProfileBuilder
constexpr bool isToken() const
static constexpr LLT float128()
Get a 128-bit IEEE quad value.
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
LLT changeToInteger() const
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
constexpr bool isFloat(FpSemantics Sem) const
constexpr bool isPointer() const
constexpr LLT()
constexpr bool isAnyScalar() const
static constexpr LLT vector(ElementCount EC, LLT ScalarTy)
Get a low-level vector of some number of elements and element type.
constexpr bool isInteger(unsigned Size) const
static constexpr LLT ppcf128()
Get a 128-bit PowerPC double double value.
constexpr ElementCount getElementCount() const
static constexpr LLT fixed_vector(unsigned NumElements, LLT ScalarTy)
Get a low-level fixed-width vector of some number of elements and element type.
LLT divide(int Factor) const
Return a type that is Factor times smaller.
static constexpr Kind toScalar(Kind Ty)
static constexpr LLT float16()
Get a 16-bit IEEE half value.
constexpr unsigned getAddressSpace() const
constexpr bool isFloat(unsigned Size) 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(Kind Info, ElementCount EC, uint64_t SizeInBits, unsigned AddressSpace)
bool isPPCF128() const
static LLT integer(unsigned SizeInBits)
constexpr LLT(Kind Info, ElementCount EC, uint64_t SizeInBits)
LLVM_DUMP_METHOD void dump() const
constexpr bool isFloatIEEE() const
static constexpr LLT bfloat16()
bool isFloat16() const
bool isFloat32() const
LLT changeElementCount(unsigned NumElements) const
constexpr LLT changeVectorElementType(LLT NewEltTy) const
Returns a vector with the same number of elements but the new element type.
bool isFloat128() const
constexpr TypeSize getSizeInBytes() const
Returns the total size of the type in bytes, i.e.
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
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)
constexpr bool isScalar(unsigned Size) const
LLT changeVectorElementCount(ElementCount EC) const
Return a vector with the same element type and the new element count.
static constexpr LLT float32()
Get a 32-bit IEEE float value.
bool isFloat64() const
static LLT floatIEEE(unsigned SizeInBits)
static LLT floatingPoint(const FpSemantics &Sem)
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.
Machine Value Type.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:352
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...
Definition TypeSize.h:181
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:201
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition TypeSize.h:169
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition TypeSize.h:166
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
Definition Error.cpp:173
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
constexpr int bit_width_constexpr(T Value)
Returns the number of bits needed to represent Value if Value is nonzero.
Definition bit.h:337
@ Enable
Enable colors.
Definition WithColor.h:47