LLVM API Documentation
00001 //===-- UnifyFunctionExitNodes.h - Ensure fn's have one return --*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This pass is used to ensure that functions have at most one return and one 00011 // unwind instruction in them. Additionally, it keeps track of which node is 00012 // the new exit node of the CFG. If there are no return or unwind instructions 00013 // in the function, the getReturnBlock/getUnwindBlock methods will return a null 00014 // pointer. 00015 // 00016 //===----------------------------------------------------------------------===// 00017 00018 #ifndef LLVM_TRANSFORMS_UNIFYFUNCTIONEXITNODES_H 00019 #define LLVM_TRANSFORMS_UNIFYFUNCTIONEXITNODES_H 00020 00021 #include "llvm/Pass.h" 00022 00023 namespace llvm { 00024 00025 struct UnifyFunctionExitNodes : public FunctionPass { 00026 BasicBlock *ReturnBlock, *UnwindBlock, *UnreachableBlock; 00027 public: 00028 static char ID; // Pass identification, replacement for typeid 00029 UnifyFunctionExitNodes() : FunctionPass(ID), 00030 ReturnBlock(0), UnwindBlock(0) { 00031 initializeUnifyFunctionExitNodesPass(*PassRegistry::getPassRegistry()); 00032 } 00033 00034 // We can preserve non-critical-edgeness when we unify function exit nodes 00035 virtual void getAnalysisUsage(AnalysisUsage &AU) const; 00036 00037 // getReturn|Unwind|UnreachableBlock - Return the new single (or nonexistant) 00038 // return, unwind, or unreachable basic blocks in the CFG. 00039 // 00040 BasicBlock *getReturnBlock() const { return ReturnBlock; } 00041 BasicBlock *getUnwindBlock() const { return UnwindBlock; } 00042 BasicBlock *getUnreachableBlock() const { return UnreachableBlock; } 00043 00044 virtual bool runOnFunction(Function &F); 00045 }; 00046 00047 Pass *createUnifyFunctionExitNodesPass(); 00048 00049 } // End llvm namespace 00050 00051 #endif