719c05ed2309174b0f8cee00c31a95958448ad67
[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.  Additionally, it keeps track of which node is the new
5 // exit node of the CFG.  If there are no exit nodes in the CFG, the getExitNode
6 // method will return a null pointer.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_XFORMS_UNIFY_FUNCTION_EXIT_NODES_H
11 #define LLVM_XFORMS_UNIFY_FUNCTION_EXIT_NODES_H
12
13 #include "llvm/Pass.h"
14
15 struct UnifyFunctionExitNodes : public FunctionPass {
16   BasicBlock *ExitNode;
17 public:
18   static AnalysisID ID;            // Pass ID
19   UnifyFunctionExitNodes(AnalysisID id = ID) : ExitNode(0) { assert(ID == id); }
20
21   // getExitNode - Return the new single (or nonexistant) exit node of the CFG.
22   //
23   BasicBlock *getExitNode() const { return ExitNode; }
24
25   virtual bool runOnFunction(Function &F);
26   virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.addProvided(ID); }
27 };
28
29 static inline Pass *createUnifyFunctionExitNodesPass() {
30   return new UnifyFunctionExitNodes();
31 }
32
33 #endif