[llvm-commits] [llvm] r48780 - in /llvm/branches/ggreif/use-diet: include/llvm/Instructions.h include/llvm/Support/LLVMBuilder.h lib/VMCore/AutoUpgrade.cpp

Chris Lattner clattner at apple.com
Tue Mar 25 11:06:55 PDT 2008


On Mar 25, 2008, at 10:55 AM, Gabor Greif wrote:

> Author: ggreif
> Date: Tue Mar 25 12:55:14 2008
> New Revision: 48780
>
> URL: http://llvm.org/viewvc/llvm-project?rev=48780&view=rev
> Log:
> Introduce static <Instr>::Create methods for CallInst and PHINode,  
> as per Sabre's suggestion. Make constructors private accordingly.

Hi Gabor,

Is there any reason not to do this on mainline?

-Chris

>
>
> Modified:
>    llvm/branches/ggreif/use-diet/include/llvm/Instructions.h
>    llvm/branches/ggreif/use-diet/include/llvm/Support/LLVMBuilder.h
>    llvm/branches/ggreif/use-diet/lib/VMCore/AutoUpgrade.cpp
>
> Modified: llvm/branches/ggreif/use-diet/include/llvm/Instructions.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/Instructions.h?rev=48780&r1=48779&r2=48780&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/branches/ggreif/use-diet/include/llvm/Instructions.h  
> (original)
> +++ llvm/branches/ggreif/use-diet/include/llvm/Instructions.h Tue  
> Mar 25 12:55:14 2008
> @@ -875,7 +875,6 @@
>     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
> @@ -915,6 +914,33 @@
>   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;
> @@ -1279,7 +1305,6 @@
>   /// 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);
> @@ -1296,7 +1321,14 @@
>       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
>
> Modified: llvm/branches/ggreif/use-diet/include/llvm/Support/ 
> LLVMBuilder.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/Support/LLVMBuilder.h?rev=48780&r1=48779&r2=48780&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/branches/ggreif/use-diet/include/llvm/Support/LLVMBuilder.h  
> (original)
> +++ llvm/branches/ggreif/use-diet/include/llvm/Support/LLVMBuilder.h  
> Tue Mar 25 12:55:14 2008
> @@ -388,21 +388,20 @@
>   // 
> = 
> = 
> =-------------------------------------------------------------------- 
> ===//
>
>   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(1) CallInst(Callee, Name));
> +    return Insert(CallInst::Create(Callee, Name));
>   }
>   CallInst *CreateCall(Value *Callee, Value *Arg, const char *Name =  
> "") {
> -    return Insert(new(2) 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 = "") {
> -    unsigned FIXME(1 + (ArgEnd - ArgBegin));
> -    return Insert(new(FIXME) CallInst(Callee, ArgBegin, ArgEnd,  
> Name));
> +    return Insert(CallInst::Create(Callee, ArgBegin, ArgEnd, Name));
>   }
>
>   SelectInst *CreateSelect(Value *C, Value *True, Value *False,
>
> Modified: llvm/branches/ggreif/use-diet/lib/VMCore/AutoUpgrade.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/lib/VMCore/AutoUpgrade.cpp?rev=48780&r1=48779&r2=48780&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/branches/ggreif/use-diet/lib/VMCore/AutoUpgrade.cpp  
> (original)
> +++ llvm/branches/ggreif/use-diet/lib/VMCore/AutoUpgrade.cpp Tue Mar  
> 25 12:55:14 2008
> @@ -240,9 +240,8 @@
>     Operands[1] = BC;
>
>     //  Construct a new CallInst
> -    unsigned FIXME;
> -    CallInst *NewCI = new(FIXME) CallInst(NewFn, Operands, Operands 
> +2,
> -                                   "upgraded."+CI->getName(), CI);
> +    CallInst *NewCI = CallInst::Create(NewFn, Operands, Operands+2,
> +                                       "upgraded."+CI->getName(),  
> CI);
>     NewCI->setTailCall(CI->isTailCall());
>     NewCI->setCallingConv(CI->getCallingConv());
>
> @@ -264,9 +263,8 @@
>     SmallVector<Value*, 8> Operands(CI->op_begin()+1, CI->op_end());
>
>     //  Construct a new CallInst
> -    unsigned FIXME;
> -    CallInst *NewCI = new(FIXME) CallInst(NewFn, Operands.begin(),  
> Operands.end(),
> -                                          "upgraded."+CI- 
> >getName(), CI);
> +    CallInst *NewCI = CallInst::Create(NewFn, Operands.begin(),  
> Operands.end(),
> +                                       "upgraded."+CI->getName(),  
> CI);
>     NewCI->setTailCall(CI->isTailCall());
>     NewCI->setCallingConv(CI->getCallingConv());
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list