remove obsolete method.
[oota-llvm.git] / include / llvm / Instructions.h
index c80154c76d0a3804820078ed04dcf15b426fd7e8..137c5e22310f98fe207c8b0419cfb5e5440ffeeb 100644 (file)
@@ -39,14 +39,13 @@ class APInt;
 /// AllocaInst.
 ///
 class AllocationInst : public UnaryInstruction {
-  unsigned Alignment;
 protected:
   AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
                  const std::string &Name = "", Instruction *InsertBefore = 0);
   AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
                  const std::string &Name, BasicBlock *InsertAtEnd);
 public:
-  // Out of line virtual method, so the vtable, etc has a home.
+  // Out of line virtual method, so the vtable, etc. has a home.
   virtual ~AllocationInst();
 
   /// isArrayAllocation - Return true if there is an allocation size parameter
@@ -74,11 +73,8 @@ public:
   /// getAlignment - Return the alignment of the memory that is being allocated
   /// by the instruction.
   ///
-  unsigned getAlignment() const { return Alignment; }
-  void setAlignment(unsigned Align) {
-    assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
-    Alignment = Align;
-  }
+  unsigned getAlignment() const { return (1u << SubclassData) >> 1; }
+  void setAlignment(unsigned Align);
 
   virtual Instruction *clone() const = 0;
 
@@ -291,6 +287,7 @@ public:
 /// StoreInst - an instruction for storing to memory
 ///
 class StoreInst : public Instruction {
+  void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
   Use Ops[2];
   
   StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
@@ -305,6 +302,10 @@ class StoreInst : public Instruction {
   }
   void AssertOK();
 public:
+  // allocate space for exactly two operands
+  void *operator new(size_t s) {
+    return User::operator new(s, 2);
+  }
   StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
   StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
   StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
@@ -442,7 +443,6 @@ class GetElementPtrInst : public Instruction {
     }
   }
 
-public:
   /// Constructors - Create a getelementptr instruction with a base pointer an
   /// list of indices.  The first ctor can optionally insert before an existing
   /// instruction, the second appends the new instruction to the specified
@@ -451,7 +451,7 @@ public:
   GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, 
                     InputIterator IdxEnd,
                     const std::string &Name = "",
-                    Instruction *InsertBefore =0)
+                    Instruction *InsertBefore = 0)
       : Instruction(PointerType::get(
                       checkType(getIndexedType(Ptr->getType(),
                                                IdxBegin, IdxEnd, true)),
@@ -475,9 +475,33 @@ public:
   /// Constructors - These two constructors are convenience methods because one
   /// and two index getelementptr instructions are so common.
   GetElementPtrInst(Value *Ptr, Value *Idx,
-                    const std::string &Name = "", Instruction *InsertBefore =0);
+                    const std::string &Name = "", Instruction *InsertBefore = 0);
   GetElementPtrInst(Value *Ptr, Value *Idx,
                     const std::string &Name, BasicBlock *InsertAtEnd);
+public:
+  template<typename InputIterator>
+  static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin, 
+                                   InputIterator IdxEnd,
+                                   const std::string &Name = "",
+                                   Instruction *InsertBefore = 0) {
+    return new(0/*FIXME*/) GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Name, InsertBefore);
+  }
+  template<typename InputIterator>
+  static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
+                                   const std::string &Name, BasicBlock *InsertAtEnd) {
+    return new(0/*FIXME*/) GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Name, InsertAtEnd);
+  }
+
+  /// Constructors - These two constructors are convenience methods because one
+  /// and two index getelementptr instructions are so common.
+  static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
+                                   const std::string &Name = "", Instruction *InsertBefore = 0) {
+    return new(2/*FIXME*/) GetElementPtrInst(Ptr, Idx, Name, InsertBefore);
+  }
+  static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
+                                   const std::string &Name, BasicBlock *InsertAtEnd) {
+    return new(2/*FIXME*/) GetElementPtrInst(Ptr, Idx, Name, InsertAtEnd);
+  }
   ~GetElementPtrInst();
 
   virtual GetElementPtrInst *clone() const;
