LLVM  11.0.0git
UnifyFunctionExitNodes.h
Go to the documentation of this file.
1 //===-- UnifyFunctionExitNodes.h - Ensure fn's have one return --*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass is used to ensure that functions have at most one return and one
10 // unwind instruction in them. Additionally, it keeps track of which node is
11 // the new exit node of the CFG. If there are no return or unwind instructions
12 // in the function, the getReturnBlock/getUnwindBlock methods will return a null
13 // pointer.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_TRANSFORMS_UTILS_UNIFYFUNCTIONEXITNODES_H
18 #define LLVM_TRANSFORMS_UTILS_UNIFYFUNCTIONEXITNODES_H
19 
20 #include "llvm/Pass.h"
21 
22 namespace llvm {
23 
24 class BasicBlock;
25 
27  BasicBlock *ReturnBlock = nullptr;
28  BasicBlock *UnwindBlock = nullptr;
30 
31 public:
32  static char ID; // Pass identification, replacement for typeid
34 
35  // We can preserve non-critical-edgeness when we unify function exit nodes
36  void getAnalysisUsage(AnalysisUsage &AU) const override;
37 
38  // getReturn|Unwind|UnreachableBlock - Return the new single (or nonexistent)
39  // return, unwind, or unreachable basic blocks in the CFG.
40  //
41  BasicBlock *getReturnBlock() const { return ReturnBlock; }
42  BasicBlock *getUnwindBlock() const { return UnwindBlock; }
44 
45  bool runOnFunction(Function &F) override;
46 };
47 
49 
50 } // end namespace llvm
51 
52 #endif // LLVM_TRANSFORMS_UTILS_UNIFYFUNCTIONEXITNODES_H
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:77
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Various leaf nodes.
Definition: ISDOpcodes.h:63
F(f)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Pass * createUnifyFunctionExitNodesPass()
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:281
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
BasicBlock * getUnreachableBlock() const