Move ExtractElementInst to ::Create instead of new. Update all uses.
authorEric Christopher <echristo@apple.com>
Sat, 25 Jul 2009 02:28:41 +0000 (02:28 +0000)
committerEric Christopher <echristo@apple.com>
Sat, 25 Jul 2009 02:28:41 +0000 (02:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77044 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Instructions.h
include/llvm/Support/IRBuilder.h
lib/AsmParser/LLParser.cpp
lib/Bitcode/Reader/BitcodeReader.cpp
lib/Transforms/Scalar/GVNPRE.cpp
lib/Transforms/Scalar/InstructionCombining.cpp
lib/VMCore/Instructions.cpp

index 63a3dc0212bb5b251d97da0682e832aa5b41662e..1afcc5fc053110b58fc00e83c7b6c146ab98df21 100644 (file)
@@ -1270,15 +1270,25 @@ class ExtractElementInst : public Instruction {
     Op<1>() = EE.Op<1>();
   }
 
     Op<1>() = EE.Op<1>();
   }
 
-public:
-  // allocate space for exactly two operands
-  void *operator new(size_t s) {
-    return User::operator new(s, 2); // FIXME: "unsigned Idx" forms of ctor?
-  }
   ExtractElementInst(Value *Vec, Value *Idx, const std::string &NameStr = "",
                      Instruction *InsertBefore = 0);
   ExtractElementInst(Value *Vec, Value *Idx, const std::string &NameStr,
                      BasicBlock *InsertAtEnd);
   ExtractElementInst(Value *Vec, Value *Idx, const std::string &NameStr = "",
                      Instruction *InsertBefore = 0);
   ExtractElementInst(Value *Vec, Value *Idx, const std::string &NameStr,
                      BasicBlock *InsertAtEnd);
+public:
+  static ExtractElementInst *Create(const ExtractElementInst &EE) {
+    return new(EE.getNumOperands()) ExtractElementInst(EE);
+  }
+
+  static ExtractElementInst *Create(Value *Vec, Value *Idx,
+                                   const std::string &NameStr = "",
+                                   Instruction *InsertBefore = 0) {
+    return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
+  }
+  static ExtractElementInst *Create(Value *Vec, Value *Idx,
+                                   const std::string &NameStr,
+                                   BasicBlock *InsertAtEnd) {
+    return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
+  }
 
   /// isValidOperands - Return true if an extractelement instruction can be
   /// formed with the specified operands.
 
   /// isValidOperands - Return true if an extractelement instruction can be
   /// formed with the specified operands.
index ac134ec303f57fb7fff0d9a3353149f4d1db60a7..d22bc3d1038832f7e2b9dd68179e05e8c851099d 100644 (file)
@@ -641,7 +641,7 @@ public:
     if (Constant *VC = dyn_cast<Constant>(Vec))
       if (Constant *IC = dyn_cast<Constant>(Idx))
         return Folder.CreateExtractElement(VC, IC);
     if (Constant *VC = dyn_cast<Constant>(Vec))
       if (Constant *IC = dyn_cast<Constant>(Idx))
         return Folder.CreateExtractElement(VC, IC);
-    return Insert(new ExtractElementInst(Vec, Idx), Name);
+    return Insert(ExtractElementInst::Create(Vec, Idx), Name);
   }
 
   Value *CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx,
   }
 
   Value *CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx,
index 10d9470d40ef513dcdb66e09bb242f6a3e8408bd..60fc8ade7aceadd5b16d4542da21ddf08821b1b9 100644 (file)
@@ -3103,7 +3103,7 @@ bool LLParser::ParseExtractElement(Instruction *&Inst, PerFunctionState &PFS) {
   if (!ExtractElementInst::isValidOperands(Op0, Op1))
     return Error(Loc, "invalid extractelement operands");
   
   if (!ExtractElementInst::isValidOperands(Op0, Op1))
     return Error(Loc, "invalid extractelement operands");
   
-  Inst = new ExtractElementInst(Op0, Op1);
+  Inst = ExtractElementInst::Create(Op0, Op1);
   return false;
 }
 
   return false;
 }
 
