Add some new methods to forward to
[oota-llvm.git] / include / llvm / Constants.h
index 77c39452d18488c102c8e4704f1e1421c59bad29..bf88ef78f8af2913768dcd3f2326240403174f38 100644 (file)
@@ -1,4 +1,4 @@
-//===-- llvm/Constants.h - Constant class subclass definitions ---*- C++ -*--=//
+//===-- llvm/Constants.h - Constant class subclass definitions --*- C++ -*-===//
 //
 // This file contains the declarations for the subclasses of Constant, which
 // represent the different type of constant pool values
@@ -17,6 +17,9 @@ class PointerType;
 
 template<class ConstantClass, class TypeClass, class ValType>
 struct ConstantCreator;
+template<class ConstantClass, class TypeClass>
+struct ConvertConstantType;
+
 
 //===---------------------------------------------------------------------------
 /// ConstantIntegral - Shared superclass of boolean and integer constants.
@@ -131,6 +134,11 @@ public:
   ///
   static ConstantInt *get(const Type *Ty, unsigned char V);
 
+  /// getRawValue - return the underlying value of this constant as a 64-bit
+  /// unsigned integer value.
+  ///
+  inline uint64_t getRawValue() const { return Val.Unsigned; }
+
   /// isNullValue - Return true if this is the value that would be returned by
   /// getNullValue.
   virtual bool isNullValue() const { return Val.Unsigned == 0; }
@@ -157,12 +165,15 @@ protected:
   ConstantSInt(const Type *Ty, int64_t V);
 public:
   /// get() - Static factory methods - Return objects of the specified value
+  ///
   static ConstantSInt *get(const Type *Ty, int64_t V);
 
   /// isValueValidForType - return true if Ty is big enough to represent V.
+  ///
   static bool isValueValidForType(const Type *Ty, int64_t V);
 
   /// getValue - return the underlying value of this constant.
+  ///
   inline int64_t getValue() const { return Val.Signed; }
 
   virtual bool isAllOnesValue() const { return getValue() == -1; }
@@ -188,6 +199,7 @@ public:
   }
 
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
+  ///
   static inline bool classof(const ConstantSInt *) { return true; }
   static bool classof(const Constant *CPV);  // defined in Constants.cpp
   static inline bool classof(const Value *V) {
@@ -205,12 +217,15 @@ protected:
   ConstantUInt(const Type *Ty, uint64_t V);
 public:
   /// get() - Static factory methods - Return objects of the specified value
+  ///
   static ConstantUInt *get(const Type *Ty, uint64_t V);
 
   /// isValueValidForType - return true if Ty is big enough to represent V.
+  ///
   static bool isValueValidForType(const Type *Ty, uint64_t V);
 
   /// getValue - return the underlying value of this constant.
+  ///
   inline uint64_t getValue() const { return Val.Unsigned; }
 
   /// isMaxValue - Return true if this is the largest value that may be
@@ -268,7 +283,6 @@ class ConstantArray : public Constant {
   ConstantArray(const ConstantArray &);      // DO NOT IMPLEMENT
 protected:
   ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
-  void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
 public:
   /// get() - Static factory methods - Return objects of the specified value
   static ConstantArray *get(const ArrayType *T, const std::vector<Constant*> &);
@@ -303,7 +317,8 @@ public:
   }
 
   virtual void destroyConstant();
-  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To);
+  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
+                                           bool DisableChecking = false);
 
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ConstantArray *) { return true; }
@@ -323,7 +338,6 @@ class ConstantStruct : public Constant {
   ConstantStruct(const ConstantStruct &);      // DO NOT IMPLEMENT
 protected:
   ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
-  void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
 public:
   /// get() - Static factory methods - Return objects of the specified value
   static ConstantStruct *get(const StructType *T,
@@ -350,7 +364,8 @@ public:
   }
 
   virtual void destroyConstant();
-  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To);
+  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
+                                           bool DisableChecking = false);
   
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ConstantStruct *) { return true; }
@@ -395,7 +410,6 @@ class ConstantPointerNull : public ConstantPointer {
   ConstantPointerNull(const ConstantPointerNull &);      // DO NOT IMPLEMENT
 protected:
   ConstantPointerNull(const PointerType *T) : ConstantPointer(T) {}
-  void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
 
 public:
 
@@ -444,7 +458,8 @@ public:
   }
 
   virtual void destroyConstant();
-  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To);
+  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
+                                           bool DisableChecking = false);
 
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const ConstantPointerRef *) { return true; }
@@ -470,6 +485,7 @@ class ConstantExpr : public Constant {
   unsigned iType;      // Operation type (an Instruction opcode)
   friend struct ConstantCreator<ConstantExpr,Type,
                             std::pair<unsigned, std::vector<Constant*> > >;
+  friend struct ConvertConstantType<ConstantExpr, Type>;
   
 protected:
   // Cast creation ctor
@@ -479,7 +495,15 @@ protected:
   // GEP instruction creation ctor
   ConstantExpr(Constant *C, const std::vector<Constant*> &IdxList,
                const Type *DestTy);
-  void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
+
+  // These private methods are used by the type resolution code to create
+  // ConstantExprs in intermediate forms.
+  static Constant *getTy(const Type *Ty, unsigned Opcode,
+                         Constant *C1, Constant *C2);
+  static Constant *getShiftTy(const Type *Ty,
+                              unsigned Opcode, Constant *C1, Constant *C2);
+  static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
+                                      const std::vector<Constant*> &IdxList);
   
 public:
   // Static methods to construct a ConstantExpr of different kinds.  Note that
@@ -488,15 +512,23 @@ public:
   // expression into something simpler if possible.
   
   /// Cast constant expr
+  ///
   static Constant *getCast(Constant *C, const Type *Ty);
 
   /// Binary constant expr - Use with binary operators...
-  static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
+  ///
+  static Constant *get(unsigned Opcode, Constant *C1, Constant *C2) {
+    return getTy(C1->getType(), Opcode, C1, C2);
+  }
 
   /// getShift - Return a shift left or shift right constant expr
-  static Constant *getShift(unsigned Opcode, Constant *C1, Constant *C2);
+  ///
+  static Constant *getShift(unsigned Opcode, Constant *C1, Constant *C2) {
+    return getShiftTy(C1->getType(), Opcode, C1, C2);
+  }
 
   /// Getelementptr form...
+  ///
   static Constant *getGetElementPtr(Constant *C,
                                     const std::vector<Constant*> &IdxList);
   
@@ -514,7 +546,8 @@ public:
   virtual bool isConstantExpr() const { return true; }
 
   virtual void destroyConstant();
-  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To);
+  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
+                                           bool DisableChecking = false);
     
   /// Override methods to provide more type information...
   inline Constant *getOperand(unsigned i) {