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 class DomTreeUpdater; 23 24 /// EscapeEnumerator - This is a little algorithm to find all escape points 25 /// from a function so that "finally"-style code can be inserted. In addition 26 /// to finding the existing return and unwind instructions, it also (if 27 /// necessary) transforms any call instructions into invokes and sends them to 28 /// a landing pad. 29 class EscapeEnumerator { 30 Function &F; 31 const char *CleanupBBName; 32 33 Function::iterator StateBB, StateE; 34 IRBuilder<> Builder; 35 bool Done; 36 bool HandleExceptions; 37 38 DomTreeUpdater *DTU; 39 40 public: 41 EscapeEnumerator(Function &F, const char *N = "cleanup", 42 bool HandleExceptions = true, DomTreeUpdater *DTU = nullptr) F(F)43 : F(F), CleanupBBName(N), StateBB(F.begin()), StateE(F.end()), 44 Builder(F.getContext()), Done(false), 45 HandleExceptions(HandleExceptions), DTU(DTU) {} 46 47 IRBuilder<> *Next(); 48 }; 49 50 } 51 52 #endif // LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H 53