index cf90c64ac69d23df5f2bb5beddacfe8c471d7342..dadfb9ebbcefc829f018d53e344f97f2a8d79e7c 100644 (file)
@@ -1666,7 +1666,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
       if (getValueTypePair(Record, OpNum, NextValueNo, Vec) ||
           getValue(Record, OpNum, Type::Int32Ty, Idx))
         return Error("Invalid EXTRACTELT record");
       if (getValueTypePair(Record, OpNum, NextValueNo, Vec) ||
           getValue(Record, OpNum, Type::Int32Ty, Idx))
         return Error("Invalid EXTRACTELT record");
-      I = new ExtractElementInst(Vec, Idx);
+      I = ExtractElementInst::Create(Vec, Idx);
       break;
     }
       
       break;
     }
       
index 85c272d7112cd27fac1b71f11e9dc7507edbd0e9..4588a7f24c5b68c7b8d5d2deda78e2d48ea8f834 100644 (file)
@@ -869,7 +869,7 @@ Value* GVNPRE::phi_translate(Value* V, BasicBlock* pred, BasicBlock* succ) {
                                  newOp1, newOp2,
                                  C->getName()+".expr");
       else if (ExtractElementInst* E = dyn_cast<ExtractElementInst>(U))
                                  newOp1, newOp2,
                                  C->getName()+".expr");
       else if (ExtractElementInst* E = dyn_cast<ExtractElementInst>(U))
-        newVal = new ExtractElementInst(newOp1, newOp2, E->getName()+".expr");
+        newVal = ExtractElementInst::Create(newOp1, newOp2, E->getName()+".expr");
       
       uint32_t v = VN.lookup_or_add(newVal);
       
       
       uint32_t v = VN.lookup_or_add(newVal);
       
