[llvm-commits] CVS: llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
Chris Lattner
lattner at cs.uiuc.edu
Mon Mar 31 11:31:00 PST 2003
Changes in directory llvm/lib/Transforms/Utils:
UnifyFunctionExitNodes.cpp updated: 1.22 -> 1.23
---
Log message:
* We now preserve the no-critical-edge pass (because we cannot insert critical edges)
* Small modification to be more efficient
---
Diffs of the changes:
Index: llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
diff -u llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp:1.22 llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp:1.23
--- llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp:1.22 Thu Sep 12 14:00:43 2002
+++ llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp Mon Mar 31 11:30:25 2003
@@ -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 @@
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 @@
//
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 @@
//
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;
}
More information about the llvm-commits
mailing list