s/Method/Function in classname
[oota-llvm.git] / include / llvm / Transforms / Utils / UnifyFunctionExitNodes.h
1 //===-- UnifyFunctionExitNodes.h - Ensure fn's have one return ---*- C++ -*--=//
2 //
3 // This pass is used to ensure that functions have at most one return
4 // instruction in them.  It also holds onto the return instruction of the last
5 // unified function.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_XFORMS_UNIFY_FUNCTION_EXIT_NODES_H
10 #define LLVM_XFORMS_UNIFY_FUNCTION_EXIT_NODES_H
11
12 #include "llvm/Pass.h"
13
14 struct UnifyFunctionExitNodes : public FunctionPass {
15   BasicBlock *ExitNode;
16 public:
17   static AnalysisID ID;            // Pass ID
18   UnifyFunctionExitNodes(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 function, a null pointer is returned.
25   //
26   static bool doit(Function *F, BasicBlock *&ExitNode);
27
28
29   virtual bool runOnFunction(Function *F) {
30     return doit(F, ExitNode);
31   }
32
33   BasicBlock *getExitNode() const { return ExitNode; }
34
35   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
36     AU.addProvided(ID);  // Provide self!
37   }
38 };
39
40 static inline Pass *createUnifyFunctionExitNodesPass() {
41   return new UnifyFunctionExitNodes();
42 }
43
44 #endif