Initial infrastructure for arbitrary precision integer
authorDuncan Sands <baldrick@free.fr>
Tue, 16 Oct 2007 09:56:48 +0000 (09:56 +0000)
committerDuncan Sands <baldrick@free.fr>
Tue, 16 Oct 2007 09:56:48 +0000 (09:56 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43030 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/ValueTypes.h
include/llvm/Target/TargetLowering.h
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/VMCore/ValueTypes.cpp

index 965043a1093365e88b505f9cd22f04ce557aecbf..05f10e8b04e21e6cd8f3582de18b4db40df3b0cb 100644 (file)
@@ -19,6 +19,7 @@
 #include <cassert>
 #include <string>
 #include "llvm/Support/DataTypes.h"
+#include "llvm/Support/MathExtras.h"
 
 namespace llvm {
   class Type;
@@ -38,6 +39,9 @@ namespace MVT {  // MVT = Machine Value Types
     i64            =   5,   // This is a 64 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
     f64            =   8,   // This is a 64 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.
 
     isVoid         =  13,   // This has no value
-    
+
     v8i8           =  14,   //  8 x i8
     v4i16          =  15,   //  4 x i16
     v2i32          =  16,   //  2 x i32
     v1i64          =  17,   //  1 x i64
     v16i8          =  18,   // 16 x i8
     v8i16          =  19,   //  8 x i16
-    v3i32           = 20,   //  3 x i32
+    v3i32           20,   //  3 x i32
     v4i32          =  21,   //  4 x i32
     v2i64          =  22,   //  2 x i64
 
     v2f32          =  23,   //  2 x f32
-    v3f32           = 24,   //  3 x f32
+    v3f32           24,   //  3 x f32
     v4f32          =  25,   //  4 x f32
     v2f64          =  26,   //  2 x f64
-    
+
     FIRST_VECTOR_VALUETYPE = v8i8,
     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
     // for intrinsics that have overloadings based on floating-point types.
     // This is only for tblgen's consumption!
-    fAny           =  253,   
+    fAny           =  253,
 
     // iAny - An integer or vector integer value of any bit width. This is
     // used for intrinsics that have overloadings based on integer bit widths.
     // This is only for tblgen's consumption!
-    iAny           =  254,   
+    iAny           =  254,
 
     // iPTR - An int value the size of the pointer of the current
     // 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.
   ///
   /// @internal
-  /// Currently extended types are always vector types. Extended types are
-  /// encoded by having the first SimpleTypeBits bits encode the vector
-  /// element type (which must be a scalar type) and the remaining upper
-  /// bits encode the vector length, offset by one.
+  /// Extended types are either vector types or arbitrary precision integers.
+  /// Arbitrary precision integers have iAny in the first SimpleTypeBits bits,
+  /// and the bit-width in the next PrecisionBits bits, offset by minus 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;
 
   static const int SimpleTypeBits = 8;
+  static const int PrecisionBits  = 8;
+  static const int VectorBits     = 32 - SimpleTypeBits - PrecisionBits;
 
   static const uint32_t SimpleTypeMask =
     (~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
   /// (as opposed to being simple).
   static inline bool isExtendedVT(ValueType VT) {
@@ -114,33 +137,34 @@ namespace MVT {  // MVT = Machine Value Types
   /// type.
   static inline bool isInteger(ValueType VT) {
     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.
   static inline bool isFloatingPoint(ValueType VT) {
     ValueType SVT = VT & SimpleTypeMask;
     return (SVT >= f32 && SVT <= ppcf128) || (SVT >= v2f32 && SVT <= v2f64);
   }
-  
+
   /// MVT::isVector - Return true if this is a vector value type.
   static inline bool isVector(ValueType VT) {
     return (VT >= FIRST_VECTOR_VALUETYPE && VT <= LAST_VECTOR_VALUETYPE) ||
-           isExtendedVT(VT);
+           (VT & VectorMask);
   }
-  
+
   /// MVT::getVectorElementType - Given a vector type, return the type of
   /// each element.
   static inline ValueType getVectorElementType(ValueType VT) {
+    assert(isVector(VT) && "Invalid vector type!");
     switch (VT) {
     default:
-      if (isExtendedVT(VT))
-        return VT & SimpleTypeMask;
-      assert(0 && "Invalid vector type!");
+      assert(isExtendedVT(VT) && "Unknown simple vector type!");
+      return VT & ElementMask;
     case v8i8 :
     case v16i8: return i8;
     case v4i16:
-    case v8i16: return i16; 
+    case v8i16: return i16;
     case v2i32:
     case v3i32:
     case v4i32: return i32;
@@ -152,20 +176,20 @@ namespace MVT {  // MVT = Machine Value Types
     case v2f64: return f64;
     }
   }
-  
+
   /// MVT::getVectorNumElements - Given a vector type, return the
   /// number of elements it contains.
   static inline unsigned getVectorNumElements(ValueType VT) {
+    assert(isVector(VT) && "Invalid vector type!");
     switch (VT) {
     default:
-      if (isExtendedVT(VT))
-        return ((VT & ~SimpleTypeMask) >> SimpleTypeBits) - 1;
-      assert(0 && "Invalid vector type!");
+      assert(isExtendedVT(VT) && "Unknown simple vector type!");
+      return ((VT & VectorMask) >> (32 - VectorBits)) - 1;
     case v16i8: return 16;
     case v8i8 :
     case v8i16: return 8;
     case v4i16:
-    case v4i32: 
+    case v4i32:
     case v4f32: return 4;
     case v3i32:
     case v3f32: return 3;
@@ -176,17 +200,20 @@ namespace MVT {  // MVT = Machine Value Types
     case v1i64: return 1;
     }
   }
-  
+
   /// MVT::getSizeInBits - Return the size of the specified value type
   /// in bits.
   ///
   static inline unsigned getSizeInBits(ValueType VT) {
     switch (VT) {
     default:
-      if (isExtendedVT(VT))
+      assert(isExtendedVT(VT) && "ValueType has no known size!");
+      if (isVector(VT))
         return getSizeInBits(getVectorElementType(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::i8  :  return 8;
     case MVT::i16 :  return 16;
@@ -196,7 +223,7 @@ namespace MVT {  // MVT = Machine Value Types
     case MVT::i64 :
     case MVT::v8i8:
     case MVT::v4i16:
-    case MVT::v2i32: 
+    case MVT::v2i32:
     case MVT::v1i64:
     case MVT::v2f32: return 64;
     case MVT::f80 :  return 80;
@@ -204,7 +231,7 @@ namespace MVT {  // MVT = Machine Value Types
     case MVT::v3f32: return 96;
     case MVT::f128:
     case MVT::ppcf128:
-    case MVT::i128: 
+    case MVT::i128:
     case MVT::v16i8:
     case MVT::v8i16:
     case MVT::v4i32:
@@ -213,7 +240,46 @@ namespace MVT {  // MVT = Machine Value Types
     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
   /// 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;
       break;
     }
-    ValueType Result = VT | ((NumElements + 1) << SimpleTypeBits);
+    ValueType Result = VT | ((NumElements + 1) << (32 - VectorBits));
     assert(getVectorElementType(Result) == VT &&
            "Bad vector element type!");
     assert(getVectorNumElements(Result) == NumElements &&
@@ -268,8 +334,8 @@ namespace MVT {  // MVT = Machine Value Types
     case 16: return v16i8;
     }
   }
-  
-  
+
+
   /// MVT::getIntVTBitMask - Return an integer with 1's every place there are
   /// bits in the specified integer value type.
   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
   /// type.  Note that this will abort for types that cannot be represented.
   const Type *getTypeForValueType(ValueType VT);
-  
+
   /// MVT::getValueType - Return the value type corresponding to the specified
   /// type.  This returns all pointers as MVT::iPTR.  If HandleUnknown is true,
   /// unknown types are returned as Other, otherwise they are invalid.
index f565bd96b971d707e358a2bf98c220af9a297c19..a8eff2275265447193deb3a82dc3e968c9dd98c7 100644 (file)
@@ -150,7 +150,13 @@ public:
     }
     
     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);
     }
     void setTypeAction(MVT::ValueType VT, LegalizeAction Action) {
@@ -179,19 +185,34 @@ public:
   /// to get to the smaller register. For illegal floating point types, this
   /// returns the integer type to transform to.
   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),
                                 MVT::getVectorNumElements(VT) / 2);
-
-    return TransformToType[VT];
+    if (MVT::isInteger(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
   /// identity function.  For types that must be expanded (i.e. integer types
   /// that are larger than the largest integer register or illegal floating
   /// point types), this returns the largest legal type it will be expanded to.
   MVT::ValueType getTypeToExpandTo(MVT::ValueType VT) const {
-    assert(!MVT::isExtendedVT(VT));
+    assert(!MVT::isVector(VT));
     while (true) {
       switch (getTypeAction(VT)) {
       case Legal:
@@ -252,7 +273,7 @@ public:
   /// expanded to some other code sequence, or the target has a custom expander
   /// for it.
   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);
   }
   
@@ -268,7 +289,7 @@ public:
   /// expanded to some other code sequence, or the target has a custom expander
   /// for it.
   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);
   }
   
@@ -284,7 +305,7 @@ public:
   /// expanded to some other code sequence, or the target has a custom expander
   /// for it.
   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);
   }
   
@@ -300,7 +321,7 @@ public:
   /// for it.
   LegalizeAction
   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);
   }
 
@@ -317,7 +338,7 @@ public:
   /// for it.
   LegalizeAction
   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);
   }  
   
@@ -385,13 +406,15 @@ public:
   MVT::ValueType getRegisterType(MVT::ValueType VT) const {
     if (!MVT::isExtendedVT(VT))
       return RegisterTypeForVT[VT];
-           
-    MVT::ValueType VT1, RegisterVT;
-    unsigned NumIntermediates;
-    (void)getVectorTypeBreakdown(VT, VT1, NumIntermediates, RegisterVT);
-    return RegisterVT;
+    if (MVT::isVector(VT)) {
+      MVT::ValueType VT1, RegisterVT;
+      unsigned NumIntermediates;
+      (void)getVectorTypeBreakdown(VT, VT1, NumIntermediates, RegisterVT);
+      return RegisterVT;
+    }
+    assert(0 && "Unsupported extended type!");
   }
-  
+
   /// getNumRegisters - Return the number of registers that this ValueType will
   /// 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
@@ -399,10 +422,12 @@ public:
   unsigned getNumRegisters(MVT::ValueType VT) const {
     if (!MVT::isExtendedVT(VT))
       return NumRegistersForVT[VT];
-           
-    MVT::ValueType VT1, VT2;
-    unsigned NumIntermediates;
-    return getVectorTypeBreakdown(VT, VT1, NumIntermediates, VT2);
+    if (MVT::isVector(VT)) {
+      MVT::ValueType VT1, VT2;
+      unsigned NumIntermediates;
+      return getVectorTypeBreakdown(VT, VT1, NumIntermediates, VT2);
+    }
+    assert(0 && "Unsupported extended type!");
   }
   
   /// hasTargetDAGCombine - If true, the target has custom DAG combine
index b1b3bd4fb856da120a1ac4f25b1be29bf0c59722..d295a607777ebe0c58defb2666ede2d5736ca05f 100644 (file)
@@ -28,6 +28,7 @@
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include <algorithm>
@@ -846,6 +847,7 @@ SDOperand SelectionDAG::getBasicBlock(MachineBasicBlock *MBB) {
 }
 
 SDOperand SelectionDAG::getValueType(MVT::ValueType VT) {
+  assert(!MVT::isExtendedVT(VT) && "Expecting a simple value type!");
   if ((unsigned)VT >= ValueTypeNodes.size())
     ValueTypeNodes.resize(VT+1);
   if (ValueTypeNodes[VT] == 0) {
@@ -1734,7 +1736,8 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
     assert(MVT::isInteger(VT) && MVT::isInteger(Operand.getValueType()) &&
            "Invalid SIGN_EXTEND!");
     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)
       return getNode(OpOpcode, VT, Operand.Val->getOperand(0));
     break;
@@ -1742,7 +1745,8 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
     assert(MVT::isInteger(VT) && MVT::isInteger(Operand.getValueType()) &&
            "Invalid ZERO_EXTEND!");
     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)
       return getNode(ISD::ZERO_EXTEND, VT, Operand.Val->getOperand(0));
     break;
@@ -1750,7 +1754,8 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
     assert(MVT::isInteger(VT) && MVT::isInteger(Operand.getValueType()) &&
            "Invalid ANY_EXTEND!");
     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)
       // (ext (zext x)) -> (zext x)  and  (ext (sext x)) -> (sext x)
       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()) &&
            "Invalid 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)
       return getNode(ISD::TRUNCATE, VT, Operand.Val->getOperand(0));
     else if (OpOpcode == ISD::ZERO_EXTEND || OpOpcode == ISD::SIGN_EXTEND ||
              OpOpcode == ISD::ANY_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));
-      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));
       else
         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(MVT::isFloatingPoint(VT) && MVT::isFloatingPoint(EVT) &&
            "Cannot FP_ROUND_INREG integer types");
-    assert(EVT <= VT && "Not rounding down!");
+    assert(MVT::getSizeInBits(EVT) <= MVT::getSizeInBits(VT) &&
+           "Not rounding down!");
     break;
   }
   case ISD::AssertSext:
