summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-01-31 01:12:06 +0000
committerChris Lattner <sabre@nondot.org>2002-01-31 01:12:06 +0000
commit21801532fdd6019734e990603405a0d983266804 (patch)
tree29a51df3ccc7996d06611c6d8e73626f0bf65ca1
parent2d4fe48b17adba604740800302f19fcc11bbdf34 (diff)
downloadllvm-21801532fdd6019734e990603405a0d983266804.tar.gz
llvm-21801532fdd6019734e990603405a0d983266804.tar.bz2
llvm-21801532fdd6019734e990603405a0d983266804.tar.xz
Eliminate SimplifyCFG.h file, pull everything into the UnifyMethodExitNodes class
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1613 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h14
-rw-r--r--lib/Transforms/Utils/UnifyFunctionExitNodes.cpp19
2 files changed, 21 insertions, 12 deletions
diff --git a/include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h b/include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h
index 09394685c1..64dc03c985 100644
--- a/include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h
+++ b/include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h
@@ -10,7 +10,6 @@
#define LLVM_XFORMS_UNIFY_METHOD_EXIT_NODES_H
#include "llvm/Pass.h"
-#include "llvm/Analysis/SimplifyCFG.h" // FIXME!!
struct UnifyMethodExitNodes : public MethodPass {
BasicBlock *ExitNode;
@@ -18,10 +17,17 @@ public:
static AnalysisID ID; // Pass ID
UnifyMethodExitNodes(AnalysisID id) : ExitNode(0) { assert(ID == id); }
- virtual bool runOnMethod(Method *M) {
- ExitNode = cfg::UnifyAllExitNodes(M);
+ // 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 in ExitNode.
+ //
+ // If there are no return stmts in the Method, a null pointer is returned.
+ //
+ static bool doit(Method *M, BasicBlock *&ExitNode);
+
- return true; // FIXME: This should return a correct code!!!
+ virtual bool runOnMethod(Method *M) {
+ return doit(M, ExitNode);
}
BasicBlock *getExitNode() const { return ExitNode; }
diff --git a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
index 4716e7ebcd..15e37e3993 100644
--- a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
+++ b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
@@ -5,7 +5,6 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/Analysis/SimplifyCFG.h"
#include "llvm/Transforms/UnifyMethodExitNodes.h"
#include "llvm/BasicBlock.h"
#include "llvm/Method.h"
@@ -23,7 +22,7 @@ AnalysisID UnifyMethodExitNodes::ID(AnalysisID::create<UnifyMethodExitNodes>());
//
// If there are no return stmts in the Method, a null pointer is returned.
//
-BasicBlock *cfg::UnifyAllExitNodes(Method *M) {
+bool UnifyMethodExitNodes::doit(Method *M, BasicBlock *&ExitNode) {
vector<BasicBlock*> ReturningBlocks;
// Loop over all of the blocks in a method, tracking all of the blocks that
@@ -33,16 +32,19 @@ BasicBlock *cfg::UnifyAllExitNodes(Method *M) {
if ((*I)->getTerminator()->getOpcode() == Instruction::Ret)
ReturningBlocks.push_back(*I);
- if (ReturningBlocks.size() == 0)
- return 0; // No blocks return
- else if (ReturningBlocks.size() == 1)
- return ReturningBlocks.front(); // Already has a single return block
+ if (ReturningBlocks.size() == 0) {
+ ExitNode = 0;
+ return false; // No blocks return
+ } else if (ReturningBlocks.size() == 1) {
+ ExitNode = ReturningBlocks.front(); // Already has a single return block
+ return false;
+ }
// Otherwise, we need to insert a new basic block into the method, add a PHI
// node (if the function returns a value), and convert all of the return
// instructions into unconditional branches.
//
- BasicBlock *NewRetBlock = new BasicBlock("", M);
+ BasicBlock *NewRetBlock = new BasicBlock("UnifiedExitNode", M);
if (M->getReturnType() != Type::VoidTy) {
// If the method doesn't return void... add a PHI node to the block...
@@ -70,5 +72,6 @@ BasicBlock *cfg::UnifyAllExitNodes(Method *M) {
delete (*I)->getInstList().pop_back(); // Remove the return insn
(*I)->getInstList().push_back(new BranchInst(NewRetBlock));
}
- return NewRetBlock;
+ ExitNode = NewRetBlock;
+ return true;
}