1 //===-- UnifyFunctionExitNodes.h - Ensure fn's have one return ---*- C++ -*--=//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_XFORMS_UNIFY_FUNCTION_EXIT_NODES_H
10 #define LLVM_XFORMS_UNIFY_FUNCTION_EXIT_NODES_H
12 #include "llvm/Pass.h"
14 struct UnifyFunctionExitNodes : public FunctionPass {
17 static AnalysisID ID; // Pass ID
18 UnifyFunctionExitNodes(AnalysisID id = ID) : ExitNode(0) { assert(ID == id); }
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.
24 // If there are no return stmts in the function, a null pointer is returned.
26 static bool doit(Function *F, BasicBlock *&ExitNode);
29 virtual bool runOnFunction(Function *F) {
30 return doit(F, ExitNode);
33 BasicBlock *getExitNode() const { return ExitNode; }
35 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
36 AU.addProvided(ID); // Provide self!
40 static inline Pass *createUnifyFunctionExitNodesPass() {
41 return new UnifyFunctionExitNodes();