Start using the nicer terminator auto-insertion API

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10111 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2003-11-20 18:25:24 +00:00
parent adbc0b5287
commit f8485c6434
12 changed files with 32 additions and 46 deletions

View File

@@ -314,12 +314,11 @@ BasicBlock* LowerSetJmp::GetRethrowBB(Function* Func)
// The basic block we're going to jump to if we need to rethrow the // The basic block we're going to jump to if we need to rethrow the
// exception. // exception.
BasicBlock* Rethrow = new BasicBlock("RethrowExcept", Func); BasicBlock* Rethrow = new BasicBlock("RethrowExcept", Func);
BasicBlock::InstListType& RethrowBlkIL = Rethrow->getInstList();
// Fill in the "Rethrow" BB with a call to rethrow the exception. This // 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 // is the last instruction in the BB since at this point the runtime
// should exit this function and go to the next function. // should exit this function and go to the next function.
RethrowBlkIL.push_back(new UnwindInst()); new UnwindInst(Rethrow);
return RethrowBBMap[Func] = Rethrow; return RethrowBBMap[Func] = Rethrow;
} }
@@ -348,7 +347,7 @@ LowerSetJmp::SwitchValuePair LowerSetJmp::GetSJSwitch(Function* Func,
BasicBlock* DecisionBB = new BasicBlock("LJDecisionBB", Func); BasicBlock* DecisionBB = new BasicBlock("LJDecisionBB", Func);
BasicBlock::InstListType& DecisionBBIL = DecisionBB->getInstList(); 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. // Fill in the "decision" basic block.
CallInst* LJVal = new CallInst(GetLJValue, std::vector<Value*>(), "LJVal"); CallInst* LJVal = new CallInst(GetLJValue, std::vector<Value*>(), "LJVal");
@@ -357,8 +356,7 @@ LowerSetJmp::SwitchValuePair LowerSetJmp::GetSJSwitch(Function* Func,
CallInst(TryCatchLJ, make_vector<Value*>(GetSetJmpMap(Func), 0), "SJNum"); CallInst(TryCatchLJ, make_vector<Value*>(GetSetJmpMap(Func), 0), "SJNum");
DecisionBBIL.push_back(SJNum); DecisionBBIL.push_back(SJNum);
SwitchInst* SI = new SwitchInst(SJNum, Rethrow); SwitchInst* SI = new SwitchInst(SJNum, Rethrow, DecisionBB);
DecisionBBIL.push_back(SI);
return SwitchValMap[Func] = SwitchValuePair(SI, LJVal); return SwitchValMap[Func] = SwitchValuePair(SI, LJVal);
} }
@@ -511,8 +509,7 @@ void LowerSetJmp::visitInvokeInst(InvokeInst& II)
CallInst(IsLJException, std::vector<Value*>(), "IsLJExcept"); CallInst(IsLJException, std::vector<Value*>(), "IsLJExcept");
InstList.push_back(IsLJExcept); InstList.push_back(IsLJExcept);
BranchInst* BR = new BranchInst(PrelimBBMap[Func], ExceptBB, IsLJExcept); new BranchInst(PrelimBBMap[Func], ExceptBB, IsLJExcept, NewExceptBB);
InstList.push_back(BR);
II.setExceptionalDest(NewExceptBB); II.setExceptionalDest(NewExceptBB);
++InvokesTransformed; ++InvokesTransformed;

View File

@@ -122,9 +122,7 @@ void CombineBranches::removeRedundant(std::map<BasicBlock *, BasicBlock *> &be){
sameTarget.push_back(MI->first); sameTarget.push_back(MI->first);
BasicBlock *newBB = new BasicBlock("newCommon", MI->first->getParent()); BasicBlock *newBB = new BasicBlock("newCommon", MI->first->getParent());
BranchInst *newBranch = new BranchInst(MI->second); BranchInst *newBranch = new BranchInst(MI->second, 0, 0, newBB);
newBB->getInstList().push_back(newBranch);
std::map<PHINode *, std::vector<unsigned int> > phiMap; std::map<PHINode *, std::vector<unsigned int> > phiMap;

View File

@@ -344,12 +344,10 @@ void insertBB(Edge ed,
newBB->getInstList().push_back(newBI2); newBB->getInstList().push_back(newBI2);
//triggerBB->getInstList().push_back(triggerInst); //triggerBB->getInstList().push_back(triggerInst);
Instruction *triggerBranch = new BranchInst(BB2); new BranchInst(BB2, 0, 0, triggerBB);
triggerBB->getInstList().push_back(triggerBranch);
} }
else{ else{
Instruction *newBI2=new BranchInst(BB2); new BranchInst(BB2, 0, 0, newBB);
newBB->getInstList().push_back(newBI2);
} }
//now iterate over BB2, and set its Phi nodes right //now iterate over BB2, and set its Phi nodes right

