1 //===--- llvm/CodeGen/WasmEHFuncInfo.h --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Data structures for Wasm exception handling schemes.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_WASMEHFUNCINFO_H
15 #define LLVM_CODEGEN_WASMEHFUNCINFO_H
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/PointerUnion.h"
19 #include "llvm/CodeGen/MachineBasicBlock.h"
20 #include "llvm/IR/BasicBlock.h"
24 enum EventTag { CPP_EXCEPTION = 0, C_LONGJMP = 1 };
26 using BBOrMBB = PointerUnion<const BasicBlock *, MachineBasicBlock *>;
28 struct WasmEHFuncInfo {
29 // When there is an entry <A, B>, if an exception is not caught by A, it
30 // should next unwind to the EH pad B.
31 DenseMap<BBOrMBB, BBOrMBB> EHPadUnwindMap;
32 // For entry <A, B>, A is a BB with an instruction that may throw
33 // (invoke/cleanupret in LLVM IR, call/rethrow in the backend) and B is an EH
34 // pad that A unwinds to.
35 DenseMap<BBOrMBB, BBOrMBB> ThrowUnwindMap;
38 const BasicBlock *getEHPadUnwindDest(const BasicBlock *BB) const {
39 return EHPadUnwindMap.lookup(BB).get<const BasicBlock *>();
41 void setEHPadUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) {
42 EHPadUnwindMap[BB] = Dest;
44 const BasicBlock *getThrowUnwindDest(BasicBlock *BB) const {
45 return ThrowUnwindMap.lookup(BB).get<const BasicBlock *>();
47 void setThrowUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) {
48 ThrowUnwindMap[BB] = Dest;
50 bool hasEHPadUnwindDest(const BasicBlock *BB) const {
51 return EHPadUnwindMap.count(BB);
53 bool hasThrowUnwindDest(const BasicBlock *BB) const {
54 return ThrowUnwindMap.count(BB);
57 MachineBasicBlock *getEHPadUnwindDest(MachineBasicBlock *MBB) const {
58 return EHPadUnwindMap.lookup(MBB).get<MachineBasicBlock *>();
60 void setEHPadUnwindDest(MachineBasicBlock *MBB, MachineBasicBlock *Dest) {
61 EHPadUnwindMap[MBB] = Dest;
63 MachineBasicBlock *getThrowUnwindDest(MachineBasicBlock *MBB) const {
64 return ThrowUnwindMap.lookup(MBB).get<MachineBasicBlock *>();
66 void setThrowUnwindDest(MachineBasicBlock *MBB, MachineBasicBlock *Dest) {
67 ThrowUnwindMap[MBB] = Dest;
69 bool hasEHPadUnwindDest(MachineBasicBlock *MBB) const {
70 return EHPadUnwindMap.count(MBB);
72 bool hasThrowUnwindDest(MachineBasicBlock *MBB) const {
73 return ThrowUnwindMap.count(MBB);
77 // Analyze the IR in the given function to build WasmEHFuncInfo.
78 void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo);
82 #endif // LLVM_CODEGEN_WASMEHFUNCINFO_H