[llvm-commits] CVS: llvm/include/llvm/Constant.h Constants.h Value.h

Chris Lattner lattner at cs.uiuc.edu
Mon Sep 26 23:08:44 PDT 2005



Changes in directory llvm/include/llvm:

Constant.h updated: 1.23 -> 1.24
Constants.h updated: 1.73 -> 1.74
Value.h updated: 1.77 -> 1.78
---
Log message:

Split SimpleConstantVal up into its components, so each Constant subclass gets
a different enum value.  This allows 'classof' for these to be really simple,
not needing to call getType() anymore.

This speeds up isa/dyncast/etc for constants, and also makes them smaller. 
For example, the text section of a release build of InstCombine.cpp shrinks
from 230037 bytes to 216363 bytes, a 6% reduction.



---
Diffs of the changes:  (+32 -35)

 Constant.h  |    8 ++------
 Constants.h |   38 ++++++++++++++++----------------------
 Value.h     |   21 ++++++++++++++-------
 3 files changed, 32 insertions(+), 35 deletions(-)


Index: llvm/include/llvm/Constant.h
diff -u llvm/include/llvm/Constant.h:1.23 llvm/include/llvm/Constant.h:1.24
--- llvm/include/llvm/Constant.h:1.23	Thu Apr 21 15:11:51 2005
+++ llvm/include/llvm/Constant.h	Tue Sep 27 01:08:32 2005
@@ -61,12 +61,8 @@
   static inline bool classof(const Constant *) { return true; }
   static inline bool classof(const GlobalValue *) { return true; }
   static inline bool classof(const Value *V) {
-    return V->getValueType() == Value::SimpleConstantVal ||
-           V->getValueType() == Value::ConstantExprVal ||
-           V->getValueType() == Value::ConstantAggregateZeroVal ||
-           V->getValueType() == Value::FunctionVal ||
-           V->getValueType() == Value::GlobalVariableVal ||
-           V->getValueType() == Value::UndefValueVal;
+    return V->getValueType() >= ConstantFirstVal &&
+           V->getValueType() <= ConstantLastVal;
   }
 
   /// replaceUsesOfWithOnConstant - This method is a special form of


Index: llvm/include/llvm/Constants.h
diff -u llvm/include/llvm/Constants.h:1.73 llvm/include/llvm/Constants.h:1.74
--- llvm/include/llvm/Constants.h:1.73	Sat Sep 24 17:57:28 2005
+++ llvm/include/llvm/Constants.h	Tue Sep 27 01:08:32 2005
@@ -47,7 +47,7 @@
     int64_t  Signed;
     uint64_t Unsigned;
   } Val;
-  ConstantIntegral(const Type *Ty, uint64_t V);
+  ConstantIntegral(const Type *Ty, ValueTy VT, uint64_t V);
 public:
 
   /// getRawValue - return the underlying value of this constant as a 64-bit
@@ -98,8 +98,9 @@
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ConstantIntegral *) { return true; }
   static bool classof(const Value *V) {
-    return V->getValueType() == SimpleConstantVal &&
-           V->getType()->isIntegral();
+    return V->getValueType() == ConstantBoolVal ||
+           V->getValueType() == ConstantSIntVal ||
+           V->getValueType() == ConstantUIntVal;
   }
 };
 
@@ -134,7 +135,7 @@
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ConstantBool *) { return true; }
   static bool classof(const Value *V) {
-    return (V == True) | (V == False);
+    return V->getValueType() == ConstantBoolVal;
   }
 };
 
@@ -146,7 +147,7 @@
 class ConstantInt : public ConstantIntegral {
 protected:
   ConstantInt(const ConstantInt &);      // DO NOT IMPLEMENT
-  ConstantInt(const Type *Ty, uint64_t V);
+  ConstantInt(const Type *Ty, ValueTy VT, uint64_t V);
 public:
   /// equalsInt - Provide a helper method that can be used to determine if the
   /// constant contained within is equal to a constant.  This only works for
@@ -173,8 +174,8 @@
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ConstantInt *) { return true; }
   static bool classof(const Value *V) {
-    return V->getValueType() == SimpleConstantVal &&
-           V->getType()->isInteger();
+    return V->getValueType() == ConstantSIntVal ||
+           V->getValueType() == ConstantUIntVal;
   }
 };
 
@@ -227,8 +228,7 @@
   ///
   static inline bool classof(const ConstantSInt *) { return true; }
   static bool classof(const Value *V) {
-    return V->getValueType() == SimpleConstantVal &&
-           V->getType()->isSigned();
+    return V->getValueType() == ConstantSIntVal;
   }
 };
 
