Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 1 | //===--- llvm/CodeGen/WasmEHFuncInfo.h --------------------------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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 |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 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 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 16 | #include "llvm/ADT/DenseMap.h" |
Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/PointerUnion.h" |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 18 | |
| 19 | namespace llvm { |
| 20 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 21 | class BasicBlock; |
| 22 | class Function; |
| 23 | class MachineBasicBlock; |
| 24 | |
| 25 | namespace WebAssembly { |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 26 | enum EventTag { CPP_EXCEPTION = 0, C_LONGJMP = 1 }; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 27 | } |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 28 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 29 | using BBOrMBB = PointerUnion<const BasicBlock *, MachineBasicBlock *>; |
| 30 | |
| 31 | struct WasmEHFuncInfo { |
| 32 | // When there is an entry <A, B>, if an exception is not caught by A, it |
| 33 | // should next unwind to the EH pad B. |
| 34 | DenseMap<BBOrMBB, BBOrMBB> EHPadUnwindMap; |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 35 | |
| 36 | // Helper functions |
| 37 | const BasicBlock *getEHPadUnwindDest(const BasicBlock *BB) const { |
| 38 | return EHPadUnwindMap.lookup(BB).get<const BasicBlock *>(); |
| 39 | } |
| 40 | void setEHPadUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) { |
| 41 | EHPadUnwindMap[BB] = Dest; |
| 42 | } |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 43 | bool hasEHPadUnwindDest(const BasicBlock *BB) const { |
| 44 | return EHPadUnwindMap.count(BB); |
| 45 | } |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 46 | |
| 47 | MachineBasicBlock *getEHPadUnwindDest(MachineBasicBlock *MBB) const { |
| 48 | return EHPadUnwindMap.lookup(MBB).get<MachineBasicBlock *>(); |
| 49 | } |
| 50 | void setEHPadUnwindDest(MachineBasicBlock *MBB, MachineBasicBlock *Dest) { |
| 51 | EHPadUnwindMap[MBB] = Dest; |
| 52 | } |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 53 | bool hasEHPadUnwindDest(MachineBasicBlock *MBB) const { |
| 54 | return EHPadUnwindMap.count(MBB); |
| 55 | } |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | // Analyze the IR in the given function to build WasmEHFuncInfo. |
| 59 | void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo); |
| 60 | |
| 61 | } // namespace llvm |
| 62 | |
| 63 | #endif // LLVM_CODEGEN_WASMEHFUNCINFO_H |