API changes for class Use size reduction, wave 1.
Specifically, introduction of XXX::Create methods
for Users that have a potentially variable number of
Uses.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49277 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp
index 0dc38a2..895e44a 100644
--- a/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -98,7 +98,7 @@
         RetVal = Constant::getNullValue(BB->getParent()->getReturnType());
 
       // Create the return...
-      NewTI = new ReturnInst(RetVal);
+      NewTI = ReturnInst::Create(RetVal);
     }
     break;
 
diff --git a/lib/Transforms/Utils/BreakCriticalEdges.cpp b/lib/Transforms/Utils/BreakCriticalEdges.cpp
index 78801db..1a41d95 100644
--- a/lib/Transforms/Utils/BreakCriticalEdges.cpp
+++ b/lib/Transforms/Utils/BreakCriticalEdges.cpp
@@ -122,10 +122,10 @@
   BasicBlock *DestBB = TI->getSuccessor(SuccNum);
 
   // Create a new basic block, linking it into the CFG.
-  BasicBlock *NewBB = new BasicBlock(TIBB->getName() + "." +
-                                     DestBB->getName() + "_crit_edge");
+  BasicBlock *NewBB = BasicBlock::Create(TIBB->getName() + "." +
+                                         DestBB->getName() + "_crit_edge");
   // Create our unconditional branch...
-  new BranchInst(DestBB, NewBB);
+  BranchInst::Create(DestBB, NewBB);
 
   // Branch to the new block, breaking the edge.
   TI->setSuccessor(SuccNum, NewBB);
diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp
index 7387144..ba9b57d 100644
--- a/lib/Transforms/Utils/CloneFunction.cpp
+++ b/lib/Transforms/Utils/CloneFunction.cpp
@@ -31,7 +31,7 @@
                                   DenseMap<const Value*, Value*> &ValueMap,
                                   const char *NameSuffix, Function *F,
                                   ClonedCodeInfo *CodeInfo) {
-  BasicBlock *NewBB = new BasicBlock("", F);
+  BasicBlock *NewBB = BasicBlock::Create("", F);
   if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix);
   NewBB->setUnwindDest(const_cast<BasicBlock*>(BB->getUnwindDest()));
 
@@ -144,7 +144,7 @@
                                     ArgTypes, F->getFunctionType()->isVarArg());
 
   // Create the new function...
-  Function *NewF = new Function(FTy, F->getLinkage(), F->getName());
+  Function *NewF = Function::Create(FTy, F->getLinkage(), F->getName());
 
   // Loop over the arguments, copying the names of the mapped arguments over...
   Function::arg_iterator DestI = NewF->arg_begin();
@@ -208,7 +208,7 @@
   
   // Nope, clone it now.
   BasicBlock *NewBB;
-  BBEntry = NewBB = new BasicBlock();
+  BBEntry = NewBB = BasicBlock::Create();
   if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix);
 
   bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false;
@@ -253,7 +253,7 @@
       // Constant fold to uncond branch!
       if (Cond) {
         BasicBlock *Dest = BI->getSuccessor(!Cond->getZExtValue());
-        ValueMap[OldTI] = new BranchInst(Dest, NewBB);
+        ValueMap[OldTI] = BranchInst::Create(Dest, NewBB);
         ToClone.push_back(Dest);
         TerminatorDone = true;
       }
@@ -265,7 +265,7 @@
       Cond = dyn_cast_or_null<ConstantInt>(ValueMap[SI->getCondition()]);
     if (Cond) {     // Constant fold to uncond branch!
       BasicBlock *Dest = SI->getSuccessor(SI->findCaseValue(Cond));
-      ValueMap[OldTI] = new BranchInst(Dest, NewBB);
+      ValueMap[OldTI] = BranchInst::Create(Dest, NewBB);
       ToClone.push_back(Dest);
       TerminatorDone = true;
     }
diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp
index f0ee1e2..e75f915 100644
--- a/lib/Transforms/Utils/CloneModule.cpp
+++ b/lib/Transforms/Utils/CloneModule.cpp
@@ -63,8 +63,8 @@
   // Loop over the functions in the module, making external functions as before
   for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) {
     Function *NF =
-      new Function(cast<FunctionType>(I->getType()->getElementType()),
-                   GlobalValue::ExternalLinkage, I->getName(), New);
+      Function::Create(cast<FunctionType>(I->getType()->getElementType()),
+                       GlobalValue::ExternalLinkage, I->getName(), New);
     NF->setCallingConv(I->getCallingConv());
     NF->setParamAttrs(I->getParamAttrs());
     if (I->hasCollector())
diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp
index 1be1c72..5434119 100644
--- a/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/lib/Transforms/Utils/CodeExtractor.cpp
@@ -161,8 +161,8 @@
       PHINode *PN = cast<PHINode>(AfterPHIs);
       // Create a new PHI node in the new region, which has an incoming value
       // from OldPred of PN.
-      PHINode *NewPN = new PHINode(PN->getType(), PN->getName()+".ce",
-                                   NewBB->begin());
+      PHINode *NewPN = PHINode::Create(PN->getType(), PN->getName()+".ce",
+                                       NewBB->begin());
       NewPN->addIncoming(PN, OldPred);
 
       // Loop over all of the incoming value in PN, moving them to NewPN if they
@@ -280,10 +280,10 @@
   const FunctionType *funcType = FunctionType::get(RetTy, paramTy, false);
 
   // Create the new function
-  Function *newFunction = new Function(funcType,
-                                       GlobalValue::InternalLinkage,
-                                       oldFunction->getName() + "_" +
-                                       header->getName(), M);
+  Function *newFunction = Function::Create(funcType,
+                                           GlobalValue::InternalLinkage,
+                                           oldFunction->getName() + "_" +
+                                           header->getName(), M);
   newFunction->getBasicBlockList().push_back(newRootNode);
 
   // Create an iterator to name all of the arguments we inserted.
@@ -299,8 +299,8 @@
       Idx[1] = ConstantInt::get(Type::Int32Ty, i);
       std::string GEPname = "gep_" + inputs[i]->getName();
       TerminatorInst *TI = newFunction->begin()->getTerminator();
-      GetElementPtrInst *GEP = new GetElementPtrInst(AI, Idx, Idx+2, 
-                                                     GEPname, TI);
+      GetElementPtrInst *GEP = GetElementPtrInst::Create(AI, Idx, Idx+2, 
+                                                         GEPname, TI);
       RewriteVal = new LoadInst(GEP, "load" + GEPname, TI);
     } else
       RewriteVal = AI++;