@@ -263,8 +263,7 @@
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ConstantUInt *) { return true; }
   static bool classof(const Value *V) {
-    return V->getValueType() == SimpleConstantVal &&
-           V->getType()->isUnsigned();
+    return V->getValueType() == ConstantUIntVal;
   }
 };
 
@@ -301,8 +300,7 @@
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ConstantFP *) { return true; }
   static bool classof(const Value *V) {
-    return V->getValueType() == SimpleConstantVal &&
-           V->getType()->isFloatingPoint();
+    return V->getValueType() == ConstantFPVal;
   }
 };
 
@@ -380,8 +378,7 @@
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ConstantArray *) { return true; }
   static bool classof(const Value *V) {
-    return V->getValueType() == SimpleConstantVal &&
-           V->getType()->getTypeID() == Type::ArrayTyID;
+    return V->getValueType() == ConstantArrayVal;
   }
 };
 
@@ -422,8 +419,7 @@
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ConstantStruct *) { return true; }
   static bool classof(const Value *V) {
-    return V->getValueType() == SimpleConstantVal &&
-           V->getType()->getTypeID() == Type::StructTyID;
+    return V->getValueType() == ConstantStructVal;
   }
 };
 
@@ -461,8 +457,7 @@
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ConstantPacked *) { return true; }
   static bool classof(const Value *V) {
-    return V->getValueType() == SimpleConstantVal &&
-           V->getType()->getTypeID() == Type::PackedTyID;
+    return V->getValueType() == ConstantPackedVal;
   }
 };
 
@@ -475,7 +470,7 @@
 protected:
   ConstantPointerNull(const PointerType *T)
     : Constant(reinterpret_cast<const Type*>(T),
-               Value::SimpleConstantVal, 0, 0) {}
+               Value::ConstantPointerNullVal, 0, 0) {}
 
 public:
 
@@ -498,8 +493,7 @@
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ConstantPointerNull *) { return true; }
   static bool classof(const Value *V) {
-    return V->getValueType() == SimpleConstantVal &&
-           isa<PointerType>(V->getType());
+    return V->getValueType() == ConstantPointerNullVal;
   }
 };
 


Index: llvm/include/llvm/Value.h
diff -u llvm/include/llvm/Value.h:1.77 llvm/include/llvm/Value.h:1.78
--- llvm/include/llvm/Value.h:1.77	Tue Aug 16 17:04:58 2005
+++ llvm/include/llvm/Value.h	Tue Sep 27 01:08:32 2005
@@ -146,8 +146,19 @@
     UndefValueVal,            // This is an instance of UndefValue
     ConstantExprVal,          // This is an instance of ConstantExpr
     ConstantAggregateZeroVal, // This is an instance of ConstantAggregateNull
-    SimpleConstantVal,        // This is some other type of Constant
+    ConstantBoolVal,          // This is an instance of ConstantBool
+    ConstantSIntVal,          // This is an instance of ConstantSInt
+    ConstantUIntVal,          // This is an instance of ConstantUInt
+    ConstantFPVal,            // This is an instance of ConstantFP
+    ConstantArrayVal,         // This is an instance of ConstantArray
+    ConstantStructVal,        // This is an instance of ConstantStruct
+    ConstantPackedVal,        // This is an instance of ConstantPacked
+    ConstantPointerNullVal,   // This is an instance of ConstantPointerNull
     InstructionVal,           // This is an instance of Instruction
+    
+    // Markers:
+    ConstantFirstVal = FunctionVal,
+    ConstantLastVal  = ConstantPointerNullVal,
   };
   unsigned getValueType() const {
     return SubclassID;
@@ -194,12 +205,8 @@
 // the subtype header files to test to see if the value is a subclass...
 //
 template <> inline bool isa_impl<Constant, Value>(const Value &Val) {
-  return Val.getValueType() == Value::SimpleConstantVal ||
-         Val.getValueType() == Value::FunctionVal ||
-         Val.getValueType() == Value::GlobalVariableVal ||
-         Val.getValueType() == Value::ConstantExprVal ||
-         Val.getValueType() == Value::ConstantAggregateZeroVal ||
-         Val.getValueType() == Value::UndefValueVal;
+  return Val.getValueType() >= Value::ConstantFirstVal &&
+         Val.getValueType() <= Value::ConstantLastVal;
 }
 template <> inline bool isa_impl<Argument, Value>(const Value &Val) {
   return Val.getValueType() == Value::ArgumentVal;






More information about the llvm-commits mailing list