1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===-- UnifyFunctionExitNodes.h - Ensure fn's have one return --*- C++ -*-===//
2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//                     The LLVM Compiler Infrastructure
4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source
6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details.
7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===//
9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This pass is used to ensure that functions have at most one return and one
11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// unwind instruction in them.  Additionally, it keeps track of which node is
12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// the new exit node of the CFG.  If there are no return or unwind instructions
13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// in the function, the getReturnBlock/getUnwindBlock methods will return a null
14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// pointer.
15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===//
17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef LLVM_TRANSFORMS_UNIFYFUNCTIONEXITNODES_H
19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define LLVM_TRANSFORMS_UNIFYFUNCTIONEXITNODES_H
20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Pass.h"
22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm {
24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanstruct UnifyFunctionExitNodes : public FunctionPass {
2619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  BasicBlock *ReturnBlock, *UnwindBlock, *UnreachableBlock;
27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanpublic:
28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  static char ID; // Pass identification, replacement for typeid
29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  UnifyFunctionExitNodes() : FunctionPass(ID),
3019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                             ReturnBlock(0), UnwindBlock(0) {
3119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    initializeUnifyFunctionExitNodesPass(*PassRegistry::getPassRegistry());
3219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  }
33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // We can preserve non-critical-edgeness when we unify function exit nodes
35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual void getAnalysisUsage(AnalysisUsage &AU) const;
36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // getReturn|Unwind|UnreachableBlock - Return the new single (or nonexistant)
38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // return, unwind, or unreachable  basic blocks in the CFG.
39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  //
40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  BasicBlock *getReturnBlock() const { return ReturnBlock; }
4119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  BasicBlock *getUnwindBlock() const { return UnwindBlock; }
42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  BasicBlock *getUnreachableBlock() const { return UnreachableBlock; }
43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual bool runOnFunction(Function &F);
45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman};
46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John BaumanPass *createUnifyFunctionExitNodesPass();
48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} // End llvm namespace
50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif
52