@@ -386,8 +386,8 @@
       Idx[0] = Constant::getNullValue(Type::Int32Ty);
       Idx[1] = ConstantInt::get(Type::Int32Ty, i);
       GetElementPtrInst *GEP =
-        new GetElementPtrInst(Struct, Idx, Idx + 2,
-                              "gep_" + StructValues[i]->getName());
+        GetElementPtrInst::Create(Struct, Idx, Idx + 2,
+                                  "gep_" + StructValues[i]->getName());
       codeReplacer->getInstList().push_back(GEP);
       StoreInst *SI = new StoreInst(StructValues[i], GEP);
       codeReplacer->getInstList().push_back(SI);
@@ -395,8 +395,8 @@
   }
 
   // Emit the call to the function
-  CallInst *call = new CallInst(newFunction, params.begin(), params.end(),
-                                NumExitBlocks > 1 ? "targetBlock" : "");
+  CallInst *call = CallInst::Create(newFunction, params.begin(), params.end(),
+                                    NumExitBlocks > 1 ? "targetBlock" : "");
   codeReplacer->getInstList().push_back(call);
 
   Function::arg_iterator OutputArgBegin = newFunction->arg_begin();
@@ -412,8 +412,8 @@
       Idx[0] = Constant::getNullValue(Type::Int32Ty);
       Idx[1] = ConstantInt::get(Type::Int32Ty, FirstOut + i);
       GetElementPtrInst *GEP
-        = new GetElementPtrInst(Struct, Idx, Idx + 2,
-                                "gep_reload_" + outputs[i]->getName());
+        = GetElementPtrInst::Create(Struct, Idx, Idx + 2,
+                                    "gep_reload_" + outputs[i]->getName());
       codeReplacer->getInstList().push_back(GEP);
       Output = GEP;
     } else {
@@ -431,8 +431,8 @@
 
   // Now we can emit a switch statement using the call as a value.
   SwitchInst *TheSwitch =
-    new SwitchInst(ConstantInt::getNullValue(Type::Int16Ty),
-                   codeReplacer, 0, codeReplacer);
+      SwitchInst::Create(ConstantInt::getNullValue(Type::Int16Ty),
+                         codeReplacer, 0, codeReplacer);
 
   // Since there may be multiple exits from the original region, make the new
   // function return an unsigned, switch on that number.  This loop iterates
@@ -453,8 +453,8 @@
         if (!NewTarget) {
           // If we don't already have an exit stub for this non-extracted
           // destination, create one now!
-          NewTarget = new BasicBlock(OldTarget->getName() + ".exitStub",
-                                     newFunction);
+          NewTarget = BasicBlock::Create(OldTarget->getName() + ".exitStub",
+                                         newFunction);
           unsigned SuccNum = switchVal++;
 
           Value *brVal = 0;
@@ -469,7 +469,7 @@
             break;
           }
 
-          ReturnInst *NTRet = new ReturnInst(brVal, NewTarget);
+          ReturnInst *NTRet = ReturnInst::Create(brVal, NewTarget);
 
           // Update the switch instruction.
           TheSwitch->addCase(ConstantInt::get(Type::Int16Ty, SuccNum),
@@ -513,9 +513,9 @@
                 Idx[0] = Constant::getNullValue(Type::Int32Ty);
                 Idx[1] = ConstantInt::get(Type::Int32Ty,FirstOut+out);
                 GetElementPtrInst *GEP =
-                  new GetElementPtrInst(OAI, Idx, Idx + 2,
-                                        "gep_" + outputs[out]->getName(),
-                                        NTRet);
+                  GetElementPtrInst::Create(OAI, Idx, Idx + 2,
+                                            "gep_" + outputs[out]->getName(),
+                                            NTRet);
                 new StoreInst(outputs[out], GEP, NTRet);
               } else {
                 new StoreInst(outputs[out], OAI, NTRet);
@@ -541,14 +541,14 @@
 
     // Check if the function should return a value
     if (OldFnRetTy == Type::VoidTy) {
-      new ReturnInst(0, TheSwitch);  // Return void
+      ReturnInst::Create(0, TheSwitch);  // Return void
     } else if (OldFnRetTy == TheSwitch->getCondition()->getType()) {
       // return what we have
-      new ReturnInst(TheSwitch->getCondition(), TheSwitch);
+      ReturnInst::Create(TheSwitch->getCondition(), TheSwitch);
     } else {
       // Otherwise we must have code extracted an unwind or something, just
       // return whatever we want.
-      new ReturnInst(Constant::getNullValue(OldFnRetTy), TheSwitch);
+      ReturnInst::Create(Constant::getNullValue(OldFnRetTy), TheSwitch);
     }
 
     TheSwitch->getParent()->getInstList().erase(TheSwitch);
@@ -556,12 +556,12 @@
   case 1:
     // Only a single destination, change the switch into an unconditional
     // branch.
-    new BranchInst(TheSwitch->getSuccessor(1), TheSwitch);
+    BranchInst::Create(TheSwitch->getSuccessor(1), TheSwitch);
     TheSwitch->getParent()->getInstList().erase(TheSwitch);
     break;
   case 2:
-    new BranchInst(TheSwitch->getSuccessor(1), TheSwitch->getSuccessor(2),
-                   call, TheSwitch);
+    BranchInst::Create(TheSwitch->getSuccessor(1), TheSwitch->getSuccessor(2),
+                       call, TheSwitch);
     TheSwitch->getParent()->getInstList().erase(TheSwitch);
     break;
   default:
@@ -641,12 +641,12 @@
   Function *oldFunction = header->getParent();
 
   // This takes place of the original loop
-  BasicBlock *codeReplacer = new BasicBlock("codeRepl", oldFunction, header);
+  BasicBlock *codeReplacer = BasicBlock::Create("codeRepl", oldFunction, header);
 
   // The new function needs a root node because other nodes can branch to the
   // head of the region, but the entry node of a function cannot have preds.
-  BasicBlock *newFuncRoot = new BasicBlock("newFuncRoot");
-  newFuncRoot->getInstList().push_back(new BranchInst(header));
+  BasicBlock *newFuncRoot = BasicBlock::Create("newFuncRoot");
+  newFuncRoot->getInstList().push_back(BranchInst::Create(header));
 
   // Find inputs to, outputs from the code region.
   findInputsOutputs(inputs, outputs);
diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp
index 74295ce..2e34984 100644
--- a/lib/Transforms/Utils/InlineFunction.cpp
+++ b/lib/Transforms/Utils/InlineFunction.cpp
@@ -84,9 +84,9 @@
           // of the old basic block.
           SmallVector<Value*, 8> InvokeArgs(CI->op_begin()+1, CI->op_end());
           InvokeInst *II =
-            new InvokeInst(CI->getCalledValue(), Split, InvokeDest,
-                           InvokeArgs.begin(), InvokeArgs.end(),
-                           CI->getName(), BB->getTerminator());
+            InvokeInst::Create(CI->getCalledValue(), Split, InvokeDest,
+                               InvokeArgs.begin(), InvokeArgs.end(),
+                               CI->getName(), BB->getTerminator());
           II->setCallingConv(CI->getCallingConv());
           II->setParamAttrs(CI->getParamAttrs());
           
@@ -116,7 +116,7 @@
         // invoke site.  Once this happens, we know that the unwind would cause
         // a control transfer to the invoke exception destination, so we can
         // transform it into a direct branch to the exception destination.
-        new BranchInst(InvokeDest, UI);
+        BranchInst::Create(InvokeDest, UI);
         
         // Delete the unwind instruction!
         UI->getParent()->getInstList().pop_back();
@@ -275,7 +275,7 @@
           DestCast, SrcCast, Size, ConstantInt::get(Type::Int32Ty, 1)
         };
         CallInst *TheMemCpy =
-          new CallInst(MemCpyFn, CallArgs, CallArgs+4, "", TheCall);
+          CallInst::Create(MemCpyFn, CallArgs, CallArgs+4, "", TheCall);
         
         // If we have a call graph, update it.
         if (CG) {
@@ -366,14 +366,14 @@
     }
       
     // Insert the llvm.stacksave.
-    CallInst *SavedPtr = new CallInst(StackSave, "savedstack", 
-                                      FirstNewBlock->begin());
+    CallInst *SavedPtr = CallInst::Create(StackSave, "savedstack", 
+                                          FirstNewBlock->begin());
     if (CG) CallerNode->addCalledFunction(SavedPtr, StackSaveCGN);
       
     // Insert a call to llvm.stackrestore before any return instructions in the
     // inlined function.
     for (unsigned i = 0, e = Returns.size(); i != e; ++i) {
-      CallInst *CI = new CallInst(StackRestore, SavedPtr, "", Returns[i]);
+      CallInst *CI = CallInst::Create(StackRestore, SavedPtr, "", Returns[i]);
       if (CG) CallerNode->addCalledFunction(CI, StackRestoreCGN);
     }
 
@@ -386,7 +386,7 @@
       for (Function::iterator BB = FirstNewBlock, E = Caller->end();
            BB != E; ++BB)
         if (UnwindInst *UI = dyn_cast<UnwindInst>(BB->getTerminator())) {
-          new CallInst(StackRestore, SavedPtr, "", UI);
+          CallInst::Create(StackRestore, SavedPtr, "", UI);
           ++NumStackRestores;
         }
     }