@@ -870,7 +894,6 @@ class CallInst : public Instruction {
     setName(Name);
   }
 
-public:
   /// Construct a CallInst given a range of arguments.  InputIterator
   /// must be a random-access iterator pointing to contiguous storage
   /// (e.g. a std::vector<>::iterator).  Checks are made for
@@ -910,6 +933,33 @@ public:
   explicit CallInst(Value *F, const std::string &Name = "",
                     Instruction *InsertBefore = 0);
   CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
+public:
+  template<typename InputIterator>
+  static CallInst *Create(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
+                          const std::string &Name = "", Instruction *InsertBefore = 0) {
+    return new(ArgEnd - ArgBegin + 1) CallInst(Func, ArgBegin, ArgEnd, Name, InsertBefore);
+  }
+  template<typename InputIterator>
+  static CallInst *Create(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
+                          const std::string &Name, BasicBlock *InsertAtEnd) {
+    return new(ArgEnd - ArgBegin + 1) CallInst(Func, ArgBegin, ArgEnd, Name, InsertAtEnd);
+  }
+  static CallInst *Create(Value *F, Value *Actual, const std::string& Name = "",
+                          Instruction *InsertBefore = 0) {
+    return new(2) CallInst(F, Actual, Name, InsertBefore);
+  }
+  static CallInst *Create(Value *F, Value *Actual, const std::string& Name,
+                          BasicBlock *InsertAtEnd) {
+    return new(2) CallInst(F, Actual, Name, InsertAtEnd);
+  }
+  static CallInst *Create(Value *F, const std::string &Name = "",
+                          Instruction *InsertBefore = 0) {
+    return new(1) CallInst(F, Name, InsertBefore);
+  }
+  static CallInst *Create(Value *F, const std::string &Name, BasicBlock *InsertAtEnd) {
+    return new(1) CallInst(F, Name, InsertAtEnd);
+  }
+
   ~CallInst();
 
   virtual CallInst *clone() const;
@@ -1015,7 +1065,6 @@ class SelectInst : public Instruction {
     : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
     init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
   }
-public:
   SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
              Instruction *InsertBefore = 0)
     : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
@@ -1028,6 +1077,15 @@ public:
     init(C, S1, S2);
     setName(Name);
   }
+public:
+  static SelectInst *Create(Value *C, Value *S1, Value *S2, const std::string &Name = "",
+             Instruction *InsertBefore = 0) {
+    return new(3) SelectInst(C, S1, S2, Name, InsertBefore);
+  }
+  static SelectInst *Create(Value *C, Value *S1, Value *S2, const std::string &Name,
+             BasicBlock *InsertAtEnd) {
+    return new(3) SelectInst(C, S1, S2, Name, InsertAtEnd);
+  }
 
   Value *getCondition() const { return Ops[0]; }
   Value *getTrueValue() const { return Ops[1]; }
@@ -1110,6 +1168,10 @@ class ExtractElementInst : public Instruction {
   }
 
 public:
+  // allocate space for exactly two operands
+  void *operator new(size_t s) {
+    return User::operator new(s, 2); // FIXME: unsigned Idx forms of constructor?
+  }
   ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
                      Instruction *InsertBefore = 0);
   ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
@@ -1156,7 +1218,6 @@ public:
 class InsertElementInst : public Instruction {
   Use Ops[3];
   InsertElementInst(const InsertElementInst &IE);
-public:
   InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
                     const std::string &Name = "",Instruction *InsertBefore = 0);
   InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
@@ -1165,6 +1226,26 @@ public:
                     const std::string &Name, BasicBlock *InsertAtEnd);
   InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
                     const std::string &Name, BasicBlock *InsertAtEnd);
+public:
+  static InsertElementInst *Create(const InsertElementInst &IE) {
+    return new(IE.getNumOperands()) InsertElementInst(IE);
+  }
+  static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
+                                   const std::string &Name = "",Instruction *InsertBefore = 0) {
+    return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
+  }
+  static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
+                                   const std::string &Name = "",Instruction *InsertBefore = 0) {
+    return new(3/*FIXME*/) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
+  }
+  static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
+                                   const std::string &Name, BasicBlock *InsertAtEnd) {
+    return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
+  }
+  static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
+                                   const std::string &Name, BasicBlock *InsertAtEnd) {
+    return new(3/*FIXME*/) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
+  }
 
   /// isValidOperands - Return true if an insertelement instruction can be
   /// formed with the specified operands.
