1
//===- CodeGen/ValueTypes.h - Low-Level Target independ. types --*- C++ -*-===//
3
// The LLVM Compiler Infrastructure
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
8
//===----------------------------------------------------------------------===//
10
// This file defines the set of low-level target independent types which various
11
// values in the code generator are. This allows the target specific behavior
12
// of instructions to be described to target independent passes.
14
//===----------------------------------------------------------------------===//
16
#ifndef LLVM_CODEGEN_VALUETYPES_H
17
#define LLVM_CODEGEN_VALUETYPES_H
21
#include "llvm/System/DataTypes.h"
22
#include "llvm/Support/MathExtras.h"
29
class MVT { // MVT = Machine Value Type
31
enum SimpleValueType {
32
// If you change this numbering, you must change the values in
33
// ValueTypes.td as well!
34
Other = 0, // This is a non-standard value
35
i1 = 1, // This is a 1 bit integer value
36
i8 = 2, // This is an 8 bit integer value
37
i16 = 3, // This is a 16 bit integer value
38
i32 = 4, // This is a 32 bit integer value
39
i64 = 5, // This is a 64 bit integer value
40
i128 = 6, // This is a 128 bit integer value
42
FIRST_INTEGER_VALUETYPE = i1,
43
LAST_INTEGER_VALUETYPE = i128,
45
f32 = 7, // This is a 32 bit floating point value
46
f64 = 8, // This is a 64 bit floating point value
47
f80 = 9, // This is a 80 bit floating point value
48
f128 = 10, // This is a 128 bit floating point value
49
ppcf128 = 11, // This is a PPC 128-bit floating point value
54
v16i8 = 15, // 16 x i8
55
v32i8 = 16, // 32 x i8
56
v2i16 = 17, // 2 x i16
57
v4i16 = 18, // 4 x i16
58
v8i16 = 19, // 8 x i16
59
v16i16 = 20, // 16 x i16
60
v2i32 = 21, // 2 x i32
61
v4i32 = 22, // 4 x i32
62
v8i32 = 23, // 8 x i32
63
v1i64 = 24, // 1 x i64
64
v2i64 = 25, // 2 x i64
65
v4i64 = 26, // 4 x i64
67
v2f32 = 27, // 2 x f32
68
v4f32 = 28, // 4 x f32
69
v8f32 = 29, // 8 x f32
70
v2f64 = 30, // 2 x f64
71
v4f64 = 31, // 4 x f64
73
FIRST_VECTOR_VALUETYPE = v2i8,
74
LAST_VECTOR_VALUETYPE = v4f64,
76
Flag = 32, // This glues nodes together during pre-RA sched
78
isVoid = 33, // This has no value
80
LAST_VALUETYPE = 34, // This always remains at the end of the list.
82
// This is the current maximum for LAST_VALUETYPE.
83
// EVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
84
// This value must be a multiple of 32.
85
MAX_ALLOWED_VALUETYPE = 64,
87
// Metadata - This is MDNode or MDString.
90
// iPTRAny - An int value the size of the pointer of the current
91
// target to any address space. This must only be used internal to
92
// tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
95
// vAny - A vector with any length and element size. This is used
96
// for intrinsics that have overloadings based on vector types.
97
// This is only for tblgen's consumption!
100
// fAny - Any floating-point or vector floating-point value. This is used
101
// for intrinsics that have overloadings based on floating-point types.
102
// This is only for tblgen's consumption!
105
// iAny - An integer or vector integer value of any bit width. This is
106
// used for intrinsics that have overloadings based on integer bit widths.
107
// This is only for tblgen's consumption!
110
// iPTR - An int value the size of the pointer of the current
111
// target. This should only be used internal to tblgen!
114
// LastSimpleValueType - The greatest valid SimpleValueType value.
115
LastSimpleValueType = 255,
117
// INVALID_SIMPLE_VALUE_TYPE - Simple value types greater than or equal
118
// to this are considered extended value types.
119
INVALID_SIMPLE_VALUE_TYPE = LastSimpleValueType + 1
122
SimpleValueType SimpleTy;
124
MVT() : SimpleTy((SimpleValueType)(INVALID_SIMPLE_VALUE_TYPE)) {}
125
MVT(SimpleValueType SVT) : SimpleTy(SVT) { }
127
bool operator>(const MVT& S) const { return SimpleTy > S.SimpleTy; }
128
bool operator<(const MVT& S) const { return SimpleTy < S.SimpleTy; }
129
bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
130
bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
131
bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
133
/// isFloatingPoint - Return true if this is a FP, or a vector FP type.
134
bool isFloatingPoint() const {
135
return ((SimpleTy >= MVT::f32 && SimpleTy <= MVT::ppcf128) ||
136
(SimpleTy >= MVT::v2f32 && SimpleTy <= MVT::v4f64));
139
/// isInteger - Return true if this is an integer, or a vector integer type.
140
bool isInteger() const {
141
return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
142
SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
143
(SimpleTy >= MVT::v2i8 && SimpleTy <= MVT::v4i64));
146
/// isVector - Return true if this is a vector value type.
147
bool isVector() const {
148
return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
149
SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
152
/// isPow2VectorType - Returns true if the given vector is a power of 2.
153
bool isPow2VectorType() const {
154
unsigned NElts = getVectorNumElements();
155
return !(NElts & (NElts - 1));
158
/// getPow2VectorType - Widens the length of the given vector EVT up to
159
/// the nearest power of 2 and returns that type.
160
MVT getPow2VectorType() const {
161
if (!isPow2VectorType()) {
162
unsigned NElts = getVectorNumElements();
163
unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
164
return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
171
/// getScalarType - If this is a vector type, return the element type,
172
/// otherwise return this.
173
MVT getScalarType() const {
174
return isVector() ? getVectorElementType() : *this;
177
MVT getVectorElementType() const {
180
return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
185
case v32i8: return i8;
189
case v16i16: return i16;
192
case v8i32: return i32;
195
case v4i64: return i64;
198
case v8f32: return f32;
200
case v4f64: return f64;
204
unsigned getVectorNumElements() const {
208
case v32i8: return 32;
210
case v16i16: return 16;
214
case v8f32: return 8;
220
case v4f64: return 4;
226
case v2f64: return 2;
227
case v1i64: return 1;
231
unsigned getSizeInBits() const {
234
assert(0 && "Value type size is target-dependent. Ask TLI.");
238
assert(0 && "Value type is overloaded.");
240
assert(0 && "getSizeInBits called on extended MVT.");
244
case v2i8: return 16;
248
case v2i16: return 32;
255
case v2f32: return 64;
256
case f80 : return 80;
265
case v2f64: return 128;
271
case v4f64: return 256;
275
static MVT getFloatingPointVT(unsigned BitWidth) {
278
assert(false && "Bad bit width!");
290
static MVT getIntegerVT(unsigned BitWidth) {
293
return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
309
static MVT getVectorVT(MVT VT, unsigned NumElements) {
310
switch (VT.SimpleTy) {
314
if (NumElements == 2) return MVT::v2i8;
315
if (NumElements == 4) return MVT::v4i8;
316
if (NumElements == 8) return MVT::v8i8;
317
if (NumElements == 16) return MVT::v16i8;
318
if (NumElements == 32) return MVT::v32i8;
321
if (NumElements == 2) return MVT::v2i16;
322
if (NumElements == 4) return MVT::v4i16;
323
if (NumElements == 8) return MVT::v8i16;
324
if (NumElements == 16) return MVT::v16i16;
327
if (NumElements == 2) return MVT::v2i32;
328
if (NumElements == 4) return MVT::v4i32;
329
if (NumElements == 8) return MVT::v8i32;
332
if (NumElements == 1) return MVT::v1i64;
333
if (NumElements == 2) return MVT::v2i64;
334
if (NumElements == 4) return MVT::v4i64;
337
if (NumElements == 2) return MVT::v2f32;
338
if (NumElements == 4) return MVT::v4f32;
339
if (NumElements == 8) return MVT::v8f32;
342
if (NumElements == 2) return MVT::v2f64;
343
if (NumElements == 4) return MVT::v4f64;
346
return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
349
static MVT getIntVectorWithNumElements(unsigned NumElts) {
351
default: return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
352
case 1: return MVT::v1i64;
353
case 2: return MVT::v2i32;
354
case 4: return MVT::v4i16;
355
case 8: return MVT::v8i8;
356
case 16: return MVT::v16i8;
361
struct EVT { // EVT = Extended Value Type
367
EVT() : V((MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE)),
369
EVT(MVT::SimpleValueType SVT) : V(SVT), LLVMTy(0) { }
370
EVT(MVT S) : V(S), LLVMTy(0) {}
372
bool operator==(const EVT VT) const {
373
if (V.SimpleTy == VT.V.SimpleTy) {
374
if (V.SimpleTy == MVT::INVALID_SIMPLE_VALUE_TYPE)
375
return LLVMTy == VT.LLVMTy;
380
bool operator!=(const EVT VT) const {
381
if (V.SimpleTy == VT.V.SimpleTy) {
382
if (V.SimpleTy == MVT::INVALID_SIMPLE_VALUE_TYPE)
383
return LLVMTy != VT.LLVMTy;
389
/// getFloatingPointVT - Returns the EVT that represents a floating point
390
/// type with the given number of bits. There are two floating point types
391
/// with 128 bits - this returns f128 rather than ppcf128.
392
static EVT getFloatingPointVT(unsigned BitWidth) {
393
return MVT::getFloatingPointVT(BitWidth);
396
/// getIntegerVT - Returns the EVT that represents an integer with the given
398
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth) {
399
MVT M = MVT::getIntegerVT(BitWidth);
400
if (M.SimpleTy == MVT::INVALID_SIMPLE_VALUE_TYPE)
401
return getExtendedIntegerVT(Context, BitWidth);
406
/// getVectorVT - Returns the EVT that represents a vector NumElements in
407
/// length, where each element is of type VT.
408
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements) {
409
MVT M = MVT::getVectorVT(VT.V, NumElements);
410
if (M.SimpleTy == MVT::INVALID_SIMPLE_VALUE_TYPE)
411
return getExtendedVectorVT(Context, VT, NumElements);
416
/// getIntVectorWithNumElements - Return any integer vector type that has
417
/// the specified number of elements.
418
static EVT getIntVectorWithNumElements(LLVMContext &C, unsigned NumElts) {
419
MVT M = MVT::getIntVectorWithNumElements(NumElts);
420
if (M.SimpleTy == MVT::INVALID_SIMPLE_VALUE_TYPE)
421
return getVectorVT(C, MVT::i8, NumElts);
426
/// isSimple - Test if the given EVT is simple (as opposed to being
428
bool isSimple() const {
429
return V.SimpleTy <= MVT::LastSimpleValueType;
432
/// isExtended - Test if the given EVT is extended (as opposed to
434
bool isExtended() const {
438
/// isFloatingPoint - Return true if this is a FP, or a vector FP type.
439
bool isFloatingPoint() const {
440
return isSimple() ? V.isFloatingPoint() : isExtendedFloatingPoint();
443
/// isInteger - Return true if this is an integer, or a vector integer type.
444
bool isInteger() const {
445
return isSimple() ? V.isInteger() : isExtendedInteger();
448
/// isVector - Return true if this is a vector value type.
449
bool isVector() const {
450
return isSimple() ? V.isVector() : isExtendedVector();
453
/// is64BitVector - Return true if this is a 64-bit vector type.
454
bool is64BitVector() const {
456
(V==MVT::v8i8 || V==MVT::v4i16 || V==MVT::v2i32 ||
457
V==MVT::v1i64 || V==MVT::v2f32) :
458
isExtended64BitVector();
461
/// is128BitVector - Return true if this is a 128-bit vector type.
462
bool is128BitVector() const {
464
(V==MVT::v16i8 || V==MVT::v8i16 || V==MVT::v4i32 ||
465
V==MVT::v2i64 || V==MVT::v4f32 || V==MVT::v2f64) :
466
isExtended128BitVector();
469
/// is256BitVector - Return true if this is a 256-bit vector type.
470
inline bool is256BitVector() const {
472
(V==MVT::v8f32 || V==MVT::v4f64 || V==MVT::v32i8 ||
473
V==MVT::v16i16 || V==MVT::v8i32 || V==MVT::v4i64) :
474
isExtended256BitVector();
477
/// isOverloaded - Return true if this is an overloaded type for TableGen.
478
bool isOverloaded() const {
479
return (V==MVT::iAny || V==MVT::fAny || V==MVT::vAny || V==MVT::iPTRAny);
482
/// isByteSized - Return true if the bit size is a multiple of 8.
483
bool isByteSized() const {
484
return (getSizeInBits() & 7) == 0;
487
/// isRound - Return true if the size is a power-of-two number of bytes.
488
bool isRound() const {
489
unsigned BitSize = getSizeInBits();
490
return BitSize >= 8 && !(BitSize & (BitSize - 1));
493
/// bitsEq - Return true if this has the same number of bits as VT.
494
bool bitsEq(EVT VT) const {
495
if (EVT::operator==(VT)) return true;
496
return getSizeInBits() == VT.getSizeInBits();
499
/// bitsGT - Return true if this has more bits than VT.
500
bool bitsGT(EVT VT) const {
501
if (EVT::operator==(VT)) return false;
502
return getSizeInBits() > VT.getSizeInBits();
505
/// bitsGE - Return true if this has no less bits than VT.
506
bool bitsGE(EVT VT) const {
507
if (EVT::operator==(VT)) return true;
508
return getSizeInBits() >= VT.getSizeInBits();
511
/// bitsLT - Return true if this has less bits than VT.
512
bool bitsLT(EVT VT) const {
513
if (EVT::operator==(VT)) return false;
514
return getSizeInBits() < VT.getSizeInBits();
517
/// bitsLE - Return true if this has no more bits than VT.
518
bool bitsLE(EVT VT) const {
519
if (EVT::operator==(VT)) return true;
520
return getSizeInBits() <= VT.getSizeInBits();
524
/// getSimpleVT - Return the SimpleValueType held in the specified
526
MVT getSimpleVT() const {
527
assert(isSimple() && "Expected a SimpleValueType!");
531
/// getScalarType - If this is a vector type, return the element type,
532
/// otherwise return this.
533
EVT getScalarType() const {
534
return isVector() ? getVectorElementType() : *this;
537
/// getVectorElementType - Given a vector type, return the type of
539
EVT getVectorElementType() const {
540
assert(isVector() && "Invalid vector type!");
542
return V.getVectorElementType();
544
return getExtendedVectorElementType();
547
/// getVectorNumElements - Given a vector type, return the number of
548
/// elements it contains.
549
unsigned getVectorNumElements() const {
550
assert(isVector() && "Invalid vector type!");
552
return V.getVectorNumElements();
554
return getExtendedVectorNumElements();
557
/// getSizeInBits - Return the size of the specified value type in bits.
558
unsigned getSizeInBits() const {
560
return V.getSizeInBits();
562
return getExtendedSizeInBits();
565
/// getStoreSize - Return the number of bytes overwritten by a store
566
/// of the specified value type.
567
unsigned getStoreSize() const {
568
return (getSizeInBits() + 7) / 8;
571
/// getStoreSizeInBits - Return the number of bits overwritten by a store
572
/// of the specified value type.
573
unsigned getStoreSizeInBits() const {
574
return getStoreSize() * 8;
577
/// getRoundIntegerType - Rounds the bit-width of the given integer EVT up
578
/// to the nearest power of two (and at least to eight), and returns the
579
/// integer EVT with that number of bits.
580
EVT getRoundIntegerType(LLVMContext &Context) const {
581
assert(isInteger() && !isVector() && "Invalid integer type!");
582
unsigned BitWidth = getSizeInBits();
586
return getIntegerVT(Context, 1 << Log2_32_Ceil(BitWidth));
589
/// getHalfSizedIntegerVT - Finds the smallest simple value type that is
590
/// greater than or equal to half the width of this EVT. If no simple
591
/// value type can be found, an extended integer value type of half the
592
/// size (rounded up) is returned.
593
EVT getHalfSizedIntegerVT(LLVMContext &Context) const {
594
assert(isInteger() && !isVector() && "Invalid integer type!");
595
unsigned EVTSize = getSizeInBits();
596
for (unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE;
597
IntVT <= MVT::LAST_INTEGER_VALUETYPE;
599
EVT HalfVT = EVT((MVT::SimpleValueType)IntVT);
600
if(HalfVT.getSizeInBits() * 2 >= EVTSize) {
604
return getIntegerVT(Context, (EVTSize + 1) / 2);
607
/// isPow2VectorType - Returns true if the given vector is a power of 2.
608
bool isPow2VectorType() const {
609
unsigned NElts = getVectorNumElements();
610
return !(NElts & (NElts - 1));
613
/// getPow2VectorType - Widens the length of the given vector EVT up to
614
/// the nearest power of 2 and returns that type.
615
EVT getPow2VectorType(LLVMContext &Context) const {
616
if (!isPow2VectorType()) {
617
unsigned NElts = getVectorNumElements();
618
unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
619
return EVT::getVectorVT(Context, getVectorElementType(), Pow2NElts);
626
/// getEVTString - This function returns value type as a string,
628
std::string getEVTString() const;
630
/// getTypeForEVT - This method returns an LLVM type corresponding to the
631
/// specified EVT. For integer types, this returns an unsigned type. Note
632
/// that this will abort for types that cannot be represented.
633
const Type *getTypeForEVT(LLVMContext &Context) const;
635
/// getEVT - Return the value type corresponding to the specified type.
636
/// This returns all pointers as iPTR. If HandleUnknown is true, unknown
637
/// types are returned as Other, otherwise they are invalid.
638
static EVT getEVT(const Type *Ty, bool HandleUnknown = false);
640
intptr_t getRawBits() {
644
return (intptr_t)(LLVMTy);
647
/// compareRawBits - A meaningless but well-behaved order, useful for
648
/// constructing containers.
649
struct compareRawBits {
650
bool operator()(EVT L, EVT R) const {
651
if (L.V.SimpleTy == R.V.SimpleTy)
652
return L.LLVMTy < R.LLVMTy;
654
return L.V.SimpleTy < R.V.SimpleTy;
659
// Methods for handling the Extended-type case in functions above.
660
// These are all out-of-line to prevent users of this header file
661
// from having a dependency on Type.h.
662
static EVT getExtendedIntegerVT(LLVMContext &C, unsigned BitWidth);
663
static EVT getExtendedVectorVT(LLVMContext &C, EVT VT,
664
unsigned NumElements);
665
bool isExtendedFloatingPoint() const;
666
bool isExtendedInteger() const;
667
bool isExtendedVector() const;
668
bool isExtended64BitVector() const;
669
bool isExtended128BitVector() const;
670
bool isExtended256BitVector() const;
671
EVT getExtendedVectorElementType() const;
672
unsigned getExtendedVectorNumElements() const;
673
unsigned getExtendedSizeInBits() const;
676
} // End llvm namespace