diff options
author | Chris Lattner <sabre@nondot.org> | 2003-03-31 17:30:25 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-03-31 17:30:25 +0000 |
commit | 6c0e0496dc8f901a282ae1f591b8af2ecf095b97 (patch) | |
tree | 264ec378879fa1aa08bd104972840175de10fb0e /lib/Transforms/Utils/UnifyFunctionExitNodes.cpp | |
parent | d76370b3069e35daf41e1f28370a5f8e8136abb3 (diff) |
* We now preserve the no-critical-edge pass (because we cannot insert critical edges)
* Small modification to be more efficient
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5757 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/UnifyFunctionExitNodes.cpp')
-rw-r--r-- | lib/Transforms/Utils/UnifyFunctionExitNodes.cpp | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp index 3c522b53ab..b56cee9379 100644 --- a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp +++ b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h" +#include "llvm/Transforms/Scalar.h" #include "llvm/BasicBlock.h" #include "llvm/Function.h" #include "llvm/iTerminators.h" @@ -18,6 +19,11 @@ using std::vector; static RegisterOpt<UnifyFunctionExitNodes> X("mergereturn", "Unify function exit nodes"); +void UnifyFunctionExitNodes::getAnalysisUsage(AnalysisUsage &AU) const{ + // We preserve the non-critical-edgeness property + AU.addPreservedID(BreakCriticalEdgesID); +} + // UnifyAllExitNodes - Unify all exit nodes of the CFG by creating a new // BasicBlock, and converting all returns to unconditional branches to this // new basic block. The singular exit node is returned. @@ -47,18 +53,11 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) { // BasicBlock *NewRetBlock = new BasicBlock("UnifiedExitNode", &F); + PHINode *PN = 0; if (F.getReturnType() != Type::VoidTy) { // If the function doesn't return void... add a PHI node to the block... - PHINode *PN = new PHINode(F.getReturnType(), "UnifiedRetVal"); + PN = new PHINode(F.getReturnType(), "UnifiedRetVal"); NewRetBlock->getInstList().push_back(PN); - - // Add an incoming element to the PHI node for every return instruction that - // is merging into this new block... - for (vector<BasicBlock*>::iterator I = ReturningBlocks.begin(), - E = ReturningBlocks.end(); I != E; ++I) - PN->addIncoming((*I)->getTerminator()->getOperand(0), *I); - - // Add a return instruction to return the result of the PHI node... NewRetBlock->getInstList().push_back(new ReturnInst(PN)); } else { // If it returns void, just add a return void instruction to the block @@ -70,9 +69,16 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) { // for (vector<BasicBlock*>::iterator I = ReturningBlocks.begin(), E = ReturningBlocks.end(); I != E; ++I) { - (*I)->getInstList().pop_back(); // Remove the return insn - (*I)->getInstList().push_back(new BranchInst(NewRetBlock)); + BasicBlock *BB = *I; + + // Add an incoming element to the PHI node for every return instruction that + // is merging into this new block... + if (PN) PN->addIncoming(BB->getTerminator()->getOperand(0), BB); + + BB->getInstList().pop_back(); // Remove the return insn + BB->getInstList().push_back(new BranchInst(NewRetBlock)); } ExitNode = NewRetBlock; + return true; } |