diff options
author | Chris Lattner <sabre@nondot.org> | 2006-09-13 21:27:00 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-09-13 21:27:00 +0000 |
commit | a4646b61e48453e343730103d3ad689be493a371 (patch) | |
tree | af39484635fd76e63ecb5750bf0115d55eb800af /lib/Transforms/Utils | |
parent | 668a1d0fd2c82ddb4424129f0a7a47520ff3f12c (diff) | |
download | external_llvm-a4646b61e48453e343730103d3ad689be493a371.zip external_llvm-a4646b61e48453e343730103d3ad689be493a371.tar.gz external_llvm-a4646b61e48453e343730103d3ad689be493a371.tar.bz2 |
Second half of the fix for Transforms/Inline/inline_cleanup.ll
This folds unconditional branches that are often produced by code
specialization.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30307 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils')
-rw-r--r-- | lib/Transforms/Utils/CloneFunction.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp index a7ef06d..f80b153 100644 --- a/lib/Transforms/Utils/CloneFunction.cpp +++ b/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. + } +} |