1193323Sed//===-- UnifyFunctionExitNodes.h - Ensure fn's have one return --*- C++ -*-===// 2193323Sed// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6193323Sed// 7193323Sed//===----------------------------------------------------------------------===// 8193323Sed// 9193323Sed// This pass is used to ensure that functions have at most one return and one 10193323Sed// unwind instruction in them. Additionally, it keeps track of which node is 11193323Sed// the new exit node of the CFG. If there are no return or unwind instructions 12193323Sed// in the function, the getReturnBlock/getUnwindBlock methods will return a null 13193323Sed// pointer. 14193323Sed// 15193323Sed//===----------------------------------------------------------------------===// 16193323Sed 17280031Sdim#ifndef LLVM_TRANSFORMS_UTILS_UNIFYFUNCTIONEXITNODES_H 18280031Sdim#define LLVM_TRANSFORMS_UTILS_UNIFYFUNCTIONEXITNODES_H 19193323Sed 20193323Sed#include "llvm/Pass.h" 21321369Sdim#include "llvm/PassRegistry.h" 22193323Sed 23193323Sednamespace llvm { 24193323Sed 25193323Sedstruct UnifyFunctionExitNodes : public FunctionPass { 26321369Sdim BasicBlock *ReturnBlock = nullptr; 27321369Sdim BasicBlock *UnwindBlock = nullptr; 28321369Sdim BasicBlock *UnreachableBlock; 29276479Sdim 30193323Sedpublic: 31193323Sed static char ID; // Pass identification, replacement for typeid 32360784Sdim UnifyFunctionExitNodes(); 33193323Sed 34193323Sed // We can preserve non-critical-edgeness when we unify function exit nodes 35276479Sdim void getAnalysisUsage(AnalysisUsage &AU) const override; 36193323Sed 37261991Sdim // getReturn|Unwind|UnreachableBlock - Return the new single (or nonexistent) 38193323Sed // return, unwind, or unreachable basic blocks in the CFG. 39193323Sed // 40193323Sed BasicBlock *getReturnBlock() const { return ReturnBlock; } 41193323Sed BasicBlock *getUnwindBlock() const { return UnwindBlock; } 42193323Sed BasicBlock *getUnreachableBlock() const { return UnreachableBlock; } 43193323Sed 44276479Sdim bool runOnFunction(Function &F) override; 45193323Sed}; 46193323Sed 47193323SedPass *createUnifyFunctionExitNodesPass(); 48193323Sed 49321369Sdim} // end namespace llvm 50193323Sed 51321369Sdim#endif // LLVM_TRANSFORMS_UTILS_UNIFYFUNCTIONEXITNODES_H 52