aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-02-24 05:54:22 +0000
committerChris Lattner <sabre@nondot.org>2004-02-24 05:54:22 +0000
commite14ea0804afba2ac5824507571a220d05b0aa21d (patch)
treeb6b9a71694fe7a9e4f74a39e79d40692f1feed04 /lib/Transforms/Utils/SimplifyCFG.cpp
parent0d56008f53587531718ec36af82cc24576580b36 (diff)
Rearrange code a bit
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11793 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp57
1 files changed, 27 insertions, 30 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index a268b47505..c4702b6af7 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -301,36 +301,6 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
assert(BB->getTerminator() && "Degenerate basic block encountered!");
assert(&BB->getParent()->front() != BB && "Can't Simplify entry block!");
- // Check to see if the first instruction in this block is just an unwind. If
- // so, replace any invoke instructions which use this as an exception
- // destination with call instructions.
- //
- if (UnwindInst *UI = dyn_cast<UnwindInst>(BB->getTerminator()))
- if (BB->begin() == BasicBlock::iterator(UI)) { // Empty block?
- std::vector<BasicBlock*> Preds(pred_begin(BB), pred_end(BB));
- while (!Preds.empty()) {
- BasicBlock *Pred = Preds.back();
- if (InvokeInst *II = dyn_cast<InvokeInst>(Pred->getTerminator()))
- 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);
- Pred->getInstList().remove(II); // Take out of symbol table
-
- // Insert the call now...
- std::vector<Value*> Args(II->op_begin()+3, II->op_end());
- CallInst *CI = new CallInst(II->getCalledValue(), Args,
- II->getName(), BI);
- // If the invoke produced a value, the Call now does instead
- II->replaceAllUsesWith(CI);
- delete II;
- Changed = true;
- }
-
- Preds.pop_back();
- }
- }
-
// Remove basic blocks that have no predecessors... which are unreachable.
if (pred_begin(BB) == pred_end(BB)) {
//cerr << "Removing BB: \n" << BB;
@@ -473,6 +443,33 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
return true;
}
}
+ } else if (UnwindInst *UI = dyn_cast<UnwindInst>(BB->begin())) {
+ // Check to see if the first instruction in this block is just an unwind.
+ // If so, replace any invoke instructions which use this as an exception
+ // destination with call instructions.
+ //
+ std::vector<BasicBlock*> Preds(pred_begin(BB), pred_end(BB));
+ while (!Preds.empty()) {
+ BasicBlock *Pred = Preds.back();
+ if (InvokeInst *II = dyn_cast<InvokeInst>(Pred->getTerminator()))
+ 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);
+ Pred->getInstList().remove(II); // Take out of symbol table
+
+ // Insert the call now...
+ std::vector<Value*> Args(II->op_begin()+3, II->op_end());
+ CallInst *CI = new CallInst(II->getCalledValue(), Args,
+ II->getName(), BI);
+ // If the invoke produced a value, the Call now does instead
+ II->replaceAllUsesWith(CI);
+ delete II;
+ Changed = true;
+ }
+
+ Preds.pop_back();
+ }
}
// Merge basic blocks into their predecessor if there is only one distinct