blob: 54e8c40a9e723744fe9d8364f2832766b0f7ee69 [file] [log] [blame]
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001//===--- llvm/CodeGen/WasmEHFuncInfo.h --------------------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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 Scullcdfcccc2018-10-05 20:58:37 +01006//
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 Scullcdfcccc2018-10-05 20:58:37 +010016#include "llvm/ADT/DenseMap.h"
Andrew Scull0372a572018-11-16 15:47:06 +000017#include "llvm/ADT/PointerUnion.h"
Andrew Scullcdfcccc2018-10-05 20:58:37 +010018
19namespace llvm {
20
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020021class BasicBlock;
22class Function;
23class MachineBasicBlock;
24
25namespace WebAssembly {
Andrew Walbran16937d02019-10-22 13:54:20 +010026enum EventTag { CPP_EXCEPTION = 0, C_LONGJMP = 1 };
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020027}
Andrew Walbran16937d02019-10-22 13:54:20 +010028
Andrew Scullcdfcccc2018-10-05 20:58:37 +010029using BBOrMBB = PointerUnion<const BasicBlock *, MachineBasicBlock *>;
30
31struct 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 Scullcdfcccc2018-10-05 20:58:37 +010035
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 Scullcdfcccc2018-10-05 20:58:37 +010043 bool hasEHPadUnwindDest(const BasicBlock *BB) const {
44 return EHPadUnwindMap.count(BB);
45 }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010046
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 Scullcdfcccc2018-10-05 20:58:37 +010053 bool hasEHPadUnwindDest(MachineBasicBlock *MBB) const {
54 return EHPadUnwindMap.count(MBB);
55 }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010056};
57
58// Analyze the IR in the given function to build WasmEHFuncInfo.
59void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo);
60
61} // namespace llvm
62
63#endif // LLVM_CODEGEN_WASMEHFUNCINFO_H