@@ -428,7 +428,7 @@
          BB != E; ++BB) {
       TerminatorInst *Term = BB->getTerminator();
       if (isa<UnwindInst>(Term)) {
-        new BranchInst(UnwindBB, Term);
+        BranchInst::Create(UnwindBB, Term);
         BB->getInstList().erase(Term);
       }
     }
@@ -452,7 +452,7 @@
     // If the call site was an invoke instruction, add a branch to the normal
     // destination.
     if (InvokeInst *II = dyn_cast<InvokeInst>(TheCall))
-      new BranchInst(II->getNormalDest(), TheCall);
+      BranchInst::Create(II->getNormalDest(), TheCall);
 
     // If the return instruction returned a value, replace uses of the call with
     // uses of the returned value.
@@ -489,7 +489,7 @@
   if (InvokeInst *II = dyn_cast<InvokeInst>(TheCall)) {
 
     // Add an unconditional branch to make this look like the CallInst case...
-    BranchInst *NewBr = new BranchInst(II->getNormalDest(), TheCall);
+    BranchInst *NewBr = BranchInst::Create(II->getNormalDest(), TheCall);
 
     // Split the basic block.  This guarantees that no PHI nodes will have to be
     // updated due to new incoming edges, and make the invoke case more
@@ -535,9 +535,9 @@
         // match corresponding return value operand number.
         Instruction *InsertPt = AfterCallBB->begin();
         for (unsigned i = 0; i < NumRetVals; ++i) {
-          PHINode *PHI = new PHINode(STy->getElementType(i),
-                                     TheCall->getName() + "." + utostr(i), 
-                                     InsertPt);
+            PHINode *PHI = PHINode::Create(STy->getElementType(i),
+                                           TheCall->getName() + "." + utostr(i), 
+                                           InsertPt);
           PHIs.push_back(PHI);
         }
         // TheCall results are used by GetResult instructions. 
@@ -547,7 +547,7 @@
           GR->eraseFromParent();
         }
       } else {
-        PHINode *PHI = new PHINode(RTy, TheCall->getName(), AfterCallBB->begin());
+        PHINode *PHI = PHINode::Create(RTy, TheCall->getName(), AfterCallBB->begin());
         PHIs.push_back(PHI);
         // Anything that used the result of the function call should now use the
         // PHI node as their operand.
@@ -578,7 +578,7 @@
     // Add a branch to the merge points and remove retrun instructions.
     for (unsigned i = 0, e = Returns.size(); i != e; ++i) {
       ReturnInst *RI = Returns[i];
-      new BranchInst(AfterCallBB, RI);
+      BranchInst::Create(AfterCallBB, RI);
       RI->eraseFromParent();
     }
   } else if (!Returns.empty()) {
diff --git a/lib/Transforms/Utils/LCSSA.cpp b/lib/Transforms/Utils/LCSSA.cpp
index 567b23e..a9d1dc4 100644
--- a/lib/Transforms/Utils/LCSSA.cpp
+++ b/lib/Transforms/Utils/LCSSA.cpp
@@ -155,8 +155,8 @@
     DomTreeNode *ExitBBNode = DT->getNode(BB);
     Value *&Phi = Phis[ExitBBNode];
     if (!Phi && DT->dominates(InstrNode, ExitBBNode)) {
-      PHINode *PN = new PHINode(Instr->getType(), Instr->getName()+".lcssa",
-                                BB->begin());
+      PHINode *PN = PHINode::Create(Instr->getType(), Instr->getName()+".lcssa",
+                                    BB->begin());
       PN->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB)));
 
       // Remember that this phi makes the value alive in this block.
