blob: aaca8474349ab0dc251607418e3d82e5853fcaa9 [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#include "llvm/CodeGen/MachineBasicBlock.h"
19#include "llvm/IR/BasicBlock.h"
20
21namespace llvm {
22
Andrew Walbran16937d02019-10-22 13:54:20 +010023enum EventTag { CPP_EXCEPTION = 0, C_LONGJMP = 1 };
24
Andrew Scullcdfcccc2018-10-05 20:58:37 +010025using BBOrMBB = PointerUnion<const BasicBlock *, MachineBasicBlock *>;
26
27struct WasmEHFuncInfo {
28 // When there is an entry <A, B>, if an exception is not caught by A, it
29 // should next unwind to the EH pad B.
30 DenseMap<BBOrMBB, BBOrMBB> EHPadUnwindMap;
31 // For entry <A, B>, A is a BB with an instruction that may throw
32 // (invoke/cleanupret in LLVM IR, call/rethrow in the backend) and B is an EH
33 // pad that A unwinds to.
34 DenseMap<BBOrMBB, BBOrMBB> ThrowUnwindMap;
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 }
43 const BasicBlock *getThrowUnwindDest(BasicBlock *BB) const {
44 return ThrowUnwindMap.lookup(BB).get<const BasicBlock *>();
45 }
46 void setThrowUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) {
47 ThrowUnwindMap[BB] = Dest;
48 }
49 bool hasEHPadUnwindDest(const BasicBlock *BB) const {
50 return EHPadUnwindMap.count(BB);
51 }
52 bool hasThrowUnwindDest(const BasicBlock *BB) const {
53 return ThrowUnwindMap.count(BB);
54 }
55
56 MachineBasicBlock *getEHPadUnwindDest(MachineBasicBlock *MBB) const {
57 return EHPadUnwindMap.lookup(MBB).get<MachineBasicBlock *>();
58 }
59 void setEHPadUnwindDest(MachineBasicBlock *MBB, MachineBasicBlock *Dest) {
60 EHPadUnwindMap[MBB] = Dest;
61 }
62 MachineBasicBlock *getThrowUnwindDest(MachineBasicBlock *MBB) const {
63 return ThrowUnwindMap.lookup(MBB).get<MachineBasicBlock *>();
64 }
65 void setThrowUnwindDest(MachineBasicBlock *MBB, MachineBasicBlock *Dest) {
66 ThrowUnwindMap[MBB] = Dest;
67 }
68 bool hasEHPadUnwindDest(MachineBasicBlock *MBB) const {
69 return EHPadUnwindMap.count(MBB);
70 }
71 bool hasThrowUnwindDest(MachineBasicBlock *MBB) const {
72 return ThrowUnwindMap.count(MBB);
73 }
74};
75
76// Analyze the IR in the given function to build WasmEHFuncInfo.
77void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo);
78
79} // namespace llvm
80
81#endif // LLVM_CODEGEN_WASMEHFUNCINFO_H