[llvm-commits] CVS: llvm/include/llvm/DerivedTypes.h Intrinsics.td Type.h

Reid Spencer reid at x10sys.com
Thu Jan 11 23:05:58 PST 2007



Changes in directory llvm/include/llvm:

DerivedTypes.h updated: 1.77 -> 1.78
Intrinsics.td updated: 1.39 -> 1.40
Type.h updated: 1.98 -> 1.99
---
Log message:

For PR1064: http://llvm.org/PR1064 :
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8, 
16, 32, and 64 bit integers.  

This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
   bits in an integer. The Type classes SubclassData field is used to
   store the number of bits. This allows 2^23 bits in an integer type. 
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
   64-bit integers. These are replaced with just IntegerType which is not
   a primitive any more. 
3. Adjust the rest of LLVM to account for this change.

Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with 
them in any significant way. Most optimization passes, for example, will 
still only deal with the byte-width integer types.  Future increments
will rectify this situation.



---
Diffs of the changes:  (+82 -46)

 DerivedTypes.h |   35 +++++++++++++++++++++++++++++++++
 Intrinsics.td  |   34 ++++++++++++++++++--------------
 Type.h         |   59 +++++++++++++++++++++++++++------------------------------
 3 files changed, 82 insertions(+), 46 deletions(-)


Index: llvm/include/llvm/DerivedTypes.h
diff -u llvm/include/llvm/DerivedTypes.h:1.77 llvm/include/llvm/DerivedTypes.h:1.78
--- llvm/include/llvm/DerivedTypes.h:1.77	Fri Jan  5 11:06:19 2007
+++ llvm/include/llvm/DerivedTypes.h	Fri Jan 12 01:05:13 2007
@@ -29,6 +29,7 @@
 class StructValType;
 class PointerValType;
 class PackedValType;
+class IntegerValType;
 
 class DerivedType : public Type {
   friend class Type;
@@ -71,6 +72,40 @@
   }
 };
 
+/// Class to represent integer types. Note that this class is also used to
+/// represent the built-in integer types: Int1Ty, Int8Ty, Int16Ty, Int32Ty and
+/// Int64Ty. 
+/// @brief Integer representation type
+class IntegerType : public DerivedType {
+protected:
+  IntegerType(unsigned NumBits) : DerivedType(IntegerTyID) {
+    setSubclassData(NumBits);
+  }
+  friend class TypeMap<IntegerValType, IntegerType>;
+public:
+  /// This enum is just used to hold constants we need for IntegerType.
+  enum {
+    MIN_INT_BITS = 1,        ///< Minimum number of bits that can be specified
+    MAX_INT_BITS = (1<<23)-1 ///< Maximum number of bits that can be specified
+      ///< Note that bit width is stored in the Type classes SubclassData field
+      ///< which has 23 bits. This yields a maximum bit width of 8,388,607 bits.
+  };
+
+  /// This static method is the primary way of constructing an IntegerType. 
+  /// If an IntegerType with the same NumBits value was previously instantiated,
+  /// that instance will be returned. Otherwise a new one will be created. Only
+  /// one instance with a given NumBits value is ever created.
+  /// @brief Get or create an IntegerType instance.
+  static const IntegerType* get(unsigned NumBits);
+
+  /// @brief Get the number of bits in this IntegerType
+  unsigned getBitWidth() const { return getSubclassData(); }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const IntegerType *T) { return true; }
+  static inline bool classof(const Type *T) { return T->isIntegral(); }
+};
+
 
 /// FunctionType - Class to represent function types
 ///


Index: llvm/include/llvm/Intrinsics.td
diff -u llvm/include/llvm/Intrinsics.td:1.39 llvm/include/llvm/Intrinsics.td:1.40
--- llvm/include/llvm/Intrinsics.td:1.39	Thu Jan 11 12:21:28 2007
+++ llvm/include/llvm/Intrinsics.td	Fri Jan 12 01:05:13 2007
@@ -57,6 +57,11 @@
   string TypeVal = typeval;
 }
 
+class LLVMIntegerType<ValueType VT, int width>
+  : LLVMType<VT, "Type::IntegerTyID"> {
+  int Width = width;
+}
+
 class LLVMPackedType<ValueType VT, int numelts, LLVMType elty>
   : LLVMType<VT, "Type::PackedTyID">{
   int NumElts = numelts;
@@ -64,25 +69,24 @@
 } 
 
 def llvm_void_ty       : LLVMType<isVoid, "Type::VoidTyID">;
-def llvm_i1_ty         : LLVMType<i1 , "Type::Int1TyID">;
-def llvm_i8_ty         : LLVMType<i8 , "Type::Int8TyID">;
-def llvm_i16_ty        : LLVMType<i16, "Type::Int16TyID">;
-def llvm_i32_ty        : LLVMType<i32, "Type::Int32TyID">;
-def llvm_i64_ty        : LLVMType<i64, "Type::Int64TyID">;
+def llvm_bool_ty       : LLVMIntegerType<i1, 1>;
+def llvm_i8_ty         : LLVMIntegerType<i8 , 8>;
+def llvm_i16_ty        : LLVMIntegerType<i16, 16>;
+def llvm_i32_ty        : LLVMIntegerType<i32, 32>;
+def llvm_i64_ty        : LLVMIntegerType<i64, 64>;
 def llvm_float_ty      : LLVMType<f32, "Type::FloatTyID">;
 def llvm_double_ty     : LLVMType<f64, "Type::DoubleTyID">;