@@ -259,8 +259,8 @@
   
   // Otherwise, the idom is the loop, so we need to insert a PHI node.  Do so
   // now, then get values to fill in the incoming values for the PHI.
-  PHINode *PN = new PHINode(OrigInst->getType(), OrigInst->getName()+".lcssa",
-                            BBN->begin());
+  PHINode *PN = PHINode::Create(OrigInst->getType(), OrigInst->getName()+".lcssa",
+                                BBN->begin());
   PN->reserveOperandSpace(std::distance(pred_begin(BBN), pred_end(BBN)));
   V = PN;
                                  
diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp
index 0d852bb..0f7d02c 100644
--- a/lib/Transforms/Utils/Local.cpp
+++ b/lib/Transforms/Utils/Local.cpp
@@ -134,7 +134,7 @@
     // now.
     if (TheOnlyDest) {
       // Insert the new branch..
-      new BranchInst(TheOnlyDest, SI);
+      BranchInst::Create(TheOnlyDest, SI);
       BasicBlock *BB = SI->getParent();
 
       // Remove entries from PHI nodes which we no longer branch to...
@@ -156,7 +156,7 @@
       Value *Cond = new ICmpInst(ICmpInst::ICMP_EQ, SI->getCondition(),
                                  SI->getSuccessorValue(1), "cond", SI);
       // Insert the new branch...
-      new BranchInst(SI->getSuccessor(1), SI->getSuccessor(0), Cond, SI);
+      BranchInst::Create(SI->getSuccessor(1), SI->getSuccessor(0), Cond, SI);
 
       // Delete the old switch...
       SI->getParent()->getInstList().erase(SI);
diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp
index 16cb30c..e6f5e7c 100644
--- a/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/lib/Transforms/Utils/LoopSimplify.cpp
@@ -270,10 +270,10 @@
                                        const std::vector<BasicBlock*> &Preds) {
 
   // Create new basic block, insert right before the original block...
-  BasicBlock *NewBB = new BasicBlock(BB->getName()+Suffix, BB->getParent(), BB);
+  BasicBlock *NewBB = BasicBlock::Create(BB->getName()+Suffix, BB->getParent(), BB);
 
   // The preheader first gets an unconditional branch to the loop header...
-  BranchInst *BI = new BranchInst(BB, NewBB);
+  BranchInst *BI = BranchInst::Create(BB, NewBB);
 
   // For every PHI node in the block, insert a PHI node into NewBB where the
   // incoming values from the out of loop edges are moved to NewBB.  We have two
@@ -300,7 +300,7 @@
       // If the values coming into the block are not the same, we need a PHI.
       if (InVal == 0) {
         // Create the new PHI node, insert it into NewBB at the end of the block
-        PHINode *NewPHI = new PHINode(PN->getType(), PN->getName()+".ph", BI);
+        PHINode *NewPHI = PHINode::Create(PN->getType(), PN->getName()+".ph", BI);
         if (AA) AA->copyValue(PN, NewPHI);
 
         // Move all of the edges from blocks outside the loop to the new PHI
@@ -623,8 +623,8 @@
     if (*I != Preheader) BackedgeBlocks.push_back(*I);
 
   // Create and insert the new backedge block...
-  BasicBlock *BEBlock = new BasicBlock(Header->getName()+".backedge", F);
-  BranchInst *BETerminator = new BranchInst(Header, BEBlock);
+  BasicBlock *BEBlock = BasicBlock::Create(Header->getName()+".backedge", F);
+  BranchInst *BETerminator = BranchInst::Create(Header, BEBlock);
 
   // Move the new backedge block to right after the last backedge block.
   Function::iterator InsertPos = BackedgeBlocks.back(); ++InsertPos;
@@ -634,8 +634,8 @@
   // the backedge block which correspond to any PHI nodes in the header block.
   for (BasicBlock::iterator I = Header->begin(); isa<PHINode>(I); ++I) {
     PHINode *PN = cast<PHINode>(I);
-    PHINode *NewPN = new PHINode(PN->getType(), PN->getName()+".be",
-                                 BETerminator);
+    PHINode *NewPN = PHINode::Create(PN->getType(), PN->getName()+".be",
+                                     BETerminator);
     NewPN->reserveOperandSpace(BackedgeBlocks.size());
     if (AA) AA->copyValue(PN, NewPN);
 
diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp
index 2f42260..8708f99 100644
--- a/lib/Transforms/Utils/LowerAllocations.cpp
+++ b/lib/Transforms/Utils/LowerAllocations.cpp
@@ -141,7 +141,7 @@
       }
 
       // Create the call to Malloc.
-      CallInst *MCall = new CallInst(MallocFunc, MallocArg, "", I);
+      CallInst *MCall = CallInst::Create(MallocFunc, MallocArg, "", I);
       MCall->setTailCall();
 
       // Create a cast instruction to convert to the right type...
@@ -162,7 +162,7 @@
                         PointerType::getUnqual(Type::Int8Ty), "", I);
 
       // Insert a call to the free function...
-      (new CallInst(FreeFunc, PtrCast, "", I))->setTailCall();
+      CallInst::Create(FreeFunc, PtrCast, "", I)->setTailCall();
 
       // Delete the old free instruction
       I = --BBIL.erase(I);
diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp
index 7f0ef85..7f85b10 100644
--- a/lib/Transforms/Utils/LowerInvoke.cpp
+++ b/lib/Transforms/Utils/LowerInvoke.cpp
@@ -211,15 +211,15 @@
     if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) {
       std::vector<Value*> CallArgs(II->op_begin()+3, II->op_end());
       // Insert a normal call instruction...
-      CallInst *NewCall = new CallInst(II->getCalledValue(),
-                                       CallArgs.begin(), CallArgs.end(), "",II);
+      CallInst *NewCall = CallInst::Create(II->getCalledValue(),
+                                           CallArgs.begin(), CallArgs.end(), "",II);
       NewCall->takeName(II);
       NewCall->setCallingConv(II->getCallingConv());
       NewCall->setParamAttrs(II->getParamAttrs());
       II->replaceAllUsesWith(NewCall);
 
       // Insert an unconditional branch to the normal destination.
-      new BranchInst(II->getNormalDest(), II);
+      BranchInst::Create(II->getNormalDest(), II);
 
       // Remove any PHI node entries from the exception destination.
       II->getUnwindDest()->removePredecessor(BB);
@@ -233,12 +233,12 @@
       writeAbortMessage(UI);
 
       // Insert a call to abort()
-      (new CallInst(AbortFn, "", UI))->setTailCall();
+      CallInst::Create(AbortFn, "", UI)->setTailCall();
 
       // Insert a return instruction.  This really should be a "barrier", as it
       // is unreachable.
-      new ReturnInst(F.getReturnType() == Type::VoidTy ? 0 :
-                            Constant::getNullValue(F.getReturnType()), UI);
+      ReturnInst::Create(F.getReturnType() == Type::VoidTy ? 0 :
+                         Constant::getNullValue(F.getReturnType()), UI);
 
       // Remove the unwind instruction now.
       BB->getInstList().erase(UI);
@@ -280,16 +280,16 @@
   
   // Insert a normal call instruction.
   std::vector<Value*> CallArgs(II->op_begin()+3, II->op_end());
-  CallInst *NewCall = new CallInst(II->getCalledValue(),
-                                   CallArgs.begin(), CallArgs.end(), "",
-                                   II);
+  CallInst *NewCall = CallInst::Create(II->getCalledValue(),
+                                       CallArgs.begin(), CallArgs.end(), "",
+                                       II);
   NewCall->takeName(II);
   NewCall->setCallingConv(II->getCallingConv());
   NewCall->setParamAttrs(II->getParamAttrs());
   II->replaceAllUsesWith(NewCall);
   
   // Replace the invoke with an uncond branch.
-  new BranchInst(II->getNormalDest(), NewCall->getParent());
+  BranchInst::Create(II->getNormalDest(), NewCall->getParent());
   II->eraseFromParent();
 }
 