View File

@@ -145,10 +145,8 @@ void InstLoops::findAndInstrumentBackEdges(Function &F){
ti->setSuccessor(index, newBB); ti->setSuccessor(index, newBB);
BasicBlock::InstListType &lt = newBB->getInstList(); BasicBlock::InstListType &lt = newBB->getInstList();
lt.push_back(new CallInst(inCountMth));
Instruction *call = new CallInst(inCountMth); new BranchInst(BB, newBB);
lt.push_back(call);
lt.push_back(new BranchInst(BB));
//now iterate over *vl, and set its Phi nodes right //now iterate over *vl, and set its Phi nodes right
for(BasicBlock::iterator BB2Inst = BB->begin(), BBend = BB->end(); for(BasicBlock::iterator BB2Inst = BB->begin(), BBend = BB->end();

View File

@@ -302,7 +302,7 @@ bool ADCE::doADCE() {
// //
if (!AliveBlocks.count(&Func->front())) { if (!AliveBlocks.count(&Func->front())) {
BasicBlock *NewEntry = new BasicBlock(); BasicBlock *NewEntry = new BasicBlock();
NewEntry->getInstList().push_back(new BranchInst(&Func->front())); new BranchInst(&Func->front(), 0, 0, NewEntry);
Func->getBasicBlockList().push_front(NewEntry); Func->getBasicBlockList().push_front(NewEntry);
AliveBlocks.insert(NewEntry); // This block is always alive! AliveBlocks.insert(NewEntry); // This block is always alive!
LiveSet.insert(NewEntry->getTerminator()); // The branch is live LiveSet.insert(NewEntry->getTerminator()); // The branch is live
@@ -432,8 +432,8 @@ bool ADCE::doADCE() {
// Delete the old terminator instruction... // Delete the old terminator instruction...
BB->getInstList().pop_back(); BB->getInstList().pop_back();
const Type *RetTy = Func->getReturnType(); const Type *RetTy = Func->getReturnType();
BB->getInstList().push_back(new ReturnInst(RetTy != Type::VoidTy ? new ReturnInst(RetTy != Type::VoidTy ?
Constant::getNullValue(RetTy) : 0)); Constant::getNullValue(RetTy) : 0, BB);
} }
} }

View File

@@ -33,7 +33,7 @@
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "Support/Statistic.h" #include "Support/Statistic.h"
namespace llvm { using namespace llvm;
namespace { namespace {
Statistic<> NumEliminated("tailcallelim", "Number of tail calls removed"); Statistic<> NumEliminated("tailcallelim", "Number of tail calls removed");
@@ -45,7 +45,9 @@ namespace {
} }
// Public interface to the TailCallElimination pass // Public interface to the TailCallElimination pass
FunctionPass *createTailCallEliminationPass() { return new TailCallElim(); } FunctionPass *llvm::createTailCallEliminationPass() {
return new TailCallElim();
}
bool TailCallElim::runOnFunction(Function &F) { bool TailCallElim::runOnFunction(Function &F) {
@@ -74,7 +76,7 @@ bool TailCallElim::runOnFunction(Function &F) {
// us to branch back to the old entry block. // us to branch back to the old entry block.
OldEntry = &F.getEntryBlock(); OldEntry = &F.getEntryBlock();
BasicBlock *NewEntry = new BasicBlock("tailrecurse", OldEntry); 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 // Now that we have created a new block, which jumps to the entry
// block, insert a PHI node for each argument of the function. // block, insert a PHI node for each argument of the function.
@@ -107,5 +109,3 @@ bool TailCallElim::runOnFunction(Function &F) {
return MadeChange; return MadeChange;
} }
} // End llvm namespace

View File

@@ -106,8 +106,7 @@ bool SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P) {
BasicBlock *NewBB = new BasicBlock(TIBB->getName() + "." + BasicBlock *NewBB = new BasicBlock(TIBB->getName() + "." +
DestBB->getName() + "_crit_edge"); DestBB->getName() + "_crit_edge");
// Create our unconditional branch... // Create our unconditional branch...
BranchInst *BI = new BranchInst(DestBB); new BranchInst(DestBB, 0, 0, NewBB);
NewBB->getInstList().push_back(BI);
// Branch to the new block, breaking the edge... // Branch to the new block, breaking the edge...
TI->setSuccessor(SuccNum, NewBB); TI->setSuccessor(SuccNum, NewBB);

View File

@@ -238,7 +238,7 @@ bool InlineFunction(CallSite CS) {
// invoke site. Once this happens, we know that the unwind would cause // invoke site. Once this happens, we know that the unwind would cause
// a control transfer to the invoke exception destination, so we can // a control transfer to the invoke exception destination, so we can
// transform it into a direct branch to the exception destination. // transform it into a direct branch to the exception destination.
BranchInst *BI = new BranchInst(InvokeDest, UI); new BranchInst(InvokeDest, UI);
// Delete the unwind instruction! // Delete the unwind instruction!
UI->getParent()->getInstList().pop_back(); UI->getParent()->getInstList().pop_back();

View File

@@ -153,8 +153,7 @@ BasicBlock *LoopSimplify::SplitBlockPredecessors(BasicBlock *BB,
BasicBlock *NewBB = new BasicBlock(BB->getName()+Suffix, BB); BasicBlock *NewBB = new BasicBlock(BB->getName()+Suffix, BB);
// The preheader first gets an unconditional branch to the loop header... // The preheader first gets an unconditional branch to the loop header...
BranchInst *BI = new BranchInst(BB); BranchInst *BI = new BranchInst(BB, 0, 0, NewBB);
NewBB->getInstList().push_back(BI);
// For every PHI node in the block, insert a PHI node into NewBB where the // 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 // incoming values from the out of loop edges are moved to NewBB. We have two
@@ -380,8 +379,7 @@ void LoopSimplify::InsertUniqueBackedgeBlock(Loop *L) {
// Create and insert the new backedge block... // Create and insert the new backedge block...
BasicBlock *BEBlock = new BasicBlock(Header->getName()+".backedge", F); BasicBlock *BEBlock = new BasicBlock(Header->getName()+".backedge", F);
Instruction *BETerminator = new BranchInst(Header); BranchInst *BETerminator = new BranchInst(Header, 0, 0, BEBlock);
BEBlock->getInstList().push_back(BETerminator);
// Move the new backedge block to right after the last backedge block. // Move the new backedge block to right after the last backedge block.
Function::iterator InsertPos = BackedgeBlocks.back(); ++InsertPos; Function::iterator InsertPos = BackedgeBlocks.back(); ++InsertPos;

View File

@@ -132,8 +132,7 @@ BasicBlock* LowerSwitch::switchConvert(CaseItr Begin, CaseItr End,
SetCondInst* Comp = new SetCondInst(Instruction::SetLT, Val, Pivot.first, SetCondInst* Comp = new SetCondInst(Instruction::SetLT, Val, Pivot.first,
"Pivot"); "Pivot");
NewNode->getInstList().push_back(Comp); NewNode->getInstList().push_back(Comp);
BranchInst* Br = new BranchInst(LBranch, RBranch, Comp); new BranchInst(LBranch, RBranch, Comp, NewNode);
NewNode->getInstList().push_back(Br);
return NewNode; return NewNode;
} }
@@ -158,8 +157,7 @@ BasicBlock* LowerSwitch::newLeafBlock(Case& Leaf, Value* Val,
// Make the conditional branch... // Make the conditional branch...
BasicBlock* Succ = Leaf.second; BasicBlock* Succ = Leaf.second;
Instruction* Br = new BranchInst(Succ, Default, Comp); new BranchInst(Succ, Default, Comp, NewLeaf);
NewLeaf->getInstList().push_back(Br);
// If there were any PHI nodes in this successor, rewrite one entry // If there were any PHI nodes in this successor, rewrite one entry
// from OrigBlock to come from NewLeaf. // from OrigBlock to come from NewLeaf.
@@ -188,7 +186,7 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI) {
// If there is only the default destination, don't bother with the code below. // If there is only the default destination, don't bother with the code below.
if (SI->getNumOperands() == 2) { if (SI->getNumOperands() == 2) {
CurBlock->getInstList().push_back(new BranchInst(SI->getDefaultDest())); new BranchInst(SI->getDefaultDest(), 0, 0, CurBlock);
delete SI; delete SI;
return; return;
} }
@@ -198,7 +196,7 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI) {
BasicBlock* NewDefault = new BasicBlock("NewDefault"); BasicBlock* NewDefault = new BasicBlock("NewDefault");
F->getBasicBlockList().insert(Default, 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 // If there is an entry in any PHI nodes for the default edge, make sure
// to update them as well. // to update them as well.
@@ -221,7 +219,7 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI) {
OrigBlock, NewDefault); OrigBlock, NewDefault);
// Branch to our shiny new if-then stuff... // 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. // We are now done with the switch instruction, delete it.
delete SI; delete SI;

View File

@@ -61,13 +61,13 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) {
UnwindBlock = UnwindingBlocks.front(); UnwindBlock = UnwindingBlocks.front();
} else { } else {
UnwindBlock = new BasicBlock("UnifiedUnwindBlock", &F); UnwindBlock = new BasicBlock("UnifiedUnwindBlock", &F);
UnwindBlock->getInstList().push_back(new UnwindInst()); new UnwindInst(UnwindBlock);
for (std::vector<BasicBlock*>::iterator I = UnwindingBlocks.begin(), for (std::vector<BasicBlock*>::iterator I = UnwindingBlocks.begin(),
E = UnwindingBlocks.end(); I != E; ++I) { E = UnwindingBlocks.end(); I != E; ++I) {
BasicBlock *BB = *I; BasicBlock *BB = *I;
BB->getInstList().pop_back(); // Remove the return insn BB->getInstList().pop_back(); // Remove the return insn
BB->getInstList().push_back(new BranchInst(UnwindBlock)); new BranchInst(UnwindBlock, 0, 0, BB);
} }
} }
@@ -91,10 +91,10 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) {
// If the function doesn't return void... add a PHI node to the block... // If the function doesn't return void... add a PHI node to the block...
PN = new PHINode(F.getReturnType(), "UnifiedRetVal"); PN = new PHINode(F.getReturnType(), "UnifiedRetVal");
NewRetBlock->getInstList().push_back(PN); NewRetBlock->getInstList().push_back(PN);
NewRetBlock->getInstList().push_back(new ReturnInst(PN)); new ReturnInst(PN, NewRetBlock);
} else { } else {
// If it returns void, just add a return void instruction to the block // 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 // Loop over all of the blocks, replacing the return instruction with an
@@ -109,7 +109,7 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) {
if (PN) PN->addIncoming(BB->getTerminator()->getOperand(0), BB); if (PN) PN->addIncoming(BB->getTerminator()->getOperand(0), BB);
BB->getInstList().pop_back(); // Remove the return insn BB->getInstList().pop_back(); // Remove the return insn
BB->getInstList().push_back(new BranchInst(NewRetBlock)); new BranchInst(NewRetBlock, 0, 0, BB);
} }
ReturnBlock = NewRetBlock; ReturnBlock = NewRetBlock;
return true; return true;

View File

@@ -243,7 +243,7 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const std::string &BBName) {
} while (Inst != &*I); // Loop until we move the specified instruction. } while (Inst != &*I); // Loop until we move the specified instruction.
// Add a branch instruction to the newly formed basic block. // 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 // 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 // _were_ the successors of the 'this' block), and update any PHI nodes in