1311116Sdim//===-- EscapeEnumerator.h --------------------------------------*- C++ -*-===// 2311116Sdim// 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 6311116Sdim// 7311116Sdim//===----------------------------------------------------------------------===// 8311116Sdim// 9311116Sdim// Defines a helper class that enumerates all possible exits from a function, 10311116Sdim// including exception handling. 11311116Sdim// 12311116Sdim//===----------------------------------------------------------------------===// 13311116Sdim 14311116Sdim#ifndef LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H 15311116Sdim#define LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H 16311116Sdim 17321369Sdim#include "llvm/IR/Function.h" 18311116Sdim#include "llvm/IR/IRBuilder.h" 19311116Sdim 20311116Sdimnamespace llvm { 21311116Sdim 22311116Sdim/// EscapeEnumerator - This is a little algorithm to find all escape points 23311116Sdim/// from a function so that "finally"-style code can be inserted. In addition 24311116Sdim/// to finding the existing return and unwind instructions, it also (if 25311116Sdim/// necessary) transforms any call instructions into invokes and sends them to 26311116Sdim/// a landing pad. 27311116Sdimclass EscapeEnumerator { 28311116Sdim Function &F; 29311116Sdim const char *CleanupBBName; 30311116Sdim 31311116Sdim Function::iterator StateBB, StateE; 32311116Sdim IRBuilder<> Builder; 33311116Sdim bool Done; 34311116Sdim bool HandleExceptions; 35311116Sdim 36311116Sdimpublic: 37311116Sdim EscapeEnumerator(Function &F, const char *N = "cleanup", 38311116Sdim bool HandleExceptions = true) 39311116Sdim : F(F), CleanupBBName(N), StateBB(F.begin()), StateE(F.end()), 40311116Sdim Builder(F.getContext()), Done(false), 41311116Sdim HandleExceptions(HandleExceptions) {} 42311116Sdim 43311116Sdim IRBuilder<> *Next(); 44311116Sdim}; 45311116Sdim 46311116Sdim} 47311116Sdim 48311116Sdim#endif // LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H 49