@@ -463,8 +463,8 @@
     std::vector<Value*> Idx;
     Idx.push_back(Constant::getNullValue(Type::Int32Ty));
     Idx.push_back(ConstantInt::get(Type::Int32Ty, 1));
-    OldJmpBufPtr = new GetElementPtrInst(JmpBuf, Idx.begin(), Idx.end(),
-                                         "OldBuf", EntryBB->getTerminator());
+    OldJmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(),
+                                             "OldBuf", EntryBB->getTerminator());
 
     // Copy the JBListHead to the alloca.
     Value *OldBuf = new LoadInst(JBListHead, "oldjmpbufptr", true,
@@ -476,7 +476,7 @@
 
     // Create the catch block.  The catch block is basically a big switch
     // statement that goes to all of the invoke catch blocks.
-    BasicBlock *CatchBB = new BasicBlock("setjmp.catch", &F);
+    BasicBlock *CatchBB = BasicBlock::Create("setjmp.catch", &F);
     
     // Create an alloca which keeps track of which invoke is currently
     // executing.  For normal calls it contains zero.
@@ -488,12 +488,12 @@
     // Insert a load in the Catch block, and a switch on its value.  By default,
     // we go to a block that just does an unwind (which is the correct action
     // for a standard call).
-    BasicBlock *UnwindBB = new BasicBlock("unwindbb", &F);
+    BasicBlock *UnwindBB = BasicBlock::Create("unwindbb", &F);
     Unwinds.push_back(new UnwindInst(UnwindBB));
     
     Value *CatchLoad = new LoadInst(InvokeNum, "invoke.num", true, CatchBB);
-    SwitchInst *CatchSwitch = 
-      new SwitchInst(CatchLoad, UnwindBB, Invokes.size(), CatchBB);
+    SwitchInst *CatchSwitch =
+      SwitchInst::Create(CatchLoad, UnwindBB, Invokes.size(), CatchBB);
 
     // Now that things are set up, insert the setjmp call itself.
     
@@ -502,11 +502,11 @@
                                                      "setjmp.cont");
 
     Idx[1] = ConstantInt::get(Type::Int32Ty, 0);
