LLVM API Documentation

UnifyFunctionExitNodes.h
Go to the documentation of this file.
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_UTILS_UNIFYFUNCTIONEXITNODES_H
00019 #define LLVM_TRANSFORMS_UTILS_UNIFYFUNCTIONEXITNODES_H
00020 
00021 #include "llvm/Pass.h"
00022 
00023 namespace llvm {
00024 
00025 struct UnifyFunctionExitNodes : public FunctionPass {
00026   BasicBlock *ReturnBlock, *UnwindBlock, *UnreachableBlock;
00027 
00028 public:
00029   static char ID; // Pass identification, replacement for typeid
00030   UnifyFunctionExitNodes() : FunctionPass(ID),
00031                              ReturnBlock(nullptr), UnwindBlock(nullptr) {
00032     initializeUnifyFunctionExitNodesPass(*PassRegistry::getPassRegistry());
00033   }
00034 
00035   // We can preserve non-critical-edgeness when we unify function exit nodes
00036   void getAnalysisUsage(AnalysisUsage &AU) const override;
00037 
00038   // getReturn|Unwind|UnreachableBlock - Return the new single (or nonexistent)
00039   // return, unwind, or unreachable  basic blocks in the CFG.
00040   //
00041   BasicBlock *getReturnBlock() const { return ReturnBlock; }
00042   BasicBlock *getUnwindBlock() const { return UnwindBlock; }
00043   BasicBlock *getUnreachableBlock() const { return UnreachableBlock; }
00044 
00045   bool runOnFunction(Function &F) override;
00046 };
00047 
00048 Pass *createUnifyFunctionExitNodesPass();
00049 
00050 } // End llvm namespace
00051 
00052 #endif