431dd8b9d3f449590e4dfd1943ab8dcb17095f78
[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 and one
4 // unwind instruction in them.  Additionally, it keeps track of which node is
5 // the new exit node of the CFG.  If there are no return or unwind instructions
6 // in the function, the getReturnBlock/getUnwindBlock methods will return a null
7 // pointer.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef LLVM_TRANSFORMS_UNIFYFUNCTIONEXITNODES_H
12 #define LLVM_TRANSFORMS_UNIFYFUNCTIONEXITNODES_H
13
14 #include "llvm/Pass.h"
15
16 struct UnifyFunctionExitNodes : public FunctionPass {
17   BasicBlock *ReturnBlock, *UnwindBlock;
18 public:
19   UnifyFunctionExitNodes() : ReturnBlock(0), UnwindBlock(0) {}
20
21   // We can preserve non-critical-edgeness when we unify function exit nodes
22   virtual void getAnalysisUsage(AnalysisUsage &AU) const;
23
24   // getReturn|UnwindBlock - Return the new single (or nonexistant) return or
25   // unwind basic blocks in the CFG.
26   //
27   BasicBlock *getReturnBlock() const { return ReturnBlock; }
28   BasicBlock *getUnwindBlock() const { return UnwindBlock; }
29
30   virtual bool runOnFunction(Function &F);
31 };
32
33 Pass *createUnifyFunctionExitNodesPass();
34
35 #endif