// The basic block we're going to jump to if we need to rethrow the
// exception.
BasicBlock* Rethrow = new BasicBlock("RethrowExcept", Func);
- BasicBlock::InstListType& RethrowBlkIL = Rethrow->getInstList();
// Fill in the "Rethrow" BB with a call to rethrow the exception. This
// is the last instruction in the BB since at this point the runtime
// should exit this function and go to the next function.
- RethrowBlkIL.push_back(new UnwindInst());
+ new UnwindInst(Rethrow);
return RethrowBBMap[Func] = Rethrow;
}
BasicBlock* DecisionBB = new BasicBlock("LJDecisionBB", Func);
BasicBlock::InstListType& DecisionBBIL = DecisionBB->getInstList();
- LongJmpPreIL.push_back(new BranchInst(DecisionBB, Rethrow, Cond));
+ new BranchInst(DecisionBB, Rethrow, Cond, LongJmpPre);
// Fill in the "decision" basic block.
CallInst* LJVal = new CallInst(GetLJValue, std::vector<Value*>(), "LJVal");
CallInst(TryCatchLJ, make_vector<Value*>(GetSetJmpMap(Func), 0), "SJNum");
DecisionBBIL.push_back(SJNum);
- SwitchInst* SI = new SwitchInst(SJNum, Rethrow);
- DecisionBBIL.push_back(SI);
+ SwitchInst* SI = new SwitchInst(SJNum, Rethrow, DecisionBB);
return SwitchValMap[Func] = SwitchValuePair(SI, LJVal);
}
CallInst(IsLJException, std::vector<Value*>(), "IsLJExcept");
InstList.push_back(IsLJExcept);
- BranchInst* BR = new BranchInst(PrelimBBMap[Func], ExceptBB, IsLJExcept);
- InstList.push_back(BR);
+ new BranchInst(PrelimBBMap[Func], ExceptBB, IsLJExcept, NewExceptBB);
II.setExceptionalDest(NewExceptBB);
++InvokesTransformed;
sameTarget.push_back(MI->first);
BasicBlock *newBB = new BasicBlock("newCommon", MI->first->getParent());
- BranchInst *newBranch = new BranchInst(MI->second);
-
- newBB->getInstList().push_back(newBranch);
+ BranchInst *newBranch = new BranchInst(MI->second, 0, 0, newBB);
std::map<PHINode *, std::vector<unsigned int> > phiMap;
newBB->getInstList().push_back(newBI2);
//triggerBB->getInstList().push_back(triggerInst);
- Instruction *triggerBranch = new BranchInst(BB2);
- triggerBB->getInstList().push_back(triggerBranch);
+ new BranchInst(BB2, 0, 0, triggerBB);
}
else{
- Instruction *newBI2=new BranchInst(BB2);
- newBB->getInstList().push_back(newBI2);
+ new BranchInst(BB2, 0, 0, newBB);
}
//now iterate over BB2, and set its Phi nodes right
ti->setSuccessor(index, newBB);
BasicBlock::InstListType < = newBB->getInstList();
-
- Instruction *call = new CallInst(inCountMth);
- lt.push_back(call);
- lt.push_back(new BranchInst(BB));
+ lt.push_back(new CallInst(inCountMth));
+ new BranchInst(BB, newBB);
//now iterate over *vl, and set its Phi nodes right
for(BasicBlock::iterator BB2Inst = BB->begin(), BBend = BB->end();
//
if (!AliveBlocks.count(&Func->front())) {
BasicBlock *NewEntry = new BasicBlock();
- NewEntry->getInstList().push_back(new BranchInst(&Func->front()));
+ new BranchInst(&Func->front(), 0, 0, NewEntry);
Func->getBasicBlockList().push_front(NewEntry);
AliveBlocks.insert(NewEntry); // This block is always alive!
LiveSet.insert(NewEntry->getTerminator()); // The branch is live
// Delete the old terminator instruction...
BB->getInstList().pop_back();
const Type *RetTy = Func->getReturnType();
- BB->getInstList().push_back(new ReturnInst(RetTy != Type::VoidTy ?
- Constant::getNullValue(RetTy) : 0));
+ new ReturnInst(RetTy != Type::VoidTy ?
+ Constant::getNullValue(RetTy) : 0, BB);
}
}
#include "llvm/Pass.h"
#include "Support/Statistic.h"
-namespace llvm {
+using namespace llvm;
namespace {
Statistic<> NumEliminated("tailcallelim", "Number of tail calls removed");
}
// Public interface to the TailCallElimination pass
-FunctionPass *createTailCallEliminationPass() { return new TailCallElim(); }
+FunctionPass *llvm::createTailCallEliminationPass() {
+ return new TailCallElim();
+}
bool TailCallElim::runOnFunction(Function &F) {
// us to branch back to the old entry block.
OldEntry = &F.getEntryBlock();
BasicBlock *NewEntry = new BasicBlock("tailrecurse", OldEntry);
- NewEntry->getInstList().push_back(new BranchInst(OldEntry));
+ new BranchInst(OldEntry, 0, 0, NewEntry);
// Now that we have created a new block, which jumps to the entry
// block, insert a PHI node for each argument of the function.
return MadeChange;
}
-
-} // End llvm namespace
BasicBlock *NewBB = new BasicBlock(TIBB->getName() + "." +
DestBB->getName() + "_crit_edge");
// Create our unconditional branch...
- BranchInst *BI = new BranchInst(DestBB);
- NewBB->getInstList().push_back(BI);
+ new BranchInst(DestBB, 0, 0, NewBB);
// Branch to the new block, breaking the edge...
TI->setSuccessor(SuccNum, NewBB);
// 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.
- BranchInst *BI = new BranchInst(InvokeDest, UI);
+ new BranchInst(InvokeDest, UI);
// Delete the unwind instruction!
UI->getParent()->getInstList().pop_back();
BasicBlock *NewBB = new BasicBlock(BB->getName()+Suffix, BB);
// The preheader first gets an unconditional branch to the loop header...
- BranchInst *BI = new BranchInst(BB);
- NewBB->getInstList().push_back(BI);
+ BranchInst *BI = new BranchInst(BB, 0, 0, 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
// Create and insert the new backedge block...
BasicBlock *BEBlock = new BasicBlock(Header->getName()+".backedge", F);
- Instruction *BETerminator = new BranchInst(Header);
- BEBlock->getInstList().push_back(BETerminator);
+ BranchInst *BETerminator = new BranchInst(Header, 0, 0, BEBlock);
// Move the new backedge block to right after the last backedge block.
Function::iterator InsertPos = BackedgeBlocks.back(); ++InsertPos;
SetCondInst* Comp = new SetCondInst(Instruction::SetLT, Val, Pivot.first,
"Pivot");
NewNode->getInstList().push_back(Comp);
- BranchInst* Br = new BranchInst(LBranch, RBranch, Comp);
- NewNode->getInstList().push_back(Br);
+ new BranchInst(LBranch, RBranch, Comp, NewNode);
return NewNode;
}
// Make the conditional branch...
BasicBlock* Succ = Leaf.second;
- Instruction* Br = new BranchInst(Succ, Default, Comp);
- NewLeaf->getInstList().push_back(Br);
+ new BranchInst(Succ, Default, Comp, NewLeaf);
// If there were any PHI nodes in this successor, rewrite one entry
// from OrigBlock to come from NewLeaf.
// If there is only the default destination, don't bother with the code below.
if (SI->getNumOperands() == 2) {
- CurBlock->getInstList().push_back(new BranchInst(SI->getDefaultDest()));
+ new BranchInst(SI->getDefaultDest(), 0, 0, CurBlock);
delete SI;
return;
}
BasicBlock* NewDefault = new BasicBlock("NewDefault");
F->getBasicBlockList().insert(Default, NewDefault);
- NewDefault->getInstList().push_back(new BranchInst(Default));
+ new BranchInst(Default, 0, 0, NewDefault);
// If there is an entry in any PHI nodes for the default edge, make sure
// to update them as well.
OrigBlock, NewDefault);
// Branch to our shiny new if-then stuff...
- OrigBlock->getInstList().push_back(new BranchInst(SwitchBlock));
+ new BranchInst(SwitchBlock, 0, 0, OrigBlock);
// We are now done with the switch instruction, delete it.
delete SI;
UnwindBlock = UnwindingBlocks.front();
} else {
UnwindBlock = new BasicBlock("UnifiedUnwindBlock", &F);
- UnwindBlock->getInstList().push_back(new UnwindInst());
+ 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 return insn
- BB->getInstList().push_back(new BranchInst(UnwindBlock));
+ new BranchInst(UnwindBlock, 0, 0, BB);
}
}
// If the function doesn't return void... add a PHI node to the block...
PN = new PHINode(F.getReturnType(), "UnifiedRetVal");
NewRetBlock->getInstList().push_back(PN);
- NewRetBlock->getInstList().push_back(new ReturnInst(PN));
+ new ReturnInst(PN, NewRetBlock);
} else {
// If it returns void, just add a return void instruction to the block
- NewRetBlock->getInstList().push_back(new ReturnInst());
+ new ReturnInst(0, NewRetBlock);
}
// Loop over all of the blocks, replacing the return instruction with an
if (PN) PN->addIncoming(BB->getTerminator()->getOperand(0), BB);
BB->getInstList().pop_back(); // Remove the return insn
- BB->getInstList().push_back(new BranchInst(NewRetBlock));
+ new BranchInst(NewRetBlock, 0, 0, BB);
}
ReturnBlock = NewRetBlock;
return true;
} while (Inst != &*I); // Loop until we move the specified instruction.
// Add a branch instruction to the newly formed basic block.
- InstList.push_back(new BranchInst(New));
+ new BranchInst(New, 0, 0, this);
// Now we must loop through all of the successors of the New block (which
// _were_ the successors of the 'this' block), and update any PHI nodes in