-    Value *JmpBufPtr = new GetElementPtrInst(JmpBuf, Idx.begin(), Idx.end(),
-                                             "TheJmpBuf",
-                                             EntryBB->getTerminator());
-    Value *SJRet = new CallInst(SetJmpFn, JmpBufPtr, "sjret",
-                                EntryBB->getTerminator());
+    Value *JmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(),
+                                                 "TheJmpBuf",
+                                                 EntryBB->getTerminator());
+    Value *SJRet = CallInst::Create(SetJmpFn, JmpBufPtr, "sjret",
+                                    EntryBB->getTerminator());
     
     // Compare the return value to zero.
     Value *IsNormal = new ICmpInst(ICmpInst::ICMP_EQ, SJRet, 
@@ -516,7 +516,7 @@
     EntryBB->getTerminator()->eraseFromParent();
     
     // Put in a new condbranch in its place.
-    new BranchInst(ContBlock, CatchBB, IsNormal, EntryBB);
+    BranchInst::Create(ContBlock, CatchBB, IsNormal, EntryBB);
 
     // At this point, we are all set up, rewrite each invoke instruction.
     for (unsigned i = 0, e = Invokes.size(); i != e; ++i)
@@ -528,9 +528,9 @@
   // Create three new blocks, the block to load the jmpbuf ptr and compare
   // against null, the block to do the longjmp, and the error block for if it
   // is null.  Add them at the end of the function because they are not hot.
-  BasicBlock *UnwindHandler = new BasicBlock("dounwind", &F);
-  BasicBlock *UnwindBlock = new BasicBlock("unwind", &F);
-  BasicBlock *TermBlock = new BasicBlock("unwinderror", &F);
+  BasicBlock *UnwindHandler = BasicBlock::Create("dounwind", &F);
+  BasicBlock *UnwindBlock = BasicBlock::Create("unwind", &F);
+  BasicBlock *TermBlock = BasicBlock::Create("unwinderror", &F);
 
   // If this function contains an invoke, restore the old jumpbuf ptr.
   Value *BufPtr;
@@ -546,17 +546,17 @@
   Value *NotNull = new ICmpInst(ICmpInst::ICMP_NE, BufPtr, 
                                 Constant::getNullValue(BufPtr->getType()),
     "notnull", UnwindHandler);
-  new BranchInst(UnwindBlock, TermBlock, NotNull, UnwindHandler);
+  BranchInst::Create(UnwindBlock, TermBlock, NotNull, UnwindHandler);
   
   // Create the block to do the longjmp.
   // Get a pointer to the jmpbuf and longjmp.
   std::vector<Value*> Idx;
   Idx.push_back(Constant::getNullValue(Type::Int32Ty));
   Idx.push_back(ConstantInt::get(Type::Int32Ty, 0));
-  Idx[0] = new GetElementPtrInst(BufPtr, Idx.begin(), Idx.end(), "JmpBuf",
-                                 UnwindBlock);
+  Idx[0] = GetElementPtrInst::Create(BufPtr, Idx.begin(), Idx.end(), "JmpBuf",
+                                     UnwindBlock);
   Idx[1] = ConstantInt::get(Type::Int32Ty, 1);
-  new CallInst(LongJmpFn, Idx.begin(), Idx.end(), "", UnwindBlock);
+  CallInst::Create(LongJmpFn, Idx.begin(), Idx.end(), "", UnwindBlock);
   new UnreachableInst(UnwindBlock);
   
   // Set up the term block ("throw without a catch").
@@ -566,13 +566,13 @@
   writeAbortMessage(TermBlock->getTerminator());
   
   // Insert a call to abort()
-  (new CallInst(AbortFn, "",
-                TermBlock->getTerminator()))->setTailCall();
+  CallInst::Create(AbortFn, "",
+                   TermBlock->getTerminator())->setTailCall();
     
   
   // Replace all unwinds with a branch to the unwind handler.
   for (unsigned i = 0, e = Unwinds.size(); i != e; ++i) {
-    new BranchInst(UnwindHandler, Unwinds[i]);
+    BranchInst::Create(UnwindHandler, Unwinds[i]);
     Unwinds[i]->eraseFromParent();    
   } 
   
diff --git a/lib/Transforms/Utils/LowerSwitch.cpp b/lib/Transforms/Utils/LowerSwitch.cpp
index e31a87f..d75880f 100644
--- a/lib/Transforms/Utils/LowerSwitch.cpp
+++ b/lib/Transforms/Utils/LowerSwitch.cpp
@@ -158,13 +158,13 @@
   // Create a new node that checks if the value is < pivot. Go to the
   // left branch if it is and right branch if not.
   Function* F = OrigBlock->getParent();
-  BasicBlock* NewNode = new BasicBlock("NodeBlock");
+  BasicBlock* NewNode = BasicBlock::Create("NodeBlock");
   Function::iterator FI = OrigBlock;
   F->getBasicBlockList().insert(++FI, NewNode);
 
   ICmpInst* Comp = new ICmpInst(ICmpInst::ICMP_SLT, Val, Pivot.Low, "Pivot");
   NewNode->getInstList().push_back(Comp);
-  new BranchInst(LBranch, RBranch, Comp, NewNode);
+  BranchInst::Create(LBranch, RBranch, Comp, NewNode);
   return NewNode;
 }
 
@@ -179,7 +179,7 @@
                                       BasicBlock* Default)
 {
   Function* F = OrigBlock->getParent();
-  BasicBlock* NewLeaf = new BasicBlock("LeafBlock");
+  BasicBlock* NewLeaf = BasicBlock::Create("LeafBlock");
   Function::iterator FI = OrigBlock;
   F->getBasicBlockList().insert(++FI, NewLeaf);
 
@@ -213,7 +213,7 @@
 
   // Make the conditional branch...
   BasicBlock* Succ = Leaf.BB;
-  new BranchInst(Succ, Default, Comp, NewLeaf);
+  BranchInst::Create(Succ, Default, Comp, NewLeaf);
 
   // If there were any PHI nodes in this successor, rewrite one entry
   // from OrigBlock to come from NewLeaf.
@@ -284,17 +284,17 @@
 
   // If there is only the default destination, don't bother with the code below.
   if (SI->getNumOperands() == 2) {
-    new BranchInst(SI->getDefaultDest(), CurBlock);
+    BranchInst::Create(SI->getDefaultDest(), CurBlock);
     CurBlock->getInstList().erase(SI);
     return;
   }
 
   // Create a new, empty default block so that the new hierarchy of
   // if-then statements go to this and the PHI nodes are happy.
-  BasicBlock* NewDefault = new BasicBlock("NewDefault");
+  BasicBlock* NewDefault = BasicBlock::Create("NewDefault");
   F->getBasicBlockList().insert(Default, NewDefault);
 
-  new BranchInst(Default, NewDefault);
+  BranchInst::Create(Default, NewDefault);
 
   // If there is an entry in any PHI nodes for the default edge, make sure
   // to update them as well.
@@ -317,7 +317,7 @@
                                           OrigBlock, NewDefault);
 
   // Branch to our shiny new if-then stuff...
-  new BranchInst(SwitchBlock, OrigBlock);
+  BranchInst::Create(SwitchBlock, OrigBlock);
 
   // We are now done with the switch instruction, delete it.
   CurBlock->getInstList().erase(SI);
diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index 3d25dee..ebd68dd 100644
--- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -834,9 +834,9 @@
 
   // Create a PhiNode using the dereferenced type... and add the phi-node to the
   // BasicBlock.
-  PN = new PHINode(Allocas[AllocaNo]->getAllocatedType(),
-                   Allocas[AllocaNo]->getName() + "." +
-                   utostr(Version++), BB->begin());
+  PN = PHINode::Create(Allocas[AllocaNo]->getAllocatedType(),
+                       Allocas[AllocaNo]->getName() + "." +
+                       utostr(Version++), BB->begin());
   ++NumPHIInsert;
   PhiToAllocaMap[PN] = AllocaNo;
   PN->reserveOperandSpace(getNumPreds(BB));
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index b9a20c1..d11bbb0 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -619,7 +619,7 @@
         assert(ThisCases.size() == 1 && "Branch can only have one case!");
         Value *Cond = BTI->getCondition();
         // Insert the new branch.
-        Instruction *NI = new BranchInst(ThisDef, TI);
+        Instruction *NI = BranchInst::Create(ThisDef, TI);
 
         // Remove PHI node entries for the dead edge.
         ThisCases[0].second->removePredecessor(TI->getParent());
