1 //===-- EscapeEnumerator.h --------------------------------------*- 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 // Defines a helper class that enumerates all possible exits from a function, 10 // including exception handling. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H 15 #define LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H 16 17 #include "llvm/IR/Function.h" 18 #include "llvm/IR/IRBuilder.h" 19 20 namespace llvm { 21 22 /// EscapeEnumerator - This is a little algorithm to find all escape points 23 /// from a function so that "finally"-style code can be inserted. In addition 24 /// to finding the existing return and unwind instructions, it also (if 25 /// necessary) transforms any call instructions into invokes and sends them to 26 /// a landing pad. 27 class EscapeEnumerator { 28 Function &F; 29 const char *CleanupBBName; 30 31 Function::iterator StateBB, StateE; 32 IRBuilder<> Builder; 33 bool Done; 34 bool HandleExceptions; 35 36 public: 37 EscapeEnumerator(Function &F, const char *N = "cleanup", 38 bool HandleExceptions = true) 39 : F(F), CleanupBBName(N), StateBB(F.begin()), StateE(F.end()), 40 Builder(F.getContext()), Done(false), 41 HandleExceptions(HandleExceptions) {} 42 43 IRBuilder<> *Next(); 44 }; 45 46 } 47 48 #endif // LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H 49