[llvm-commits] CVS: llvm/lib/Transforms/Scalar/SCCP.cpp
Chris Lattner
lattner at cs.uiuc.edu
Fri Dec 10 14:29:21 PST 2004
Changes in directory llvm/lib/Transforms/Scalar:
SCCP.cpp updated: 1.113 -> 1.114
---
Log message:
Implement SCCP/ipsccp-conditional.ll, by totally deleting dead blocks.
---
Diffs of the changes: (+29 -2)
Index: llvm/lib/Transforms/Scalar/SCCP.cpp
diff -u llvm/lib/Transforms/Scalar/SCCP.cpp:1.113 llvm/lib/Transforms/Scalar/SCCP.cpp:1.114
--- llvm/lib/Transforms/Scalar/SCCP.cpp:1.113 Fri Dec 10 14:41:50 2004
+++ llvm/lib/Transforms/Scalar/SCCP.cpp Fri Dec 10 16:29:08 2004
@@ -1109,17 +1109,20 @@
}
}
+ 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 @@
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 @@
}
}
}
+
+ // 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;
}
More information about the llvm-commits
mailing list