1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 11:42:57 +01:00

Initial infrastructure for arbitrary precision integer

codegen support.  This should have no effect on codegen
for other types.  Debatable bits: (1) the use (abuse?)
of a set in SDNode::getValueTypeList; (2) the length of
getTypeToTransformTo, which maybe should be refactored
with a non-inline part for extended value types.

llvm-svn: 43030
This commit is contained in:
Duncan Sands 2007-10-16 09:56:48 +00:00
parent 12d0747c70
commit 9d622a6de1
4 changed files with 185 additions and 96 deletions

View File

@ -19,6 +19,7 @@
#include <cassert> #include <cassert>
#include <string> #include <string>
#include "llvm/Support/DataTypes.h" #include "llvm/Support/DataTypes.h"
#include "llvm/Support/MathExtras.h"
namespace llvm { namespace llvm {
class Type; class Type;
@ -38,6 +39,9 @@ namespace MVT { // MVT = Machine Value Types
i64 = 5, // This is a 64 bit integer value i64 = 5, // This is a 64 bit integer value
i128 = 6, // This is a 128 bit integer value i128 = 6, // This is a 128 bit integer value
FIRST_INTEGER_VALUETYPE = i1,
LAST_INTEGER_VALUETYPE = i128,
f32 = 7, // This is a 32 bit floating point value f32 = 7, // This is a 32 bit floating point value
f64 = 8, // This is a 64 bit floating point value f64 = 8, // This is a 64 bit floating point value
f80 = 9, // This is a 80 bit floating point value f80 = 9, // This is a 80 bit floating point value
@ -46,22 +50,22 @@ namespace MVT { // MVT = Machine Value Types
Flag = 12, // This is a condition code or machine flag. Flag = 12, // This is a condition code or machine flag.
isVoid = 13, // This has no value isVoid = 13, // This has no value
v8i8 = 14, // 8 x i8 v8i8 = 14, // 8 x i8
v4i16 = 15, // 4 x i16 v4i16 = 15, // 4 x i16
v2i32 = 16, // 2 x i32 v2i32 = 16, // 2 x i32
v1i64 = 17, // 1 x i64 v1i64 = 17, // 1 x i64
v16i8 = 18, // 16 x i8 v16i8 = 18, // 16 x i8
v8i16 = 19, // 8 x i16 v8i16 = 19, // 8 x i16
v3i32 = 20, // 3 x i32 v3i32 = 20, // 3 x i32
v4i32 = 21, // 4 x i32 v4i32 = 21, // 4 x i32
v2i64 = 22, // 2 x i64 v2i64 = 22, // 2 x i64
v2f32 = 23, // 2 x f32 v2f32 = 23, // 2 x f32
v3f32 = 24, // 3 x f32 v3f32 = 24, // 3 x f32
v4f32 = 25, // 4 x f32 v4f32 = 25, // 4 x f32
v2f64 = 26, // 2 x f64 v2f64 = 26, // 2 x f64
FIRST_VECTOR_VALUETYPE = v8i8, FIRST_VECTOR_VALUETYPE = v8i8,
LAST_VECTOR_VALUETYPE = v2f64, LAST_VECTOR_VALUETYPE = v2f64,
@ -70,12 +74,12 @@ namespace MVT { // MVT = Machine Value Types
// fAny - Any floating-point or vector floating-point value. This is used // fAny - Any floating-point or vector floating-point value. This is used
// for intrinsics that have overloadings based on floating-point types. // for intrinsics that have overloadings based on floating-point types.
// This is only for tblgen's consumption! // This is only for tblgen's consumption!
fAny = 253, fAny = 253,
// iAny - An integer or vector integer value of any bit width. This is // iAny - An integer or vector integer value of any bit width. This is
// used for intrinsics that have overloadings based on integer bit widths. // used for intrinsics that have overloadings based on integer bit widths.
// This is only for tblgen's consumption! // This is only for tblgen's consumption!
iAny = 254, iAny = 254,
// iPTR - An int value the size of the pointer of the current // iPTR - An int value the size of the pointer of the current
// target. This should only be used internal to tblgen! // target. This should only be used internal to tblgen!
@ -93,17 +97,36 @@ namespace MVT { // MVT = Machine Value Types
/// value types that are not legal. /// value types that are not legal.
/// ///
/// @internal /// @internal
/// Currently extended types are always vector types. Extended types are /// Extended types are either vector types or arbitrary precision integers.
/// encoded by having the first SimpleTypeBits bits encode the vector /// Arbitrary precision integers have iAny in the first SimpleTypeBits bits,
/// element type (which must be a scalar type) and the remaining upper /// and the bit-width in the next PrecisionBits bits, offset by minus one.
/// bits encode the vector length, offset by one. /// Vector types are encoded by having the first SimpleTypeBits+PrecisionBits
/// bits encode the vector element type (which must be a scalar type, possibly
/// an arbitrary precision integer) and the remaining VectorBits upper bits
/// encode the vector length, offset by one.
///
/// 31--------------16-----------8-------------0
/// | Vector length | Precision | Simple type |
/// | Vector element |
typedef uint32_t ValueType; typedef uint32_t ValueType;
static const int SimpleTypeBits = 8; static const int SimpleTypeBits = 8;
static const int PrecisionBits = 8;
static const int VectorBits = 32 - SimpleTypeBits - PrecisionBits;
static const uint32_t SimpleTypeMask = static const uint32_t SimpleTypeMask =
(~uint32_t(0) << (32 - SimpleTypeBits)) >> (32 - SimpleTypeBits); (~uint32_t(0) << (32 - SimpleTypeBits)) >> (32 - SimpleTypeBits);
static const uint32_t PrecisionMask =
((~uint32_t(0) << VectorBits) >> (32 - PrecisionBits)) << SimpleTypeBits;
static const uint32_t VectorMask =
(~uint32_t(0) >> (32 - VectorBits)) << (32 - VectorBits);
static const uint32_t ElementMask =
(~uint32_t(0) << VectorBits) >> VectorBits;
/// MVT::isExtendedVT - Test if the given ValueType is extended /// MVT::isExtendedVT - Test if the given ValueType is extended
/// (as opposed to being simple). /// (as opposed to being simple).
static inline bool isExtendedVT(ValueType VT) { static inline bool isExtendedVT(ValueType VT) {
@ -114,33 +137,34 @@ namespace MVT { // MVT = Machine Value Types
/// type. /// type.
static inline bool isInteger(ValueType VT) { static inline bool isInteger(ValueType VT) {
ValueType SVT = VT & SimpleTypeMask; ValueType SVT = VT & SimpleTypeMask;
return (SVT >= i1 && SVT <= i128) || (SVT >= v8i8 && SVT <= v2i64); return (SVT >= FIRST_INTEGER_VALUETYPE && SVT <= LAST_INTEGER_VALUETYPE) ||
(SVT >= v8i8 && SVT <= v2i64) || (SVT == iAny && (VT & PrecisionMask));
} }
/// MVT::isFloatingPoint - Return true if this is an FP, or a vector FP type. /// MVT::isFloatingPoint - Return true if this is an FP, or a vector FP type.
static inline bool isFloatingPoint(ValueType VT) { static inline bool isFloatingPoint(ValueType VT) {
ValueType SVT = VT & SimpleTypeMask; ValueType SVT = VT & SimpleTypeMask;
return (SVT >= f32 && SVT <= ppcf128) || (SVT >= v2f32 && SVT <= v2f64); return (SVT >= f32 && SVT <= ppcf128) || (SVT >= v2f32 && SVT <= v2f64);
} }
/// MVT::isVector - Return true if this is a vector value type. /// MVT::isVector - Return true if this is a vector value type.
static inline bool isVector(ValueType VT) { static inline bool isVector(ValueType VT) {
return (VT >= FIRST_VECTOR_VALUETYPE && VT <= LAST_VECTOR_VALUETYPE) || return (VT >= FIRST_VECTOR_VALUETYPE && VT <= LAST_VECTOR_VALUETYPE) ||
isExtendedVT(VT); (VT & VectorMask);
} }
/// MVT::getVectorElementType - Given a vector type, return the type of /// MVT::getVectorElementType - Given a vector type, return the type of
/// each element. /// each element.
static inline ValueType getVectorElementType(ValueType VT) { static inline ValueType getVectorElementType(ValueType VT) {
assert(isVector(VT) && "Invalid vector type!");
switch (VT) { switch (VT) {
default: default:
if (isExtendedVT(VT)) assert(isExtendedVT(VT) && "Unknown simple vector type!");
return VT & SimpleTypeMask; return VT & ElementMask;
assert(0 && "Invalid vector type!");
case v8i8 : case v8i8 :
case v16i8: return i8; case v16i8: return i8;
case v4i16: case v4i16:
case v8i16: return i16; case v8i16: return i16;
case v2i32: case v2i32:
case v3i32: case v3i32:
case v4i32: return i32; case v4i32: return i32;
@ -152,20 +176,20 @@ namespace MVT { // MVT = Machine Value Types
case v2f64: return f64; case v2f64: return f64;
} }
} }
/// MVT::getVectorNumElements - Given a vector type, return the /// MVT::getVectorNumElements - Given a vector type, return the
/// number of elements it contains. /// number of elements it contains.
static inline unsigned getVectorNumElements(ValueType VT) { static inline unsigned getVectorNumElements(ValueType VT) {
assert(isVector(VT) && "Invalid vector type!");
switch (VT) { switch (VT) {
default: default:
if (isExtendedVT(VT)) assert(isExtendedVT(VT) && "Unknown simple vector type!");
return ((VT & ~SimpleTypeMask) >> SimpleTypeBits) - 1; return ((VT & VectorMask) >> (32 - VectorBits)) - 1;
assert(0 && "Invalid vector type!");
case v16i8: return 16; case v16i8: return 16;
case v8i8 : case v8i8 :
case v8i16: return 8; case v8i16: return 8;
case v4i16: case v4i16:
case v4i32: case v4i32:
case v4f32: return 4; case v4f32: return 4;
case v3i32: case v3i32:
case v3f32: return 3; case v3f32: return 3;
@ -176,17 +200,20 @@ namespace MVT { // MVT = Machine Value Types
case v1i64: return 1; case v1i64: return 1;
} }
} }
/// MVT::getSizeInBits - Return the size of the specified value type /// MVT::getSizeInBits - Return the size of the specified value type
/// in bits. /// in bits.
/// ///
static inline unsigned getSizeInBits(ValueType VT) { static inline unsigned getSizeInBits(ValueType VT) {
switch (VT) { switch (VT) {
default: default:
if (isExtendedVT(VT)) assert(isExtendedVT(VT) && "ValueType has no known size!");
if (isVector(VT))
return getSizeInBits(getVectorElementType(VT)) * return getSizeInBits(getVectorElementType(VT)) *
getVectorNumElements(VT); getVectorNumElements(VT);
assert(0 && "ValueType has no known size!"); if (isInteger(VT))
return ((VT & PrecisionMask) >> SimpleTypeBits) + 1;
assert(0 && "Unknown value type!");
case MVT::i1 : return 1; case MVT::i1 : return 1;
case MVT::i8 : return 8; case MVT::i8 : return 8;
case MVT::i16 : return 16; case MVT::i16 : return 16;
@ -196,7 +223,7 @@ namespace MVT { // MVT = Machine Value Types
case MVT::i64 : case MVT::i64 :
case MVT::v8i8: case MVT::v8i8:
case MVT::v4i16: case MVT::v4i16:
case MVT::v2i32: case MVT::v2i32:
case MVT::v1i64: case MVT::v1i64:
case MVT::v2f32: return 64; case MVT::v2f32: return 64;
case MVT::f80 : return 80; case MVT::f80 : return 80;
@ -204,7 +231,7 @@ namespace MVT { // MVT = Machine Value Types
case MVT::v3f32: return 96; case MVT::v3f32: return 96;
case MVT::f128: case MVT::f128:
case MVT::ppcf128: case MVT::ppcf128:
case MVT::i128: case MVT::i128:
case MVT::v16i8: case MVT::v16i8:
case MVT::v8i16: case MVT::v8i16:
case MVT::v4i32: case MVT::v4i32:
@ -213,7 +240,46 @@ namespace MVT { // MVT = Machine Value Types
case MVT::v2f64: return 128; case MVT::v2f64: return 128;
} }
} }
/// MVT::getIntegerType - Returns the ValueType that represents an integer
/// with the given number of bits.
///
static inline ValueType getIntegerType(unsigned BitWidth) {
switch (BitWidth) {
default:
break;
case 1:
return MVT::i1;
case 8:
return MVT::i8;
case 16:
return MVT::i16;
case 32:
return MVT::i32;
case 64:
return MVT::i64;
case 128:
return MVT::i128;
}
ValueType Result = iAny |
(((BitWidth - 1) << SimpleTypeBits) & PrecisionMask);
assert(getSizeInBits(Result) == BitWidth && "Bad bit width!");
return Result;
}
/// MVT::RoundIntegerType - Rounds the bit-width of the given integer
/// ValueType up to the nearest power of two (and at least to eight),
/// and returns the integer ValueType with that number of bits.
///
static inline ValueType RoundIntegerType(ValueType VT) {
assert(isInteger(VT) && !isVector(VT) && "Invalid integer type!");
unsigned BitWidth = getSizeInBits(VT);
if (BitWidth <= 8)
return MVT::i8;
else
return getIntegerType(1 << Log2_32_Ceil(BitWidth));
}
/// MVT::getVectorType - Returns the ValueType that represents a vector /// MVT::getVectorType - Returns the ValueType that represents a vector
/// NumElements in length, where each element is of type VT. /// NumElements in length, where each element is of type VT.
/// ///
@ -247,7 +313,7 @@ namespace MVT { // MVT = Machine Value Types
if (NumElements == 2) return MVT::v2f64; if (NumElements == 2) return MVT::v2f64;
break; break;
} }
ValueType Result = VT | ((NumElements + 1) << SimpleTypeBits); ValueType Result = VT | ((NumElements + 1) << (32 - VectorBits));
assert(getVectorElementType(Result) == VT && assert(getVectorElementType(Result) == VT &&
"Bad vector element type!"); "Bad vector element type!");
assert(getVectorNumElements(Result) == NumElements && assert(getVectorNumElements(Result) == NumElements &&
@ -268,8 +334,8 @@ namespace MVT { // MVT = Machine Value Types
case 16: return v16i8; case 16: return v16i8;
} }
} }
/// MVT::getIntVTBitMask - Return an integer with 1's every place there are /// MVT::getIntVTBitMask - Return an integer with 1's every place there are
/// bits in the specified integer value type. /// bits in the specified integer value type.
static inline uint64_t getIntVTBitMask(ValueType VT) { static inline uint64_t getIntVTBitMask(ValueType VT) {
@ -291,7 +357,7 @@ namespace MVT { // MVT = Machine Value Types
/// to the specified ValueType. For integer types, this returns an unsigned /// to the specified ValueType. For integer types, this returns an unsigned
/// type. Note that this will abort for types that cannot be represented. /// type. Note that this will abort for types that cannot be represented.
const Type *getTypeForValueType(ValueType VT); const Type *getTypeForValueType(ValueType VT);
/// MVT::getValueType - Return the value type corresponding to the specified /// MVT::getValueType - Return the value type corresponding to the specified
/// type. This returns all pointers as MVT::iPTR. If HandleUnknown is true, /// type. This returns all pointers as MVT::iPTR. If HandleUnknown is true,
/// unknown types are returned as Other, otherwise they are invalid. /// unknown types are returned as Other, otherwise they are invalid.

View File

@ -150,7 +150,13 @@ public:
} }
LegalizeAction getTypeAction(MVT::ValueType VT) const { LegalizeAction getTypeAction(MVT::ValueType VT) const {
if (MVT::isExtendedVT(VT)) return Expand; if (MVT::isExtendedVT(VT)) {
if (MVT::isVector(VT)) return Expand;
if (MVT::isInteger(VT))
// First promote to a power-of-two size, then expand if necessary.
return VT == MVT::RoundIntegerType(VT) ? Expand : Promote;
assert(0 && "Unsupported extended type!");
}
return (LegalizeAction)((ValueTypeActions[VT>>4] >> ((2*VT) & 31)) & 3); return (LegalizeAction)((ValueTypeActions[VT>>4] >> ((2*VT) & 31)) & 3);
} }
void setTypeAction(MVT::ValueType VT, LegalizeAction Action) { void setTypeAction(MVT::ValueType VT, LegalizeAction Action) {
@ -179,19 +185,34 @@ public:
/// to get to the smaller register. For illegal floating point types, this /// to get to the smaller register. For illegal floating point types, this
/// returns the integer type to transform to. /// returns the integer type to transform to.
MVT::ValueType getTypeToTransformTo(MVT::ValueType VT) const { MVT::ValueType getTypeToTransformTo(MVT::ValueType VT) const {
if (MVT::isExtendedVT(VT)) if (!MVT::isExtendedVT(VT)) {
MVT::ValueType NVT = TransformToType[VT];
assert(getTypeAction(NVT) != Promote &&
"Promote may not follow Expand or Promote");
return NVT;
}
if (MVT::isVector(VT))
return MVT::getVectorType(MVT::getVectorElementType(VT), return MVT::getVectorType(MVT::getVectorElementType(VT),
MVT::getVectorNumElements(VT) / 2); MVT::getVectorNumElements(VT) / 2);
if (MVT::isInteger(VT)) {
return TransformToType[VT]; MVT::ValueType NVT = MVT::RoundIntegerType(VT);
if (NVT == VT)
// Size is a power of two - expand to half the size.
return MVT::getIntegerType(MVT::getSizeInBits(VT) / 2);
else
// Promote to a power of two size, avoiding multi-step promotion.
return getTypeAction(NVT) == Promote ? getTypeToTransformTo(NVT) : NVT;
}
assert(0 && "Unsupported extended type!");
} }
/// getTypeToExpandTo - For types supported by the target, this is an /// getTypeToExpandTo - For types supported by the target, this is an
/// identity function. For types that must be expanded (i.e. integer types /// identity function. For types that must be expanded (i.e. integer types
/// that are larger than the largest integer register or illegal floating /// that are larger than the largest integer register or illegal floating
/// point types), this returns the largest legal type it will be expanded to. /// point types), this returns the largest legal type it will be expanded to.
MVT::ValueType getTypeToExpandTo(MVT::ValueType VT) const { MVT::ValueType getTypeToExpandTo(MVT::ValueType VT) const {
assert(!MVT::isExtendedVT(VT)); assert(!MVT::isVector(VT));
while (true) { while (true) {
switch (getTypeAction(VT)) { switch (getTypeAction(VT)) {
case Legal: case Legal:
@ -252,7 +273,7 @@ public:
/// expanded to some other code sequence, or the target has a custom expander /// expanded to some other code sequence, or the target has a custom expander
/// for it. /// for it.
LegalizeAction getOperationAction(unsigned Op, MVT::ValueType VT) const { LegalizeAction getOperationAction(unsigned Op, MVT::ValueType VT) const {
if (MVT::isExtendedVT(VT)) return Expand; if (MVT::isExtendedVT(VT)) return getTypeAction(VT);
return (LegalizeAction)((OpActions[Op] >> (2*VT)) & 3); return (LegalizeAction)((OpActions[Op] >> (2*VT)) & 3);
} }
@ -268,7 +289,7 @@ public:
/// expanded to some other code sequence, or the target has a custom expander /// expanded to some other code sequence, or the target has a custom expander
/// for it. /// for it.
LegalizeAction getLoadXAction(unsigned LType, MVT::ValueType VT) const { LegalizeAction getLoadXAction(unsigned LType, MVT::ValueType VT) const {
if (MVT::isExtendedVT(VT)) return Expand; if (MVT::isExtendedVT(VT)) return getTypeAction(VT);
return (LegalizeAction)((LoadXActions[LType] >> (2*VT)) & 3); return (LegalizeAction)((LoadXActions[LType] >> (2*VT)) & 3);
} }
@ -284,7 +305,7 @@ public:
/// expanded to some other code sequence, or the target has a custom expander /// expanded to some other code sequence, or the target has a custom expander
/// for it. /// for it.
LegalizeAction getStoreXAction(MVT::ValueType VT) const { LegalizeAction getStoreXAction(MVT::ValueType VT) const {
if (MVT::isExtendedVT(VT)) return Expand; if (MVT::isExtendedVT(VT)) return getTypeAction(VT);
return (LegalizeAction)((StoreXActions >> (2*VT)) & 3); return (LegalizeAction)((StoreXActions >> (2*VT)) & 3);
} }
@ -300,7 +321,7 @@ public:
/// for it. /// for it.
LegalizeAction LegalizeAction
getIndexedLoadAction(unsigned IdxMode, MVT::ValueType VT) const { getIndexedLoadAction(unsigned IdxMode, MVT::ValueType VT) const {
if (MVT::isExtendedVT(VT)) return Expand; if (MVT::isExtendedVT(VT)) return getTypeAction(VT);
return (LegalizeAction)((IndexedModeActions[0][IdxMode] >> (2*VT)) & 3); return (LegalizeAction)((IndexedModeActions[0][IdxMode] >> (2*VT)) & 3);
} }
@ -317,7 +338,7 @@ public:
/// for it. /// for it.
LegalizeAction LegalizeAction
getIndexedStoreAction(unsigned IdxMode, MVT::ValueType VT) const { getIndexedStoreAction(unsigned IdxMode, MVT::ValueType VT) const {
if (MVT::isExtendedVT(VT)) return Expand; if (MVT::isExtendedVT(VT)) return getTypeAction(VT);
return (LegalizeAction)((IndexedModeActions[1][IdxMode] >> (2*VT)) & 3); return (LegalizeAction)((IndexedModeActions[1][IdxMode] >> (2*VT)) & 3);
} }
@ -385,13 +406,15 @@ public:
MVT::ValueType getRegisterType(MVT::ValueType VT) const { MVT::ValueType getRegisterType(MVT::ValueType VT) const {
if (!MVT::isExtendedVT(VT)) if (!MVT::isExtendedVT(VT))
return RegisterTypeForVT[VT]; return RegisterTypeForVT[VT];
if (MVT::isVector(VT)) {
MVT::ValueType VT1, RegisterVT; MVT::ValueType VT1, RegisterVT;
unsigned NumIntermediates; unsigned NumIntermediates;
(void)getVectorTypeBreakdown(VT, VT1, NumIntermediates, RegisterVT); (void)getVectorTypeBreakdown(VT, VT1, NumIntermediates, RegisterVT);
return RegisterVT; return RegisterVT;
}
assert(0 && "Unsupported extended type!");
} }
/// getNumRegisters - Return the number of registers that this ValueType will /// getNumRegisters - Return the number of registers that this ValueType will
/// eventually require. This is one for any types promoted to live in larger /// eventually require. This is one for any types promoted to live in larger
/// registers, but may be more than one for types (like i64) that are split /// registers, but may be more than one for types (like i64) that are split
@ -399,10 +422,12 @@ public:
unsigned getNumRegisters(MVT::ValueType VT) const { unsigned getNumRegisters(MVT::ValueType VT) const {
if (!MVT::isExtendedVT(VT)) if (!MVT::isExtendedVT(VT))
return NumRegistersForVT[VT]; return NumRegistersForVT[VT];
if (MVT::isVector(VT)) {
MVT::ValueType VT1, VT2; MVT::ValueType VT1, VT2;
unsigned NumIntermediates; unsigned NumIntermediates;
return getVectorTypeBreakdown(VT, VT1, NumIntermediates, VT2); return getVectorTypeBreakdown(VT, VT1, NumIntermediates, VT2);
}
assert(0 && "Unsupported extended type!");
} }
/// hasTargetDAGCombine - If true, the target has custom DAG combine /// hasTargetDAGCombine - If true, the target has custom DAG combine

View File

@ -28,6 +28,7 @@
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringExtras.h"
#include <algorithm> #include <algorithm>
@ -846,6 +847,7 @@ SDOperand SelectionDAG::getBasicBlock(MachineBasicBlock *MBB) {
} }
SDOperand SelectionDAG::getValueType(MVT::ValueType VT) { SDOperand SelectionDAG::getValueType(MVT::ValueType VT) {
assert(!MVT::isExtendedVT(VT) && "Expecting a simple value type!");
if ((unsigned)VT >= ValueTypeNodes.size()) if ((unsigned)VT >= ValueTypeNodes.size())
ValueTypeNodes.resize(VT+1); ValueTypeNodes.resize(VT+1);
if (ValueTypeNodes[VT] == 0) { if (ValueTypeNodes[VT] == 0) {
@ -1734,7 +1736,8 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
assert(MVT::isInteger(VT) && MVT::isInteger(Operand.getValueType()) && assert(MVT::isInteger(VT) && MVT::isInteger(Operand.getValueType()) &&
"Invalid SIGN_EXTEND!"); "Invalid SIGN_EXTEND!");
if (Operand.getValueType() == VT) return Operand; // noop extension if (Operand.getValueType() == VT) return Operand; // noop extension
assert(Operand.getValueType() < VT && "Invalid sext node, dst < src!"); assert(MVT::getSizeInBits(Operand.getValueType()) < MVT::getSizeInBits(VT)
&& "Invalid sext node, dst < src!");
if (OpOpcode == ISD::SIGN_EXTEND || OpOpcode == ISD::ZERO_EXTEND) if (OpOpcode == ISD::SIGN_EXTEND || OpOpcode == ISD::ZERO_EXTEND)
return getNode(OpOpcode, VT, Operand.Val->getOperand(0)); return getNode(OpOpcode, VT, Operand.Val->getOperand(0));
break; break;
@ -1742,7 +1745,8 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
assert(MVT::isInteger(VT) && MVT::isInteger(Operand.getValueType()) && assert(MVT::isInteger(VT) && MVT::isInteger(Operand.getValueType()) &&
"Invalid ZERO_EXTEND!"); "Invalid ZERO_EXTEND!");
if (Operand.getValueType() == VT) return Operand; // noop extension if (Operand.getValueType() == VT) return Operand; // noop extension
assert(Operand.getValueType() < VT && "Invalid zext node, dst < src!"); assert(MVT::getSizeInBits(Operand.getValueType()) < MVT::getSizeInBits(VT)
&& "Invalid zext node, dst < src!");
if (OpOpcode == ISD::ZERO_EXTEND) // (zext (zext x)) -> (zext x) if (OpOpcode == ISD::ZERO_EXTEND) // (zext (zext x)) -> (zext x)
return getNode(ISD::ZERO_EXTEND, VT, Operand.Val->getOperand(0)); return getNode(ISD::ZERO_EXTEND, VT, Operand.Val->getOperand(0));
break; break;
@ -1750,7 +1754,8 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
assert(MVT::isInteger(VT) && MVT::isInteger(Operand.getValueType()) && assert(MVT::isInteger(VT) && MVT::isInteger(Operand.getValueType()) &&
"Invalid ANY_EXTEND!"); "Invalid ANY_EXTEND!");
if (Operand.getValueType() == VT) return Operand; // noop extension if (Operand.getValueType() == VT) return Operand; // noop extension
assert(Operand.getValueType() < VT && "Invalid anyext node, dst < src!"); assert(MVT::getSizeInBits(Operand.getValueType()) < MVT::getSizeInBits(VT)
&& "Invalid anyext node, dst < src!");
if (OpOpcode == ISD::ZERO_EXTEND || OpOpcode == ISD::SIGN_EXTEND) if (OpOpcode == ISD::ZERO_EXTEND || OpOpcode == ISD::SIGN_EXTEND)
// (ext (zext x)) -> (zext x) and (ext (sext x)) -> (sext x) // (ext (zext x)) -> (zext x) and (ext (sext x)) -> (sext x)
return getNode(OpOpcode, VT, Operand.Val->getOperand(0)); return getNode(OpOpcode, VT, Operand.Val->getOperand(0));
@ -1759,15 +1764,18 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
assert(MVT::isInteger(VT) && MVT::isInteger(Operand.getValueType()) && assert(MVT::isInteger(VT) && MVT::isInteger(Operand.getValueType()) &&
"Invalid TRUNCATE!"); "Invalid TRUNCATE!");
if (Operand.getValueType() == VT) return Operand; // noop truncate if (Operand.getValueType() == VT) return Operand; // noop truncate
assert(Operand.getValueType() > VT && "Invalid truncate node, src < dst!"); assert(MVT::getSizeInBits(Operand.getValueType()) > MVT::getSizeInBits(VT)
&& "Invalid truncate node, src < dst!");
if (OpOpcode == ISD::TRUNCATE) if (OpOpcode == ISD::TRUNCATE)
return getNode(ISD::TRUNCATE, VT, Operand.Val->getOperand(0)); return getNode(ISD::TRUNCATE, VT, Operand.Val->getOperand(0));
else if (OpOpcode == ISD::ZERO_EXTEND || OpOpcode == ISD::SIGN_EXTEND || else if (OpOpcode == ISD::ZERO_EXTEND || OpOpcode == ISD::SIGN_EXTEND ||
OpOpcode == ISD::ANY_EXTEND) { OpOpcode == ISD::ANY_EXTEND) {
// If the source is smaller than the dest, we still need an extend. // If the source is smaller than the dest, we still need an extend.
if (Operand.Val->getOperand(0).getValueType() < VT) if (MVT::getSizeInBits(Operand.Val->getOperand(0).getValueType())
< MVT::getSizeInBits(VT))
return getNode(OpOpcode, VT, Operand.Val->getOperand(0)); return getNode(OpOpcode, VT, Operand.Val->getOperand(0));
else if (Operand.Val->getOperand(0).getValueType() > VT) else if (MVT::getSizeInBits(Operand.Val->getOperand(0).getValueType())
> MVT::getSizeInBits(VT))
return getNode(ISD::TRUNCATE, VT, Operand.Val->getOperand(0)); return getNode(ISD::TRUNCATE, VT, Operand.Val->getOperand(0));
else else
return Operand.Val->getOperand(0); return Operand.Val->getOperand(0);
@ -1874,7 +1882,8 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
assert(VT == N1.getValueType() && "Not an inreg round!"); assert(VT == N1.getValueType() && "Not an inreg round!");
assert(MVT::isFloatingPoint(VT) && MVT::isFloatingPoint(EVT) && assert(MVT::isFloatingPoint(VT) && MVT::isFloatingPoint(EVT) &&
"Cannot FP_ROUND_INREG integer types"); "Cannot FP_ROUND_INREG integer types");
assert(EVT <= VT && "Not rounding down!"); assert(MVT::getSizeInBits(EVT) <= MVT::getSizeInBits(VT) &&
"Not rounding down!");
break; break;
} }
case ISD::AssertSext: case ISD::AssertSext:
@ -1884,7 +1893,8 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
assert(VT == N1.getValueType() && "Not an inreg extend!"); assert(VT == N1.getValueType() && "Not an inreg extend!");
assert(MVT::isInteger(VT) && MVT::isInteger(EVT) && assert(MVT::isInteger(VT) && MVT::isInteger(EVT) &&
"Cannot *_EXTEND_INREG FP types"); "Cannot *_EXTEND_INREG FP types");
assert(EVT <= VT && "Not extending!"); assert(MVT::getSizeInBits(EVT) <= MVT::getSizeInBits(VT) &&
"Not extending!");
} }
default: break; default: break;
@ -2299,7 +2309,8 @@ SDOperand SelectionDAG::getExtLoad(ISD::LoadExtType ExtType, MVT::ValueType VT,
if (MVT::isVector(VT)) if (MVT::isVector(VT))
assert(EVT == MVT::getVectorElementType(VT) && "Invalid vector extload!"); assert(EVT == MVT::getVectorElementType(VT) && "Invalid vector extload!");
else else
assert(EVT < VT && "Should only be an extending load, not truncating!"); assert(MVT::getSizeInBits(EVT) < MVT::getSizeInBits(VT) &&
"Should only be an extending load, not truncating!");
assert((ExtType == ISD::EXTLOAD || MVT::isInteger(VT)) && assert((ExtType == ISD::EXTLOAD || MVT::isInteger(VT)) &&
"Cannot sign/zero extend a FP/Vector load!"); "Cannot sign/zero extend a FP/Vector load!");
assert(MVT::isInteger(VT) == MVT::isInteger(EVT) && assert(MVT::isInteger(VT) == MVT::isInteger(EVT) &&
@ -2415,7 +2426,8 @@ SDOperand SelectionDAG::getTruncStore(SDOperand Chain, SDOperand Val,
MVT::ValueType VT = Val.getValueType(); MVT::ValueType VT = Val.getValueType();
bool isTrunc = VT != SVT; bool isTrunc = VT != SVT;
assert(VT > SVT && "Not a truncation?"); assert(MVT::getSizeInBits(VT) > MVT::getSizeInBits(SVT) &&
"Not a truncation?");
assert(MVT::isInteger(VT) == MVT::isInteger(SVT) && assert(MVT::isInteger(VT) == MVT::isInteger(SVT) &&
"Can't do FP-INT conversion!"); "Can't do FP-INT conversion!");
@ -2648,18 +2660,7 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, SDVTList VTList,
} }
SDVTList SelectionDAG::getVTList(MVT::ValueType VT) { SDVTList SelectionDAG::getVTList(MVT::ValueType VT) {
if (!MVT::isExtendedVT(VT)) return makeVTList(SDNode::getValueTypeList(VT), 1);
return makeVTList(SDNode::getValueTypeList(VT), 1);
for (std::list<std::vector<MVT::ValueType> >::iterator I = VTList.begin(),
E = VTList.end(); I != E; ++I) {
if (I->size() == 1 && (*I)[0] == VT)
return makeVTList(&(*I)[0], 1);
}
std::vector<MVT::ValueType> V;
V.push_back(VT);
VTList.push_front(V);
return makeVTList(&(*VTList.begin())[0], 1);
} }
SDVTList SelectionDAG::getVTList(MVT::ValueType VT1, MVT::ValueType VT2) { SDVTList SelectionDAG::getVTList(MVT::ValueType VT1, MVT::ValueType VT2) {
@ -3427,11 +3428,16 @@ void SDNode::Profile(FoldingSetNodeID &ID) {
/// getValueTypeList - Return a pointer to the specified value type. /// getValueTypeList - Return a pointer to the specified value type.
/// ///
MVT::ValueType *SDNode::getValueTypeList(MVT::ValueType VT) { MVT::ValueType *SDNode::getValueTypeList(MVT::ValueType VT) {
static MVT::ValueType VTs[MVT::LAST_VALUETYPE]; if (MVT::isExtendedVT(VT)) {
VTs[VT] = VT; static std::set<MVT::ValueType> EVTs;
return &VTs[VT]; return (MVT::ValueType *)&(*EVTs.insert(VT).first);
} else {
static MVT::ValueType VTs[MVT::LAST_VALUETYPE];
VTs[VT] = VT;
return &VTs[VT];
}
} }
/// hasNUsesOfValue - Return true if there are exactly NUSES uses of the /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
/// indicated value. This method ignores uses of other values defined by this /// indicated value. This method ignores uses of other values defined by this
/// operation. /// operation.

View File

@ -22,9 +22,11 @@ using namespace llvm;
std::string MVT::getValueTypeString(MVT::ValueType VT) { std::string MVT::getValueTypeString(MVT::ValueType VT) {
switch (VT) { switch (VT) {
default: default:
if (isExtendedVT(VT)) if (isVector(VT))
return "v" + utostr(getVectorNumElements(VT)) + return "v" + utostr(getVectorNumElements(VT)) +
getValueTypeString(getVectorElementType(VT)); getValueTypeString(getVectorElementType(VT));
if (isInteger(VT))
return "i" + utostr(getSizeInBits(VT));
assert(0 && "Invalid ValueType!"); assert(0 && "Invalid ValueType!");
case MVT::i1: return "i1"; case MVT::i1: return "i1";
case MVT::i8: return "i8"; case MVT::i8: return "i8";
@ -62,9 +64,11 @@ std::string MVT::getValueTypeString(MVT::ValueType VT) {
const Type *MVT::getTypeForValueType(MVT::ValueType VT) { const Type *MVT::getTypeForValueType(MVT::ValueType VT) {
switch (VT) { switch (VT) {
default: default:
if (isExtendedVT(VT)) if (isVector(VT))
return VectorType::get(getTypeForValueType(getVectorElementType(VT)), return VectorType::get(getTypeForValueType(getVectorElementType(VT)),
getVectorNumElements(VT)); getVectorNumElements(VT));
if (isInteger(VT))
return IntegerType::get(getSizeInBits(VT));
assert(0 && "ValueType does not correspond to LLVM type!"); assert(0 && "ValueType does not correspond to LLVM type!");
case MVT::isVoid:return Type::VoidTy; case MVT::isVoid:return Type::VoidTy;
case MVT::i1: return Type::Int1Ty; case MVT::i1: return Type::Int1Ty;
@ -105,19 +109,7 @@ MVT::ValueType MVT::getValueType(const Type *Ty, bool HandleUnknown) {
case Type::VoidTyID: case Type::VoidTyID:
return MVT::isVoid; return MVT::isVoid;
case Type::IntegerTyID: case Type::IntegerTyID:
switch (cast<IntegerType>(Ty)->getBitWidth()) { return getIntegerType(cast<IntegerType>(Ty)->getBitWidth());
default:
// FIXME: Return MVT::iANY.
if (HandleUnknown) return MVT::Other;
assert(0 && "Invalid width for value type");
case 1: return MVT::i1;
case 8: return MVT::i8;
case 16: return MVT::i16;
case 32: return MVT::i32;
case 64: return MVT::i64;
case 128: return MVT::i128;
}
break;
case Type::FloatTyID: return MVT::f32; case Type::FloatTyID: return MVT::f32;
case Type::DoubleTyID: return MVT::f64; case Type::DoubleTyID: return MVT::f64;
case Type::X86_FP80TyID: return MVT::f80; case Type::X86_FP80TyID: return MVT::f80;