Rename Method to Function
[oota-llvm.git] / include / llvm / Transforms / Utils / UnifyFunctionExitNodes.h
1 //===-- UnifyMethodExitNodes.h - Ensure methods have one return --*- C++ -*--=//
2 //
3 // This pass is used to ensure that methods have at most one return instruction
4 // in them.  It also holds onto the return instruction of the last unified
5 // method.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_XFORMS_UNIFY_METHOD_EXIT_NODES_H
10 #define LLVM_XFORMS_UNIFY_METHOD_EXIT_NODES_H
11
12 #include "llvm/Pass.h"
13
14 struct UnifyMethodExitNodes : public MethodPass {
15   BasicBlock *ExitNode;
16 public:
17   static AnalysisID ID;            // Pass ID
18   UnifyMethodExitNodes(AnalysisID id = ID) : ExitNode(0) { assert(ID == id); }
19
20   // UnifyAllExitNodes - Unify all exit nodes of the CFG by creating a new
21   // BasicBlock, and converting all returns to unconditional branches to this
22   // new basic block.  The singular exit node is returned in ExitNode.
23   //
24   // If there are no return stmts in the Method, a null pointer is returned.
25   //
26   static bool doit(Function *F, BasicBlock *&ExitNode);
27
28
29   virtual bool runOnMethod(Function *F) {
30     return doit(F, ExitNode);
31   }
32
33   BasicBlock *getExitNode() const { return ExitNode; }
34
35   virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required,
36                                     Pass::AnalysisSet &Destroyed,
37                                     Pass::AnalysisSet &Provided) {
38     // FIXME: Should invalidate CFG
39     Provided.push_back(ID);  // Provide self!
40   }
41 };
42
43 static inline Pass *createUnifyMethodExitNodesPass() {
44   return new UnifyMethodExitNodes();
45 }
46
47 #endif