@@ -1694,7 +1694,7 @@ void GVNPRE::insertion_pre(Value* e, BasicBlock* BB,
         newVal = InsertElementInst::Create(s1, s2, s3, S->getName()+".gvnpre",
                                            (*PI)->getTerminator());
       else if (ExtractElementInst* S = dyn_cast<ExtractElementInst>(U))
         newVal = InsertElementInst::Create(s1, s2, s3, S->getName()+".gvnpre",
                                            (*PI)->getTerminator());
       else if (ExtractElementInst* S = dyn_cast<ExtractElementInst>(U))
-        newVal = new ExtractElementInst(s1, s2, S->getName()+".gvnpre",
+        newVal = ExtractElementInst::Create(s1, s2, S->getName()+".gvnpre",
                                         (*PI)->getTerminator());
       else if (SelectInst* S = dyn_cast<SelectInst>(U))
         newVal = SelectInst::Create(s1, s2, s3, S->getName()+".gvnpre",
                                         (*PI)->getTerminator());
       else if (SelectInst* S = dyn_cast<SelectInst>(U))
         newVal = SelectInst::Create(s1, s2, s3, S->getName()+".gvnpre",
index e3d0744b30395f17f769f037725c3d9f9d2eeb35..3451b717264f230f7105818a10250b8aca957299 100644 (file)
@@ -1734,9 +1734,9 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
           Value *LHS = II->getOperand(1);
           Value *RHS = II->getOperand(2);
           // Extract the element as scalars.
           Value *LHS = II->getOperand(1);
           Value *RHS = II->getOperand(2);
           // Extract the element as scalars.
-          LHS = InsertNewInstBefore(new ExtractElementInst(LHS, 
+          LHS = InsertNewInstBefore(ExtractElementInst::Create(LHS, 
             ConstantInt::get(Type::Int32Ty, 0U, false), "tmp"), *II);
             ConstantInt::get(Type::Int32Ty, 0U, false), "tmp"), *II);
-          RHS = InsertNewInstBefore(new ExtractElementInst(RHS,
+          RHS = InsertNewInstBefore(ExtractElementInst::Create(RHS,
             ConstantInt::get(Type::Int32Ty, 0U, false), "tmp"), *II);
           
           switch (II->getIntrinsicID()) {
             ConstantInt::get(Type::Int32Ty, 0U, false), "tmp"), *II);
           
           switch (II->getIntrinsicID()) {
@@ -9012,7 +9012,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
     if (SrcVTy->getNumElements() == 1) {
       if (!isa<VectorType>(DestTy)) {
         Instruction *Elem =
     if (SrcVTy->getNumElements() == 1) {
       if (!isa<VectorType>(DestTy)) {
         Instruction *Elem =
-            new ExtractElementInst(Src, Context->getNullValue(Type::Int32Ty));
+          ExtractElementInst::Create(Src, Context->getNullValue(Type::Int32Ty));
         InsertNewInstBefore(Elem, CI);
         return CastInst::Create(Instruction::BitCast, Elem, DestTy);
       }
         InsertNewInstBefore(Elem, CI);
         return CastInst::Create(Instruction::BitCast, Elem, DestTy);
       }
@@ -9956,7 +9956,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
           
           if (ExtractedElts[Idx] == 0) {
             Instruction *Elt = 
           
           if (ExtractedElts[Idx] == 0) {
             Instruction *Elt = 
-              new ExtractElementInst(Idx < 16 ? Op0 : Op1, 
+              ExtractElementInst::Create(Idx < 16 ? Op0 : Op1, 
                   ConstantInt::get(Type::Int32Ty, Idx&15, false), "tmp");
             InsertNewInstBefore(Elt, CI);
             ExtractedElts[Idx] = Elt;
                   ConstantInt::get(Type::Int32Ty, Idx&15, false), "tmp");
             InsertNewInstBefore(Elt, CI);
             ExtractedElts[Idx] = Elt;
@@ -12419,10 +12419,10 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
         bool isConstantElt = isa<ConstantInt>(EI.getOperand(1));
         if (CheapToScalarize(BO, isConstantElt)) {
           ExtractElementInst *newEI0 = 
         bool isConstantElt = isa<ConstantInt>(EI.getOperand(1));
         if (CheapToScalarize(BO, isConstantElt)) {
           ExtractElementInst *newEI0 = 
-            new ExtractElementInst(BO->getOperand(0), EI.getOperand(1),
+            ExtractElementInst::Create(BO->getOperand(0), EI.getOperand(1),
                                    EI.getName()+".lhs");
           ExtractElementInst *newEI1 =
                                    EI.getName()+".lhs");
           ExtractElementInst *newEI1 =
-            new ExtractElementInst(BO->getOperand(1), EI.getOperand(1),
+            ExtractElementInst::Create(BO->getOperand(1), EI.getOperand(1),
                                    EI.getName()+".rhs");
           InsertNewInstBefore(newEI0, EI);
           InsertNewInstBefore(newEI1, EI);
                                    EI.getName()+".rhs");
           InsertNewInstBefore(newEI0, EI);
           InsertNewInstBefore(newEI1, EI);
@@ -12468,7 +12468,7 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
         } else {
           return ReplaceInstUsesWith(EI, Context->getUndef(EI.getType()));
         }
         } else {
           return ReplaceInstUsesWith(EI, Context->getUndef(EI.getType()));
         }
-        return new ExtractElementInst(Src,
+        return ExtractElementInst::Create(Src,
                          ConstantInt::get(Type::Int32Ty, SrcIdx, false));
       }
     }
                          ConstantInt::get(Type::Int32Ty, SrcIdx, false));
       }
     }
index 6fc94514e5b735fbe9d3c3605fefc1080d42841a..e1583c9ffd2d6c8567428b03090ed86afa01cf8d 100644 (file)
@@ -2982,7 +2982,7 @@ VAArgInst *VAArgInst::clone(LLVMContext&) const {
 }
 
 ExtractElementInst *ExtractElementInst::clone(LLVMContext&) const {
 }
 
 ExtractElementInst *ExtractElementInst::clone(LLVMContext&) const {
-  return new ExtractElementInst(*this);
+  return ExtractElementInst::Create(*this);
 }
 
 InsertElementInst *InsertElementInst::clone(LLVMContext&) const {
 }
 
 InsertElementInst *InsertElementInst::clone(LLVMContext&) const {