[InstCombine] Signed saturation patterns
[llvm-core.git] / include / llvm / Transforms / Utils / UnifyFunctionExitNodes.h
blobf68534ecd2ebbf616dc4e75ded8c61b93affae0c
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.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_TRANSFORMS_UTILS_UNIFYFUNCTIONEXITNODES_H
18 #define LLVM_TRANSFORMS_UTILS_UNIFYFUNCTIONEXITNODES_H
20 #include "llvm/Pass.h"
21 #include "llvm/PassRegistry.h"
23 namespace llvm {
25 struct UnifyFunctionExitNodes : public FunctionPass {
26 BasicBlock *ReturnBlock = nullptr;
27 BasicBlock *UnwindBlock = nullptr;
28 BasicBlock *UnreachableBlock;
30 public:
31 static char ID; // Pass identification, replacement for typeid
32 UnifyFunctionExitNodes() : FunctionPass(ID) {
33 initializeUnifyFunctionExitNodesPass(*PassRegistry::getPassRegistry());
36 // We can preserve non-critical-edgeness when we unify function exit nodes
37 void getAnalysisUsage(AnalysisUsage &AU) const override;
39 // getReturn|Unwind|UnreachableBlock - Return the new single (or nonexistent)
40 // return, unwind, or unreachable basic blocks in the CFG.
42 BasicBlock *getReturnBlock() const { return ReturnBlock; }
43 BasicBlock *getUnwindBlock() const { return UnwindBlock; }
44 BasicBlock *getUnreachableBlock() const { return UnreachableBlock; }
46 bool runOnFunction(Function &F) override;
49 Pass *createUnifyFunctionExitNodesPass();
51 } // end namespace llvm
53 #endif // LLVM_TRANSFORMS_UTILS_UNIFYFUNCTIONEXITNODES_H