@@ -689,7 +689,7 @@
         CheckEdge = 0;
 
     // Insert the new branch.
-    Instruction *NI = new BranchInst(TheRealDest, TI);
+    Instruction *NI = BranchInst::Create(TheRealDest, TI);
 
     DOUT << "Threading pred instr: " << *Pred->getTerminator()
          << "Through successor TI: " << *TI << "Leaving: " << *NI << "\n";
@@ -802,7 +802,7 @@
         AddPredecessorToBlock(NewSuccessors[i], Pred, BB);
 
       // Now that the successors are updated, create the new Switch instruction.
-      SwitchInst *NewSI = new SwitchInst(CV, PredDefault, PredCases.size(),PTI);
+      SwitchInst *NewSI = SwitchInst::Create(CV, PredDefault, PredCases.size(), PTI);
       for (unsigned i = 0, e = PredCases.size(); i != e; ++i)
         NewSI->addCase(PredCases[i].first, PredCases[i].second);
 
@@ -824,8 +824,8 @@
           if (InfLoopBlock == 0) {
             // Insert it at the end of the loop, because it's either code,
             // or it won't matter if it's hot. :)
-            InfLoopBlock = new BasicBlock("infloop", BB->getParent());
-            new BranchInst(InfLoopBlock, InfLoopBlock);
+            InfLoopBlock = BasicBlock::Create("infloop", BB->getParent());
+            BranchInst::Create(InfLoopBlock, InfLoopBlock);
           }
           NewSI->setSuccessor(i, InfLoopBlock);
         }
@@ -902,8 +902,8 @@
         // that determines the right value.
         SelectInst *&SI = InsertedSelects[std::make_pair(BB1V, BB2V)];
         if (SI == 0)
-          SI = new SelectInst(BI->getCondition(), BB1V, BB2V,
-                              BB1V->getName()+"."+BB2V->getName(), NT);
+          SI = SelectInst::Create(BI->getCondition(), BB1V, BB2V,
+                                  BB1V->getName()+"."+BB2V->getName(), NT);
         // Make the PHI node use the select for all incoming values for BB1/BB2
         for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
           if (PN->getIncomingBlock(i) == BB1 || PN->getIncomingBlock(i) == BB2)
@@ -987,9 +987,9 @@
       // difficult cases.  Instead of being smart about this, just insert a new
       // block that jumps to the destination block, effectively splitting
       // the edge we are about to create.
