1 //===-- EscapeEnumerator.h --------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // Defines a helper class that enumerates all possible exits from a function,
10 // including exception handling.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H
15 #define LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H
17 #include "llvm/IR/Function.h"
18 #include "llvm/IR/IRBuilder.h"
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
27 class EscapeEnumerator
{
29 const char *CleanupBBName
;
31 Function::iterator StateBB
, StateE
;
34 bool HandleExceptions
;
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
) {}
48 #endif // LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H