add alias support to bitcode
[oota-llvm.git] / include / llvm / Constants.h
index 7257d2645a7c8259ad58b5a73f68ef99bfd8c8cc..2bec1d42ab63b47c59e640758edb74f780288959 100644 (file)
@@ -52,6 +52,9 @@ public:
   inline const APInt& getValue() const {
     return Val;
   }
+  
+  /// getBitWidth - Return the bitwidth of this constant.
+  unsigned getBitWidth() const { return Val.getBitWidth(); }
 
   /// Return the constant as a 64-bit unsigned integer value after it
   /// has been zero extended as appropriate for the type of this constant. Note
@@ -94,7 +97,7 @@ public:
   /// either getSExtValue() or getZExtValue() will yield a correctly sized and
   /// signed value for the type Ty.
   /// @brief Get a ConstantInt for a specific value.
-  static ConstantInt *get(const Type *Ty, uint64_t V);
+  static ConstantInt *get(const Type *Ty, uint64_t V, bool isSigned = false);
 
   /// Return a ConstantInt with the specified value and an implied Type. The
   /// type is the integer type that corresponds to the bit width of the value.
@@ -127,10 +130,18 @@ public:
     return Val == 0; 
   }
 
+  /// This is just a convenience method to make client code smaller for a
+  /// common code. It also correctly performs the comparison without the
+  /// potential for an assertion from getZExtValue().
+  bool isZero() const {
+    return Val == 0;
+  }
+
   /// This is just a convenience method to make client code smaller for a 
-  /// common case.
+  /// common case. It also correctly performs the comparison without the
+  /// potential for an assertion from getZExtValue().
   /// @brief Determine if the value is one.
-  virtual bool isUnitValue() const {
+  bool isOne() const {
     return Val == 1;
   }
 
@@ -166,6 +177,22 @@ public:
       return Val.isMinValue();
   }
 
+  /// This function will return true iff this constant represents a value with
+  /// active bits bigger than 64 bits or a value greater than the given uint64_t
+  /// value.
+  /// @returns true iff this constant is greater or equal to the given number.
+  /// @brief Determine if the value is greater or equal to the given number.
+  bool uge(uint64_t Num) {
+    return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num;
+  }
+
+  /// @returns the 64-bit value of this constant if its active bits number is 
+  /// not greater than 64, otherwise, just return the given uint64_t number.
+  /// @brief Get the constant's value if possible.
+  uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
+    return Val.getLimitedValue(Limit);
+  }
+
   /// @returns the value for an integer constant of the given type that has all
   /// its bits set to true.
   /// @brief Get the all ones value
@@ -174,7 +201,7 @@ public:
   /// @brief Methods to 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() == ConstantIntVal;
+    return V->getValueID() == ConstantIntVal;
   }
   static void ResetTrueFalse() { TheTrueVal = TheFalseVal = 0; }
 private:
@@ -212,7 +239,7 @@ public:
   /// 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() == ConstantFPVal;
+    return V->getValueID() == ConstantFPVal;
   }
 };
 
@@ -223,7 +250,7 @@ class ConstantAggregateZero : public Constant {
   friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
   ConstantAggregateZero(const ConstantAggregateZero &);      // DO NOT IMPLEMENT
 protected:
-  ConstantAggregateZero(const Type *Ty)
+  explicit ConstantAggregateZero(const Type *Ty)
     : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
 public:
   /// get() - static factory method for creating a null aggregate.  It is
@@ -240,7 +267,7 @@ public:
   ///
   static bool classof(const ConstantAggregateZero *) { return true; }
   static bool classof(const Value *V) {
-    return V->getValueType() == ConstantAggregateZeroVal;
+    return V->getValueID() == ConstantAggregateZeroVal;
   }
 };
 
@@ -304,7 +331,7 @@ public:
   /// 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() == ConstantArrayVal;
+    return V->getValueID() == ConstantArrayVal;
   }
 };
 
@@ -349,7 +376,7 @@ public:
   /// 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() == ConstantStructVal;
+    return V->getValueID() == ConstantStructVal;
   }
 };
 
@@ -401,7 +428,7 @@ public:
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ConstantVector *) { return true; }
   static bool classof(const Value *V) {
-    return V->getValueType() == ConstantVectorVal;
+    return V->getValueID() == ConstantVectorVal;
   }
 };
 
@@ -412,7 +439,7 @@ class ConstantPointerNull : public Constant {
   friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
   ConstantPointerNull(const ConstantPointerNull &);      // DO NOT IMPLEMENT
 protected:
-  ConstantPointerNull(const PointerType *T)
+  explicit ConstantPointerNull(const PointerType *T)
     : Constant(reinterpret_cast<const Type*>(T),
                Value::ConstantPointerNullVal, 0, 0) {}
 
@@ -437,7 +464,7 @@ public:
   /// 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() == ConstantPointerNullVal;
+    return V->getValueID() == ConstantPointerNullVal;
   }
 };
 
@@ -646,7 +673,7 @@ public:
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ConstantExpr *) { return true; }
   static inline bool classof(const Value *V) {
-    return V->getValueType() == ConstantExprVal;
+    return V->getValueID() == ConstantExprVal;
   }
 };
 
@@ -661,7 +688,7 @@ class UndefValue : public Constant {
   friend struct ConstantCreator<UndefValue, Type, char>;
   UndefValue(const UndefValue &);      // DO NOT IMPLEMENT
 protected:
-  UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
+  explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
 public:
   /// get() - Static factory methods - Return an 'undef' object of the specified
   /// type.
@@ -677,7 +704,7 @@ public:
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const UndefValue *) { return true; }
   static bool classof(const Value *V) {
-    return V->getValueType() == UndefValueVal;
+    return V->getValueID() == UndefValueVal;
   }
 };