diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/BasicBlock.h | 17 | ||||
-rw-r--r-- | include/llvm/Constants.h | 31 | ||||
-rw-r--r-- | include/llvm/Function.h | 9 | ||||
-rw-r--r-- | include/llvm/GlobalAlias.h | 4 | ||||
-rw-r--r-- | include/llvm/GlobalVariable.h | 5 | ||||
-rw-r--r-- | include/llvm/InstrTypes.h | 16 | ||||
-rw-r--r-- | include/llvm/Instructions.h | 197 | ||||
-rw-r--r-- | include/llvm/Support/LLVMBuilder.h | 32 | ||||
-rw-r--r-- | include/llvm/User.h | 6 |
9 files changed, 277 insertions, 40 deletions
diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h index 253a8fa1a0..797f50e864 100644 --- a/include/llvm/BasicBlock.h +++ b/include/llvm/BasicBlock.h @@ -66,17 +66,22 @@ private : BasicBlock(const BasicBlock &); // Do not implement void operator=(const BasicBlock &); // Do not implement -public: - /// Instruction iterators... - typedef InstListType::iterator iterator; - typedef InstListType::const_iterator const_iterator; - /// BasicBlock ctor - If the function parameter is specified, the basic block /// is automatically inserted at either the end of the function (if /// InsertBefore is null), or before the specified basic block. /// explicit BasicBlock(const std::string &Name = "", Function *Parent = 0, - BasicBlock *InsertBefore = 0, BasicBlock *unwindDest = 0); + BasicBlock *InsertBefore = 0, BasicBlock *UnwindDest = 0); +public: + /// Instruction iterators... + typedef InstListType::iterator iterator; + typedef InstListType::const_iterator const_iterator; + + // allocate space for exactly zero operands + static BasicBlock *Create(const std::string &Name = "", Function *Parent = 0, + BasicBlock *InsertBefore = 0, BasicBlock *UnwindDest = 0) { + return new(!!UnwindDest) BasicBlock(Name, Parent, InsertBefore, UnwindDest); + } ~BasicBlock(); /// getUnwindDest - Returns the BasicBlock that flow will enter if an unwind diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index f71c655455..13df601f41 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -43,9 +43,15 @@ struct ConvertConstantType; /// @brief Class for constant integers. class ConstantInt : public Constant { static ConstantInt *TheTrueVal, *TheFalseVal; + void *operator new(size_t, unsigned); // DO NOT IMPLEMENT ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT ConstantInt(const IntegerType *Ty, const APInt& V); APInt Val; +protected: + // allocate space for exactly zero operands + void *operator new(size_t s) { + return User::operator new(s, 0); + } public: /// Return the constant as an APInt value reference. This allows clients to /// obtain a copy of the value, with all its precision in tact. @@ -215,9 +221,15 @@ private: /// class ConstantFP : public Constant { APFloat Val; + void *operator new(size_t, unsigned);// DO NOT IMPLEMENT ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT protected: ConstantFP(const Type *Ty, const APFloat& V); +protected: + // allocate space for exactly zero operands + void *operator new(size_t s) { + return User::operator new(s, 0); + } public: /// get() - Static factory methods - Return objects of the specified value static ConstantFP *get(const Type *Ty, const APFloat& V); @@ -262,10 +274,16 @@ public: /// class ConstantAggregateZero : public Constant { friend struct ConstantCreator<ConstantAggregateZero, Type, char>; + void *operator new(size_t, unsigned); // DO NOT IMPLEMENT ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT protected: explicit ConstantAggregateZero(const Type *Ty) : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {} +protected: + // allocate space for exactly zero operands + void *operator new(size_t s) { + return User::operator new(s, 0); + } public: /// get() - static factory method for creating a null aggregate. It is /// illegal to call this method with a non-aggregate type. @@ -457,14 +475,19 @@ public: /// class ConstantPointerNull : public Constant { friend struct ConstantCreator<ConstantPointerNull, PointerType, char>; + void *operator new(size_t, unsigned); // DO NOT IMPLEMENT ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT protected: explicit ConstantPointerNull(const PointerType *T) : Constant(reinterpret_cast<const Type*>(T), Value::ConstantPointerNullVal, 0, 0) {} +protected: + // allocate space for exactly zero operands + void *operator new(size_t s) { + return User::operator new(s, 0); + } public: - /// get() - Static factory methods - Return objects of the specified value static ConstantPointerNull *get(const PointerType *T); @@ -706,9 +729,15 @@ public: /// class UndefValue : public Constant { friend struct ConstantCreator<UndefValue, Type, char>; + void *operator new(size_t, unsigned); // DO NOT IMPLEMENT UndefValue(const UndefValue &); // DO NOT IMPLEMENT protected: explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {} +protected: + // allocate space for exactly zero operands + void *operator new(size_t s) { + return User::operator new(s, 0); + } public: /// get() - Static factory methods - Return an 'undef' object of the specified /// type. diff --git a/include/llvm/Function.h b/include/llvm/Function.h index 36b0dd3df8..ae51fe2f00 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -104,13 +104,20 @@ private: Function(const Function&); // DO NOT IMPLEMENT void operator=(const Function&); // DO NOT IMPLEMENT -public: + /// Function ctor - If the (optional) Module argument is specified, the /// function is automatically inserted into the end of the function list for /// the module. /// Function(const FunctionType *Ty, LinkageTypes Linkage, const std::string &N = "", Module *M = 0); + +public: + static Function *Create(const FunctionType *Ty, LinkageTypes Linkage, + const std::string &N = "", Module *M = 0) { + return new(0) Function(Ty, Linkage, N, M); + } + ~Function(); const Type *getReturnType() const; // Return the type of the ret val diff --git a/include/llvm/GlobalAlias.h b/include/llvm/GlobalAlias.h index 161cb58cbb..b59537c9af 100644 --- a/include/llvm/GlobalAlias.h +++ b/include/llvm/GlobalAlias.h @@ -44,6 +44,10 @@ class GlobalAlias : public GlobalValue { Use Aliasee; public: + // allocate space for exactly zero operands + void *operator new(size_t s) { + return User::operator new(s, 0); + } /// GlobalAlias ctor - If a parent module is specified, the alias is /// automatically inserted into the end of the specified module's alias list. GlobalAlias(const Type *Ty, LinkageTypes Linkage, const std::string &Name = "", diff --git a/include/llvm/GlobalVariable.h b/include/llvm/GlobalVariable.h index d733798479..8c6d8030c6 100644 --- a/include/llvm/GlobalVariable.h +++ b/include/llvm/GlobalVariable.h @@ -32,6 +32,7 @@ template<typename ValueSubClass, typename ItemParentClass> class GlobalVariable : public GlobalValue { friend class SymbolTableListTraits<GlobalVariable, Module>; + void *operator new(size_t, unsigned); // Do not implement void operator=(const GlobalVariable &); // Do not implement GlobalVariable(const GlobalVariable &); // Do not implement @@ -46,6 +47,10 @@ class GlobalVariable : public GlobalValue { Use Initializer; public: + // allocate space for exactly zero operands + void *operator new(size_t s) { + return User::operator new(s, 0); + } /// GlobalVariable ctor - If a parent module is specified, the global is /// automatically inserted into the end of the specified modules global list. GlobalVariable(const Type *Ty, bool isConstant, LinkageTypes Linkage, diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h index 7441a104b5..ef0ee89a3e 100644 --- a/include/llvm/InstrTypes.h +++ b/include/llvm/InstrTypes.h @@ -83,6 +83,7 @@ public: //===----------------------------------------------------------------------===// class UnaryInstruction : public Instruction { + void *operator new(size_t, unsigned); // Do not implement Use Op; // avoiding warning: 'this' : used in base member initializer list @@ -95,6 +96,11 @@ protected: : Instruction(Ty, iType, &Op, 1, IAE), Op(V, this_()) { } public: + // allocate space for exactly one operand + void *operator new(size_t s) { + return User::operator new(s, 1); + } + // Out of line virtual method, so the vtable, etc has a home. ~UnaryInstruction(); @@ -129,6 +135,7 @@ public: //===----------------------------------------------------------------------===// class BinaryOperator : public Instruction { + void *operator new(size_t, unsigned); // Do not implement Use Ops[2]; protected: void init(BinaryOps iType); @@ -137,6 +144,10 @@ protected: BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd); public: + // allocate space for exactly two operands + void *operator new(size_t s) { + return User::operator new(s, 2); + } /// Transparently provide more efficient getOperand methods. Value *getOperand(unsigned i) const { @@ -489,6 +500,7 @@ public: /// This class is the base class for the comparison instructions. /// @brief Abstract base class of comparison instructions. class CmpInst: public Instruction { + void *operator new(size_t, unsigned); // DO NOT IMPLEMENT CmpInst(); // do not implement protected: CmpInst(Instruction::OtherOps op, unsigned short pred, Value *LHS, Value *RHS, @@ -500,6 +512,10 @@ protected: Use Ops[2]; // CmpInst instructions always have 2 operands, optimize public: + // allocate space for exactly two operands + void *operator new(size_t s) { + return User::operator new(s, 2); + } /// Construct a compare instruction, given the opcode, the predicate and /// the two operands. Optionally (if InstBefore is specified) insert the /// instruction into a BasicBlock right before the specified instruction. diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 2f66ffce22..137c5e2231 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -45,7 +45,7 @@ protected: 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 @@ -287,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) { @@ -301,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, @@ -438,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 @@ -447,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)), @@ -471,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; @@ -866,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 @@ -906,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; @@ -1011,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) { @@ -1024,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]; } @@ -1106,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 = "", @@ -1152,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, @@ -1161,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. @@ -1207,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, @@ -1265,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), @@ -1282,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 @@ -1401,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 @@ -1422,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; @@ -1467,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' @@ -1481,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 { @@ -1561,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 @@ -1575,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); } @@ -1703,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 @@ -1739,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(); @@ -1856,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); @@ -1888,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); @@ -2388,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) : @@ -2398,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); diff --git a/include/llvm/Support/LLVMBuilder.h b/include/llvm/Support/LLVMBuilder.h index 2a7fc635d7..c82bfd7b18 100644 --- a/include/llvm/Support/LLVMBuilder.h +++ b/include/llvm/Support/LLVMBuilder.h @@ -87,32 +87,32 @@ public: /// CreateRetVoid - Create a 'ret void' instruction. ReturnInst *CreateRetVoid() { - return Insert(new ReturnInst()); + return Insert(ReturnInst::Create()); } /// @verbatim /// CreateRet - Create a 'ret <val>' instruction. /// @endverbatim ReturnInst *CreateRet(Value *V) { - return Insert(new ReturnInst(V)); + return Insert(ReturnInst::Create(V)); } /// CreateBr - Create an unconditional 'br label X' instruction. BranchInst *CreateBr(BasicBlock *Dest) { - return Insert(new BranchInst(Dest)); + return Insert(BranchInst::Create(Dest)); } /// CreateCondBr - Create a conditional 'br Cond, TrueDest, FalseDest' /// instruction. BranchInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False) { - return Insert(new BranchInst(True, False, Cond)); + return Insert(BranchInst::Create(True, False, Cond)); } /// CreateSwitch - Create a switch instruction with the specified value, /// default dest, and with a hint for the number of cases that will be added /// (for efficient allocation). SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10) { - return Insert(new SwitchInst(V, Dest, NumCases)); + return Insert(SwitchInst::Create(V, Dest, NumCases)); } /// CreateInvoke - Create an invoke instruction. @@ -120,8 +120,8 @@ public: InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, InputIterator ArgBegin, InputIterator ArgEnd, const char *Name = "") { - return(Insert(new InvokeInst(Callee, NormalDest, UnwindDest, - ArgBegin, ArgEnd, Name))); + return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, + ArgBegin, ArgEnd, Name)); } UnwindInst *CreateUnwind() { @@ -221,10 +221,10 @@ public: template<typename InputIterator> GetElementPtrInst *CreateGEP(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd, const char *Name = "") { - return(Insert(new GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Name))); + return(Insert(GetElementPtrInst::Create(Ptr, IdxBegin, IdxEnd, Name))); } GetElementPtrInst *CreateGEP(Value *Ptr, Value *Idx, const char *Name = "") { - return Insert(new GetElementPtrInst(Ptr, Idx, Name)); + return Insert(GetElementPtrInst::Create(Ptr, Idx, Name)); } GetElementPtrInst *CreateStructGEP(Value *Ptr, unsigned Idx, const char *Name = "") { @@ -232,7 +232,7 @@ public: ConstantInt::get(llvm::Type::Int32Ty, 0), ConstantInt::get(llvm::Type::Int32Ty, Idx) }; - return Insert(new GetElementPtrInst(Ptr, Idxs, Idxs+2, Name)); + return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2, Name)); } //===--------------------------------------------------------------------===// @@ -384,25 +384,25 @@ public: //===--------------------------------------------------------------------===// PHINode *CreatePHI(const Type *Ty, const char *Name = "") { - return Insert(new PHINode(Ty, Name)); + return Insert(PHINode::Create(Ty, Name)); } CallInst *CreateCall(Value *Callee, const char *Name = "") { - return Insert(new CallInst(Callee, Name)); + return Insert(CallInst::Create(Callee, Name)); } CallInst *CreateCall(Value *Callee, Value *Arg, const char *Name = "") { - return Insert(new CallInst(Callee, Arg, Name)); + return Insert(CallInst::Create(Callee, Arg, Name)); } template<typename InputIterator> CallInst *CreateCall(Value *Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char *Name = "") { - return(Insert(new CallInst(Callee, ArgBegin, ArgEnd, Name))); + return Insert(CallInst::Create(Callee, ArgBegin, ArgEnd, Name)); } SelectInst *CreateSelect(Value *C, Value *True, Value *False, const char *Name = "") { - return Insert(new SelectInst(C, True, False, Name)); + return Insert(SelectInst::Create(C, True, False, Name)); } VAArgInst *CreateVAArg(Value *List, const Type *Ty, const char *Name = "") { @@ -416,7 +416,7 @@ public: InsertElementInst *CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const char *Name = "") { - return Insert(new InsertElementInst(Vec, NewElt, Idx, Name)); + return Insert(InsertElementInst::Create(Vec, NewElt, Idx, Name)); } ShuffleVectorInst *CreateShuffleVector(Value *V1, Value *V2, Value *Mask, diff --git a/include/llvm/User.h b/include/llvm/User.h index 0f1dcfe7a0..77bba9de64 100644 --- a/include/llvm/User.h +++ b/include/llvm/User.h @@ -25,6 +25,7 @@ namespace llvm { class User : public Value { User(const User &); // Do not implement + void *operator new(size_t); // Do not implement protected: /// OperandList - This is a pointer to the array of Users for this operand. /// For nodes of fixed arity (e.g. a binary operator) this array will live @@ -38,10 +39,13 @@ protected: /// unsigned NumOperands; -public: + void *operator new(size_t s, unsigned) { + return ::operator new(s); + } User(const Type *Ty, unsigned vty, Use *OpList, unsigned NumOps) : Value(Ty, vty), OperandList(OpList), NumOperands(NumOps) {} +public: Value *getOperand(unsigned i) const { assert(i < NumOperands && "getOperand() out of range!"); return OperandList[i]; |