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
20namespace llvm {
21
22class 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.
29class EscapeEnumerator {
30 Function &F;
31 const char *CleanupBBName;
32
33 Function::iterator StateBB, StateE;
34 IRBuilder<> Builder;
35 bool Done = false;
36 bool HandleExceptions;
37
38 DomTreeUpdater *DTU;
39
40public:
41 EscapeEnumerator(Function &F, const char *N = "cleanup",
42 bool HandleExceptions = true, DomTreeUpdater *DTU = nullptr)
43 : F(F), CleanupBBName(N), StateBB(F.begin()), StateE(F.end()),
44 Builder(F.getContext()), HandleExceptions(HandleExceptions), DTU(DTU) {}
45
46 IRBuilder<> *Next();
47};
48
49}
50
51#endif // LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H
52

source code of llvm/include/llvm/Transforms/Utils/EscapeEnumerator.h