1 //===-- UnifyMethodExitNodes.h - Ensure methods have one return --*- C++ -*--=//
3 // This pass is used to ensure that methods have at most one return instruction
4 // in them. It also holds onto the return instruction of the last unified
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_XFORMS_UNIFY_METHOD_EXIT_NODES_H
10 #define LLVM_XFORMS_UNIFY_METHOD_EXIT_NODES_H
12 #include "llvm/Pass.h"
14 struct UnifyMethodExitNodes : public MethodPass {
17 static AnalysisID ID; // Pass ID
18 UnifyMethodExitNodes(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 Method, a null pointer is returned.
26 static bool doit(Method *M, BasicBlock *&ExitNode);
29 virtual bool runOnMethod(Method *M) {
30 return doit(M, ExitNode);
33 BasicBlock *getExitNode() const { return ExitNode; }
35 virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required,
36 Pass::AnalysisSet &Destroyed,
37 Pass::AnalysisSet &Provided) {
38 // FIXME: Should invalidate CFG
39 Provided.push_back(ID); // Provide self!
43 static inline Pass *createUnifyMethodExitNodesPass() {
44 return new UnifyMethodExitNodes();