1 //===-- UnifyFunctionExitNodes.h - Ensure fn's have one return --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This pass is used to ensure that functions have at most one return and one
11 // unwind instruction in them. Additionally, it keeps track of which node is
12 // the new exit node of the CFG. If there are no return or unwind instructions
13 // in the function, the getReturnBlock/getUnwindBlock methods will return a null
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_TRANSFORMS_UNIFYFUNCTIONEXITNODES_H
19 #define LLVM_TRANSFORMS_UNIFYFUNCTIONEXITNODES_H
21 #include "llvm/Pass.h"
25 struct UnifyFunctionExitNodes : public FunctionPass {
26 BasicBlock *ReturnBlock, *UnwindBlock, *UnreachableBlock;
28 UnifyFunctionExitNodes() : ReturnBlock(0), UnwindBlock(0) {}
30 // We can preserve non-critical-edgeness when we unify function exit nodes
31 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
33 // getReturn|Unwind|UnreachableBlock - Return the new single (or nonexistant)
34 // return, unwind, or unreachable basic blocks in the CFG.
36 BasicBlock *getReturnBlock() const { return ReturnBlock; }
37 BasicBlock *getUnwindBlock() const { return UnwindBlock; }
38 BasicBlock *getUnreachableBlock() const { return UnreachableBlock; }
40 virtual bool runOnFunction(Function &F);
43 Pass *createUnifyFunctionExitNodesPass();
45 } // End llvm namespace