@@ -1211,6 +1292,10 @@ class ShuffleVectorInst : public Instruction {
   Use Ops[3];
   ShuffleVectorInst(const ShuffleVectorInst &IE);
 public:
+  // allocate space for exactly three operands
+  void *operator new(size_t s) {
+    return User::operator new(s, 3);
+  }
   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
                     const std::string &Name = "", Instruction *InsertBefor = 0);
   ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
@@ -1269,11 +1354,15 @@ public:
 // scientist's overactive imagination.
 //
 class PHINode : public Instruction {
+  void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
   /// the number actually in use.
   unsigned ReservedSpace;
   PHINode(const PHINode &PN);
-public:
+  // allocate space for exactly zero operands
+  void *operator new(size_t s) {
+    return User::operator new(s, 0);
+  }
   explicit PHINode(const Type *Ty, const std::string &Name = "",
                    Instruction *InsertBefore = 0)
     : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
@@ -1286,7 +1375,14 @@ public:
       ReservedSpace(0) {
     setName(Name);
   }
-
+public:
+  static PHINode *Create(const Type *Ty, const std::string &Name = "",
+                         Instruction *InsertBefore = 0) {
+    return new PHINode(Ty, Name, InsertBefore);
+  }
+  static PHINode *Create(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) {
+    return new PHINode(Ty, Name, InsertAtEnd);
+  }
   ~PHINode();
 
   /// reserveOperandSpace - This method can be used to avoid repeated
@@ -1405,7 +1501,7 @@ class ReturnInst : public TerminatorInst {
   ReturnInst(const ReturnInst &RI);
   void init(Value * const* retVals, unsigned N);
 
-public:
+private:
   // ReturnInst constructors:
   // ReturnInst()                  - 'ret void' instruction
   // ReturnInst(    null)          - 'ret void' instruction
@@ -1426,6 +1522,25 @@ public:
   ReturnInst(Value * const* retVals, unsigned N, Instruction *InsertBefore);
   ReturnInst(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd);
   explicit ReturnInst(BasicBlock *InsertAtEnd);
+public:
+  static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) {
+    return new(!!retVal) ReturnInst(retVal, InsertBefore);
+  }
+  static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) {
+    return new(!!retVal) ReturnInst(retVal, InsertAtEnd);
+  }
+  static ReturnInst* Create(Value * const* retVals, unsigned N) {
+    return new(N) ReturnInst(retVals, N);
+  }
+  static ReturnInst* Create(Value * const* retVals, unsigned N, Instruction *InsertBefore) {
+    return new(N) ReturnInst(retVals, N, InsertBefore);
+  }
+  static ReturnInst* Create(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd) {
+    return new(N) ReturnInst(retVals, N, InsertAtEnd);
+  }
+  static ReturnInst* Create(BasicBlock *InsertAtEnd) {
+    return new(0) ReturnInst(InsertAtEnd);
+  }
   virtual ~ReturnInst();
 
   virtual ReturnInst *clone() const;
@@ -1471,7 +1586,6 @@ class BranchInst : public TerminatorInst {
   Use Ops[3];
   BranchInst(const BranchInst &BI);
   void AssertOK();
-public:
   // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
   // BranchInst(BB *B)                           - 'br B'
   // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
@@ -1485,6 +1599,21 @@ public:
   BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
   BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
              BasicBlock *InsertAtEnd);