-      BasicBlock *EdgeBB = new BasicBlock(RealDest->getName()+".critedge",
-                                          RealDest->getParent(), RealDest);
-      new BranchInst(RealDest, EdgeBB);
+      BasicBlock *EdgeBB = BasicBlock::Create(RealDest->getName()+".critedge",
+                                              RealDest->getParent(), RealDest);
+      BranchInst::Create(RealDest, EdgeBB);
       PHINode *PN;
       for (BasicBlock::iterator BBI = RealDest->begin();
            (PN = dyn_cast<PHINode>(BBI)); ++BBI) {
@@ -1156,7 +1156,7 @@
     Value *FalseVal =
       PN->getIncomingValue(PN->getIncomingBlock(0) == IfTrue);
     
-    Value *NV = new SelectInst(IfCond, TrueVal, FalseVal, "", AfterPHIIt);
+    Value *NV = SelectInst::Create(IfCond, TrueVal, FalseVal, "", AfterPHIIt);
     PN->replaceAllUsesWith(NV);
     NV->takeName(PN);
     
@@ -1307,7 +1307,7 @@
             if (RI->getNumOperands() == 0) {
               TrueSucc->removePredecessor(BI->getParent());
               FalseSucc->removePredecessor(BI->getParent());
-              new ReturnInst(0, BI);
+              ReturnInst::Create(0, BI);
               BI->getParent()->getInstList().erase(BI);
               return true;
             }
@@ -1341,8 +1341,8 @@
               Value *NewRetVal;
               Value *BrCond = BI->getCondition();
               if (TrueValue != FalseValue)
-                NewRetVal = new SelectInst(BrCond, TrueValue,
-                                           FalseValue, "retval", BI);
+                NewRetVal = SelectInst::Create(BrCond, TrueValue,
+                                               FalseValue, "retval", BI);
               else
                 NewRetVal = TrueValue;
               
@@ -1350,7 +1350,7 @@
                    << "\n  " << *BI << "Select = " << *NewRetVal
                    << "TRUEBLOCK: " << *TrueSucc << "FALSEBLOCK: "<< *FalseSucc;
 
-              new ReturnInst(NewRetVal, BI);
+              ReturnInst::Create(NewRetVal, BI);
               BI->eraseFromParent();
               if (Instruction *BrCondI = dyn_cast<Instruction>(BrCond))
                 if (isInstructionTriviallyDead(BrCondI))
@@ -1386,13 +1386,13 @@
         if (II->getUnwindDest() == BB) {
           // Insert a new branch instruction before the invoke, because this
           // is now a fall through...
-          BranchInst *BI = new BranchInst(II->getNormalDest(), II);
+          BranchInst *BI = BranchInst::Create(II->getNormalDest(), II);
           Pred->getInstList().remove(II);   // Take out of symbol table
 
           // Insert the call now...
           SmallVector<Value*,8> Args(II->op_begin()+3, II->op_end());
-          CallInst *CI = new CallInst(II->getCalledValue(),
-                                      Args.begin(), Args.end(), II->getName(), BI);
+          CallInst *CI = CallInst::Create(II->getCalledValue(),
+                                          Args.begin(), Args.end(), II->getName(), BI);
           CI->setCallingConv(II->getCallingConv());
           CI->setParamAttrs(II->getParamAttrs());
           // If the invoke produced a value, the Call now does instead
@@ -1540,9 +1540,9 @@
               // Otherwise, if there are multiple predecessors, insert a PHI 
               // that merges in the constant and simplify the block result.
               if (BlockIsSimpleEnoughToThreadThrough(BB)) {
-                PHINode *NewPN = new PHINode(Type::Int1Ty,
-                                            BI->getCondition()->getName()+".pr",
-                                            BB->begin());
+                PHINode *NewPN = PHINode::Create(Type::Int1Ty,
+                                                 BI->getCondition()->getName()+".pr",
+                                                 BB->begin());
                 for (PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
                   if ((PBI = dyn_cast<BranchInst>((*PI)->getTerminator())) &&
                       PBI != BI && PBI->isConditional() &&
@@ -1661,8 +1661,8 @@
                   Value *PBIV = PN->getIncomingValue(PBBIdx);
                   if (BIV != PBIV) {
                     // Insert a select in PBI to pick the right value.
-                    Value *NV = new SelectInst(PBICond, PBIV, BIV,
-                                               PBIV->getName()+".mux", PBI);
+                    Value *NV = SelectInst::Create(PBICond, PBIV, BIV,
+                                                   PBIV->getName()+".mux", PBI);
                     PN->setIncomingValue(PBBIdx, NV);
                   }
                 }
@@ -1705,10 +1705,10 @@
             }
           } else {
             if (BI->getSuccessor(0) == BB) {
-              new BranchInst(BI->getSuccessor(1), BI);
+              BranchInst::Create(BI->getSuccessor(1), BI);
               BI->eraseFromParent();
             } else if (BI->getSuccessor(1) == BB) {
-              new BranchInst(BI->getSuccessor(0), BI);
+              BranchInst::Create(BI->getSuccessor(0), BI);
               BI->eraseFromParent();
               Changed = true;
             }
@@ -1761,14 +1761,14 @@
           if (II->getUnwindDest() == BB) {
             // Convert the invoke to a call instruction.  This would be a good
             // place to note that the call does not throw though.
-            BranchInst *BI = new BranchInst(II->getNormalDest(), II);
+            BranchInst *BI = BranchInst::Create(II->getNormalDest(), II);
             II->removeFromParent();   // Take out of symbol table
 
             // Insert the call now...
             SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end());
-            CallInst *CI = new CallInst(II->getCalledValue(),
-                                        Args.begin(), Args.end(),
-                                        II->getName(), BI);
+            CallInst *CI = CallInst::Create(II->getCalledValue(),
+                                            Args.begin(), Args.end(),
+                                            II->getName(), BI);
             CI->setCallingConv(II->getCallingConv());
             CI->setParamAttrs(II->getParamAttrs());
             // If the invoke produced a value, the Call does now instead.
@@ -1894,7 +1894,7 @@
           if (!TrueWhenEqual) std::swap(DefaultBB, EdgeBB);
 
           // Create the new switch instruction now.
-          SwitchInst *New = new SwitchInst(CompVal, DefaultBB,Values.size(),BI);
+          SwitchInst *New = SwitchInst::Create(CompVal, DefaultBB,Values.size(),BI);
 
           // Add all of the 'cases' to the switch instruction.
           for (unsigned i = 0, e = Values.size(); i != e; ++i)
diff --git a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
index 9f129a8..76b565c 100644
--- a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
+++ b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
@@ -69,14 +69,14 @@
   } else if (UnwindingBlocks.size() == 1) {
     UnwindBlock = UnwindingBlocks.front();
   } else {
-    UnwindBlock = new BasicBlock("UnifiedUnwindBlock", &F);
+    UnwindBlock = BasicBlock::Create("UnifiedUnwindBlock", &F);
     new UnwindInst(UnwindBlock);
 
     for (std::vector<BasicBlock*>::iterator I = UnwindingBlocks.begin(),
            E = UnwindingBlocks.end(); I != E; ++I) {
       BasicBlock *BB = *I;
       BB->getInstList().pop_back();  // Remove the unwind insn
-      new BranchInst(UnwindBlock, BB);
+      BranchInst::Create(UnwindBlock, BB);
     }
   }
 
@@ -86,14 +86,14 @@
   } else if (UnreachableBlocks.size() == 1) {
     UnreachableBlock = UnreachableBlocks.front();
   } else {
-    UnreachableBlock = new BasicBlock("UnifiedUnreachableBlock", &F);
+    UnreachableBlock = BasicBlock::Create("UnifiedUnreachableBlock", &F);
     new UnreachableInst(UnreachableBlock);
 
     for (std::vector<BasicBlock*>::iterator I = UnreachableBlocks.begin(),
            E = UnreachableBlocks.end(); I != E; ++I) {
       BasicBlock *BB = *I;
       BB->getInstList().pop_back();  // Remove the unreachable inst.
-      new BranchInst(UnreachableBlock, BB);
+      BranchInst::Create(UnreachableBlock, BB);
     }
   }
 
@@ -110,27 +110,27 @@
   // nodes (if the function returns values), and convert all of the return
   // instructions into unconditional branches.
   //
-  BasicBlock *NewRetBlock = new BasicBlock("UnifiedReturnBlock", &F);
+  BasicBlock *NewRetBlock = BasicBlock::Create("UnifiedReturnBlock", &F);
 
   SmallVector<Value *, 4> Phis;
   unsigned NumRetVals = ReturningBlocks[0]->getTerminator()->getNumOperands();
   if (NumRetVals == 0)
-    new ReturnInst(NULL, NewRetBlock);
+    ReturnInst::Create(NULL, NewRetBlock);
   else if (const StructType *STy = dyn_cast<StructType>(F.getReturnType())) {
     Instruction *InsertPt = NewRetBlock->getFirstNonPHI();
     for (unsigned i = 0; i < NumRetVals; ++i) {
-      PHINode *PN = new PHINode(STy->getElementType(i), "UnifiedRetVal." 
-                                + utostr(i), InsertPt);
+      PHINode *PN = PHINode::Create(STy->getElementType(i), "UnifiedRetVal." 
+                                    + utostr(i), InsertPt);
       Phis.push_back(PN);
     }
-    new ReturnInst(&Phis[0], NumRetVals);
+    ReturnInst::Create(&Phis[0], NumRetVals);
   }
   else {
     // If the function doesn't return void... add a PHI node to the block...
-    PHINode *PN = new PHINode(F.getReturnType(), "UnifiedRetVal");
+    PHINode *PN = PHINode::Create(F.getReturnType(), "UnifiedRetVal");
     NewRetBlock->getInstList().push_back(PN);
     Phis.push_back(PN);
-    new ReturnInst(PN, NewRetBlock);
+    ReturnInst::Create(PN, NewRetBlock);
   }
 
   // Loop over all of the blocks, replacing the return instruction with an
@@ -149,7 +149,7 @@
     }
 
     BB->getInstList().pop_back();  // Remove the return insn
-    new BranchInst(NewRetBlock, BB);
+    BranchInst::Create(NewRetBlock, BB);
   }
   ReturnBlock = NewRetBlock;
   return true;