-def llvm_ptr_ty        : LLVMType<iPTR, "Type::PointerTyID">;     // sbyte*
-def llvm_ptrptr_ty     : LLVMType<iPTR, "Type::PointerTyID">;     // sbyte**
+def llvm_ptr_ty        : LLVMType<iPTR, "Type::PointerTyID">;     // i8*
+def llvm_ptrptr_ty     : LLVMType<iPTR, "Type::PointerTyID">;     // i8**
 def llvm_descriptor_ty : LLVMType<iPTR, "Type::PointerTyID">;     // global*
 
-def llvm_v16i8_ty      : LLVMPackedType<v16i8,16, llvm_i8_ty>;  // 16 x sbyte
-def llvm_v8i16_ty      : LLVMPackedType<v8i16, 8, llvm_i16_ty>;  // 8 x short
-
-def llvm_v2i64_ty      : LLVMPackedType<v2i64, 2, llvm_i64_ty>;   // 2 x long
-def llvm_v2i32_ty      : LLVMPackedType<v2i32, 2, llvm_i32_ty>;    // 2 x int
-def llvm_v4i32_ty      : LLVMPackedType<v4i32, 4, llvm_i32_ty>;    // 4 x int
-def llvm_v4f32_ty      : LLVMPackedType<v4f32, 4, llvm_float_ty>;  // 4 x float
-def llvm_v2f64_ty      : LLVMPackedType<v2f64, 2, llvm_double_ty>; // 2 x double
+def llvm_v16i8_ty      : LLVMPackedType<v16i8,16, llvm_i8_ty>;    // 16 x i8
+def llvm_v8i16_ty      : LLVMPackedType<v8i16, 8, llvm_i16_ty>;   //  8 x i16
+def llvm_v2i64_ty      : LLVMPackedType<v2i64, 2, llvm_i64_ty>;   //  2 x i64
+def llvm_v2i32_ty      : LLVMPackedType<v2i32, 2, llvm_i32_ty>;   //  2 x i32
+def llvm_v4i32_ty      : LLVMPackedType<v4i32, 4, llvm_i32_ty>;   //  4 x i32
+def llvm_v4f32_ty      : LLVMPackedType<v4f32, 4, llvm_float_ty>; //  4 x float
+def llvm_v2f64_ty      : LLVMPackedType<v2f64, 2, llvm_double_ty>;//  2 x double
 
 //===----------------------------------------------------------------------===//
 // Intrinsic Definitions.


Index: llvm/include/llvm/Type.h
diff -u llvm/include/llvm/Type.h:1.98 llvm/include/llvm/Type.h:1.99
--- llvm/include/llvm/Type.h:1.98	Thu Jan 11 12:21:28 2007
+++ llvm/include/llvm/Type.h	Fri Jan 12 01:05:13 2007
@@ -71,32 +71,31 @@
   ///
   enum TypeID {
     // PrimitiveTypes .. make sure LastPrimitiveTyID stays up to date
-    VoidTyID = 0  , Int1TyID,           //  0, 1: Basics...
-    Int8TyID,                           //  2   :  8 bit type...
-    Int16TyID,                          //  3   : 16 bit type...
-    Int32TyID,                          //  4   : 32 bit type...
-    Int64TyID,                          //  5   : 64 bit type...
-    FloatTyID, DoubleTyID,              //  6, 7: Floating point types...
-    LabelTyID,                          //  8   : Labels...
+    VoidTyID = 0,    ///<  0: type with no size
+    FloatTyID,       ///<  1: 32 bit floating point type
+    DoubleTyID,      ///<  2: 64 bit floating point type
+    LabelTyID,       ///<  3: Labels
 
     // Derived types... see DerivedTypes.h file...
     // Make sure FirstDerivedTyID stays up to date!!!
-    FunctionTyID  , StructTyID,         // Functions... Structs...
-    ArrayTyID     , PointerTyID,        // Array... pointer...
-    OpaqueTyID,                         // Opaque type instances...
-    PackedTyID,                         // SIMD 'packed' format...
-    BC_ONLY_PackedStructTyID,           // packed struct, for BC rep only
-    //...
+    IntegerTyID,     ///<  4: Arbitrary bit width integers
+    FunctionTyID,    ///<  5: Functions
+    StructTyID,      ///<  6: Structures
+    PackedStructTyID,///<  7: Packed Structure. This is for bytecode only
+    ArrayTyID,       ///<  8: Arrays
+    PointerTyID,     ///<  9: Pointers
+    OpaqueTyID,      ///< 10: Opaque: type with unknown structure
+    PackedTyID,      ///< 11: SIMD 'packed' format, or other vector type
 
     NumTypeIDs,                         // Must remain as last defined ID
     LastPrimitiveTyID = LabelTyID,
-    FirstDerivedTyID = FunctionTyID
+    FirstDerivedTyID = IntegerTyID
   };
 
 private:
   TypeID   ID : 8;    // The current base type of this type.
   bool     Abstract : 1;  // True if type contains an OpaqueType