+public:
+  static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
+    return new(1) BranchInst(IfTrue, InsertBefore);
+  }
+  static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
+                            Instruction *InsertBefore = 0) {
+    return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
+  }
+  static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
+    return new(1) BranchInst(IfTrue, InsertAtEnd);
+  }
+  static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
+                            BasicBlock *InsertAtEnd) {
+    return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
+  }
 
   /// Transparently provide more efficient getOperand methods.
   Value *getOperand(unsigned i) const {
@@ -1565,7 +1694,6 @@ class SwitchInst : public TerminatorInst {
   SwitchInst(const SwitchInst &RI);
   void init(Value *Value, BasicBlock *Default, unsigned NumCases);
   void resizeOperands(unsigned No);
-public:
   /// SwitchInst ctor - Create a new switch instruction, specifying a value to
   /// switch on and a default destination.  The number of additional cases can
   /// be specified here to make memory allocation more efficient.  This
@@ -1579,9 +1707,17 @@ public:
   /// constructor also autoinserts at the end of the specified BasicBlock.
   SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
              BasicBlock *InsertAtEnd);
+public:
+  static SwitchInst *Create(Value *Value, BasicBlock *Default, unsigned NumCases,
+                            Instruction *InsertBefore = 0) {
+    return new(NumCases/*FIXME*/) SwitchInst(Value, Default, NumCases, InsertBefore);
+  }
+  static SwitchInst *Create(Value *Value, BasicBlock *Default, unsigned NumCases,
+                            BasicBlock *InsertAtEnd) {
+    return new(NumCases/*FIXME*/) SwitchInst(Value, Default, NumCases, InsertAtEnd);
+  }
   ~SwitchInst();
 
-
   // Accessor Methods for Switch stmt
   Value *getCondition() const { return getOperand(0); }
   void setCondition(Value *V) { setOperand(0, V); }
@@ -1707,7 +1843,6 @@ class InvokeInst : public TerminatorInst {
     setName(Name);
   }
 
-public:
   /// Construct an InvokeInst given a range of arguments.
   /// InputIterator must be a random-access iterator pointing to
   /// contiguous storage (e.g. a std::vector<>::iterator).  Checks are
@@ -1743,6 +1878,19 @@ public:
     init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
          typename std::iterator_traits<InputIterator>::iterator_category());
   }
+public:
+  template<typename InputIterator>
+  static InvokeInst *Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
+                            InputIterator ArgBegin, InputIterator ArgEnd,
+                            const std::string &Name = "", Instruction *InsertBefore = 0) {
+    return new(ArgEnd - ArgBegin + 3) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, InsertBefore);
+  }
+  template<typename InputIterator>
+  static InvokeInst *Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
+                            InputIterator ArgBegin, InputIterator ArgEnd,
+                            const std::string &Name, BasicBlock *InsertAtEnd) {
+    return new(ArgEnd - ArgBegin + 3) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, InsertAtEnd);
+  }
 
   ~InvokeInst();
 
@@ -1860,7 +2008,12 @@ private:
 /// until an invoke instruction is found.
 ///
 class UnwindInst : public TerminatorInst {
+  void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
 public:
+  // allocate space for exactly zero operands
+  void *operator new(size_t s) {
+    return User::operator new(s, 0);
+  }
   explicit UnwindInst(Instruction *InsertBefore = 0);
   explicit UnwindInst(BasicBlock *InsertAtEnd);
 
@@ -1892,7 +2045,12 @@ private:
 /// end of the block cannot be reached.
 ///
 class UnreachableInst : public TerminatorInst {
+  void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
 public:
+  // allocate space for exactly zero operands
+  void *operator new(size_t s) {
+    return User::operator new(s, 0);
+  }
   explicit UnreachableInst(Instruction *InsertBefore = 0);
   explicit UnreachableInst(BasicBlock *InsertAtEnd);
 
@@ -2392,7 +2550,8 @@ public:
 /// GetResultInst - This instruction extracts individual result value from
 /// aggregate value, where aggregate value is returned by CallInst.
 ///
-class GetResultInst : public Instruction {
+class GetResultInst : public /*FIXME: Unary*/Instruction {
+  void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
   Use Aggr;
   unsigned Idx;
   GetResultInst(const GetResultInst &GRI) :
@@ -2402,6 +2561,10 @@ class GetResultInst : public Instruction {
   }
 
 public:
+  // allocate space for exactly one operand
+  void *operator new(size_t s) {
+    return User::operator new(s, 1);
+  }
   explicit GetResultInst(Value *Aggr, unsigned index,
                          const std::string &Name = "",
                          Instruction *InsertBefore = 0);