[Alignment][NFC] Migrate Instructions to Align
[llvm-core.git] / include / llvm / Transforms / Utils / EscapeEnumerator.h
blobe667796c841bc1ab4012940afa5528a36d005e42
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.
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"
20 namespace llvm {
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;
31 Function::iterator StateBB, StateE;
32 IRBuilder<> Builder;
33 bool Done;
34 bool HandleExceptions;
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) {}
43 IRBuilder<> *Next();
48 #endif // LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H