-  bool     SubclassData : 1; //Space for subclasses to store a flag
+  unsigned SubclassData : 23; //Space for subclasses to store data
 
   /// RefCount - This counts the number of PATypeHolders that are pointing to
   /// this type.  When this number falls to zero, if the type is abstract and
@@ -108,7 +107,8 @@
   const Type *getForwardedTypeInternal() const;
 protected:
   Type(const char *Name, TypeID id);
-  Type(TypeID id) : ID(id), Abstract(false), RefCount(0), ForwardType(0) {}
+  Type(TypeID id) : ID(id), Abstract(false), SubclassData(0), RefCount(0), 
+                    ForwardType(0) {}
   virtual ~Type() {
     assert(AbstractTypeUsers.empty());
   }
@@ -119,8 +119,8 @@
 
   unsigned getRefCount() const { return RefCount; }
 
-  bool getSubclassData() const { return SubclassData; }
-  void setSubclassData(bool b) { SubclassData = b; }
+  unsigned getSubclassData() const { return SubclassData; }
+  void setSubclassData(unsigned val) { SubclassData = val; }
 
   /// ForwardType - This field is used to implement the union find scheme for
   /// abstract types.  When types are refined to other types, this field is set
@@ -162,12 +162,12 @@
 
   /// isInteger - Equivalent to isSigned() || isUnsigned()
   ///
-  bool isInteger() const { return ID >= Int8TyID && ID <= Int64TyID; }
+  bool isInteger() const { return ID == IntegerTyID && this != Int1Ty; } 
 
   /// isIntegral - Returns true if this is an integral type, which is either
   /// Int1Ty or one of the Integer types.
   ///
-  bool isIntegral() const { return isInteger() || this == Int1Ty; }
+  bool isIntegral() const { return ID == IntegerTyID; }
 
   /// isFloatingPoint - Return true if this is one of the two floating point
   /// types
@@ -200,7 +200,7 @@
   ///
   inline bool isFirstClassType() const {
     return (ID != VoidTyID && ID <= LastPrimitiveTyID) ||
-            ID == PointerTyID || ID == PackedTyID;
+            ID == IntegerTyID || ID == PointerTyID || ID == PackedTyID;
   }
 
   /// isSized - Return true if it makes sense to take the size of this type.  To
@@ -209,11 +209,13 @@
   ///
   bool isSized() const {
     // If it's a primitive, it is always sized.
-    if (ID >= Int1TyID && ID <= DoubleTyID || ID == PointerTyID)
+    if (ID == IntegerTyID || (ID >= FloatTyID && ID <= DoubleTyID) || 
+        ID == PointerTyID)
       return true;
     // If it is not something that can have a size (e.g. a function or label),
     // it doesn't have a size.
-    if (ID != StructTyID && ID != ArrayTyID && ID != PackedTyID)
+    if (ID != StructTyID && ID != ArrayTyID && ID != PackedTyID &&
+        ID != PackedStructTyID)
       return false;
     // If it is something that can have a size and it's concrete, it definitely
     // has a size, otherwise we have to try harder to decide.
@@ -224,7 +226,6 @@
   /// type.  These are fixed by LLVM and are not target dependent.  This will
   /// return zero if the type does not have a size or is not a primitive type.
   ///
-  unsigned getPrimitiveSize() const;
   unsigned getPrimitiveSizeInBits() const;
 
   /// getIntegralTypeMask - Return a bitmask with ones set for all of the bits
@@ -248,7 +249,7 @@
   /// will be promoted to if passed through a variable argument
   /// function.
   const Type *getVAArgsPromotedType() const {
-    if (ID == Int1TyID || ID == Int8TyID || ID == Int16TyID)
+    if (ID == IntegerTyID && getSubclassData() < 32)
       return Type::Int32Ty;
     else if (ID == FloatTyID)
       return Type::DoubleTy;
@@ -288,12 +289,8 @@
   //===--------------------------------------------------------------------===//
   // These are the builtin types that are always available...
   //
-  static Type *VoidTy , *Int1Ty;
-  static Type *Int8Ty , *Int16Ty,
-              *Int32Ty, *Int64Ty;
-  static Type *FloatTy, *DoubleTy;
-
-  static Type* LabelTy;
+  static const Type *VoidTy, *LabelTy, *FloatTy, *DoubleTy;
+  static const Type *Int1Ty, *Int8Ty, *Int16Ty, *Int32Ty, *Int64Ty;
 
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const Type *T) { return true; }






More information about the llvm-commits mailing list