@@ -1884,7 +1893,8 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
     assert(VT == N1.getValueType() && "Not an inreg extend!");
     assert(MVT::isInteger(VT) && MVT::isInteger(EVT) &&
            "Cannot *_EXTEND_INREG FP types");
-    assert(EVT <= VT && "Not extending!");
+    assert(MVT::getSizeInBits(EVT) <= MVT::getSizeInBits(VT) &&
+           "Not extending!");
   }
 
   default: break;
@@ -2299,7 +2309,8 @@ SDOperand SelectionDAG::getExtLoad(ISD::LoadExtType ExtType, MVT::ValueType VT,
   if (MVT::isVector(VT))
     assert(EVT == MVT::getVectorElementType(VT) && "Invalid vector extload!");
   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)) &&
          "Cannot sign/zero extend a FP/Vector load!");
   assert(MVT::isInteger(VT) == MVT::isInteger(EVT) &&
@@ -2415,7 +2426,8 @@ SDOperand SelectionDAG::getTruncStore(SDOperand Chain, SDOperand Val,
   MVT::ValueType VT = Val.getValueType();
   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) &&
          "Can't do FP-INT conversion!");
 
@@ -2648,18 +2660,7 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, SDVTList VTList,
 }
 
 SDVTList SelectionDAG::getVTList(MVT::ValueType VT) {
-  if (!MVT::isExtendedVT(VT))
-    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);
+  return makeVTList(SDNode::getValueTypeList(VT), 1);
 }
 
 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.
 ///
 MVT::ValueType *SDNode::getValueTypeList(MVT::ValueType VT) {
-  static MVT::ValueType VTs[MVT::LAST_VALUETYPE];
-  VTs[VT] = VT;
-  return &VTs[VT];
+  if (MVT::isExtendedVT(VT)) {
+    static std::set<MVT::ValueType> EVTs;
+    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
 /// indicated value.  This method ignores uses of other values defined by this
 /// operation.
index 3d9951bc300547997b1ccbdaa6cb3d203ca876a6..6089c5691d65970f224ec85b99403802f55f71fc 100644 (file)
@@ -22,9 +22,11 @@ using namespace llvm;
 std::string MVT::getValueTypeString(MVT::ValueType VT) {
   switch (VT) {
   default:
-    if (isExtendedVT(VT))
+    if (isVector(VT))
       return "v" + utostr(getVectorNumElements(VT)) +
              getValueTypeString(getVectorElementType(VT));
+    if (isInteger(VT))
+      return "i" + utostr(getSizeInBits(VT));
     assert(0 && "Invalid ValueType!");
   case MVT::i1:      return "i1";
   case MVT::i8:      return "i8";
@@ -62,9 +64,11 @@ std::string MVT::getValueTypeString(MVT::ValueType VT) {
 const Type *MVT::getTypeForValueType(MVT::ValueType VT) {
   switch (VT) {
   default:
-    if (isExtendedVT(VT))
+    if (isVector(VT))
       return VectorType::get(getTypeForValueType(getVectorElementType(VT)),
                              getVectorNumElements(VT));
+    if (isInteger(VT))
+      return IntegerType::get(getSizeInBits(VT));
     assert(0 && "ValueType does not correspond to LLVM type!");
   case MVT::isVoid:return Type::VoidTy;
   case MVT::i1:      return Type::Int1Ty;
@@ -105,19 +109,7 @@ MVT::ValueType MVT::getValueType(const Type *Ty, bool HandleUnknown) {
   case Type::VoidTyID:
     return MVT::isVoid;
   case Type::IntegerTyID:
-    switch (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;
+    return getIntegerType(cast<IntegerType>(Ty)->getBitWidth());
   case Type::FloatTyID:     return MVT::f32;
   case Type::DoubleTyID:    return MVT::f64;
   case Type::X86_FP80TyID:  return MVT::f80;