aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-12-10 22:29:08 +0000
committerChris Lattner <sabre@nondot.org>2004-12-10 22:29:08 +0000
commit5f9e8b4c3fbafe0a3f968392386f2b6c83d7e45f (patch)
treeaadf2723a14f5121a5a254026ce4e93c57830ff7 /lib/Transforms
parent9b07c66501b0720d0421b2478327f2b660f3d815 (diff)
Implement SCCP/ipsccp-conditional.ll, by totally deleting dead blocks.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18781 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index 10c70bfdfd..f6be510fb0 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -1109,17 +1109,20 @@ bool IPSCCP::runOnModule(Module &M) {
}
}
+ std::vector<BasicBlock*> BlocksToErase;
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
if (!ExecutableBBs.count(BB)) {
DEBUG(std::cerr << " BasicBlock Dead:" << *BB);
++IPNumDeadBlocks;
+ BlocksToErase.push_back(BB);
// Delete the instructions backwards, as it has a reduced likelihood of
// having to update as many def-use and use-def chains.
std::vector<Instruction*> Insts;
- for (BasicBlock::iterator I = BB->begin(), E = BB->getTerminator();
- I != E; ++I)
+ TerminatorInst *TI = BB->getTerminator();
+ for (BasicBlock::iterator I = BB->begin(), E = TI; I != E; ++I)
Insts.push_back(I);
+
while (!Insts.empty()) {
Instruction *I = Insts.back();
Insts.pop_back();
@@ -1129,6 +1132,14 @@ bool IPSCCP::runOnModule(Module &M) {
MadeChanges = true;
++IPNumInstRemoved;
}
+
+ for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i) {
+ BasicBlock *Succ = TI->getSuccessor(i);
+ if (Succ->begin() != Succ->end() && isa<PHINode>(Succ->begin()))
+ TI->getSuccessor(i)->removePredecessor(BB);
+ }
+ BB->getInstList().erase(TI);
+
} else {
for (BasicBlock::iterator BI = BB->begin(), E = BB->end(); BI != E; ) {
Instruction *Inst = BI++;
@@ -1155,6 +1166,22 @@ bool IPSCCP::runOnModule(Module &M) {
}
}
}
+
+ // Now that all instructions in the function are constant folded, erase dead
+ // blocks, because we can now use ConstantFoldTerminator to get rid of
+ // in-edges.
+ for (unsigned i = 0, e = BlocksToErase.size(); i != e; ++i) {
+ // If there are any PHI nodes in this successor, drop entries for BB now.
+ BasicBlock *DeadBB = BlocksToErase[i];
+ while (!DeadBB->use_empty()) {
+ Instruction *I = cast<Instruction>(DeadBB->use_back());
+ bool Folded = ConstantFoldTerminator(I->getParent());
+ assert(Folded && "Didn't fold away reference to block!");
+ }
+
+ // Finally, delete the basic block.
+ F->getBasicBlockList().erase(DeadBB);
+ }
}
return MadeChanges;
}