summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/CloneFunction.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-09-13 21:27:00 +0000
committerChris Lattner <sabre@nondot.org>2006-09-13 21:27:00 +0000
commit237ccf2a51f72e5b1a5174bb2a5c4c4515333bfb (patch)
tree16e9f52130ae7cc160a7e04c29c95001482c4935 /llvm/lib/Transforms/Utils/CloneFunction.cpp
parent12efffc96bd44f58097856ea94e84eae1136fb5a (diff)
downloadbcm5719-llvm-237ccf2a51f72e5b1a5174bb2a5c4c4515333bfb.tar.gz
bcm5719-llvm-237ccf2a51f72e5b1a5174bb2a5c4c4515333bfb.zip
Second half of the fix for Transforms/Inline/inline_cleanup.ll
This folds unconditional branches that are often produced by code specialization. llvm-svn: 30307
Diffstat (limited to 'llvm/lib/Transforms/Utils/CloneFunction.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/CloneFunction.cpp30
1 files changed, 28 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index a7ef06d684f..f80b1530f89 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -449,6 +449,32 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
}
}
}
-}
-
+
+ // Now that the inlined function body has been fully constructed, go through
+ // and zap unconditional fall-through branches. This happen all the time when
+ // specializing code: code specialization turns conditional branches into
+ // uncond branches, and this code folds them.
+ Function::iterator I = cast<BasicBlock>(ValueMap[&OldFunc->getEntryBlock()]);
+ while (I != NewFunc->end()) {
+ BranchInst *BI = dyn_cast<BranchInst>(I->getTerminator());
+ if (!BI || BI->isConditional()) { ++I; continue; }
+
+ BasicBlock *Dest = BI->getSuccessor(0);
+ if (!Dest->getSinglePredecessor()) { ++I; continue; }
+
+ // We know all single-entry PHI nodes in the inlined function have been
+ // removed, so we just need to splice the blocks.
+ BI->eraseFromParent();
+
+ // Move all the instructions in the succ to the pred.
+ I->getInstList().splice(I->end(), Dest->getInstList());
+
+ // Make all PHI nodes that referred to Dest now refer to I as their source.
+ Dest->replaceAllUsesWith(I);
+ // Remove the dest block.
+ Dest->eraseFromParent();
+
+ // Do not increment I, iteratively merge all things this block branches to.
+ }
+}
OpenPOWER on IntegriCloud