Add a method to reserve space for operands
[oota-llvm.git] / include / llvm / Constants.h
index 07d516bc173a27125d970ced4f48d052542b07d4..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
@@ -8,8 +8,6 @@
 #ifndef LLVM_CONSTANTS_H
 #define LLVM_CONSTANTS_H
 
-#include <assert.h>
-
 #include "llvm/Constant.h"
 #include "Support/DataTypes.h"
 
@@ -19,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.
@@ -133,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; }
@@ -159,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; }
@@ -190,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) {
@@ -207,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
@@ -270,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*> &);
@@ -305,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; }
@@ -325,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,
@@ -352,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; }
@@ -397,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:
 
@@ -446,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; }
@@ -472,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
@@ -481,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
@@ -490,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);
   
@@ -516,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) {