]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/include/llvm/CodeGen/WasmEHFuncInfo.h
MFV r368464:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / include / llvm / CodeGen / WasmEHFuncInfo.h
1 //===--- llvm/CodeGen/WasmEHFuncInfo.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 // Data structures for Wasm exception handling schemes.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_CODEGEN_WASMEHFUNCINFO_H
14 #define LLVM_CODEGEN_WASMEHFUNCINFO_H
15
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/PointerUnion.h"
18
19 namespace llvm {
20
21 class BasicBlock;
22 class Function;
23 class MachineBasicBlock;
24
25 enum EventTag { CPP_EXCEPTION = 0, C_LONGJMP = 1 };
26
27 using BBOrMBB = PointerUnion<const BasicBlock *, MachineBasicBlock *>;
28
29 struct WasmEHFuncInfo {
30   // When there is an entry <A, B>, if an exception is not caught by A, it
31   // should next unwind to the EH pad B.
32   DenseMap<BBOrMBB, BBOrMBB> EHPadUnwindMap;
33
34   // Helper functions
35   const BasicBlock *getEHPadUnwindDest(const BasicBlock *BB) const {
36     return EHPadUnwindMap.lookup(BB).get<const BasicBlock *>();
37   }
38   void setEHPadUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) {
39     EHPadUnwindMap[BB] = Dest;
40   }
41   bool hasEHPadUnwindDest(const BasicBlock *BB) const {
42     return EHPadUnwindMap.count(BB);
43   }
44
45   MachineBasicBlock *getEHPadUnwindDest(MachineBasicBlock *MBB) const {
46     return EHPadUnwindMap.lookup(MBB).get<MachineBasicBlock *>();
47   }
48   void setEHPadUnwindDest(MachineBasicBlock *MBB, MachineBasicBlock *Dest) {
49     EHPadUnwindMap[MBB] = Dest;
50   }
51   bool hasEHPadUnwindDest(MachineBasicBlock *MBB) const {
52     return EHPadUnwindMap.count(MBB);
53   }
54 };
55
56 // Analyze the IR in the given function to build WasmEHFuncInfo.
57 void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo);
58
59 } // namespace llvm
60
61 #endif // LLVM_CODEGEN_WASMEHFUNCINFO_H