blob: 887a1467b3e49f439664ed3a01e4a92b66a807a6 [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;
Andrew Scullcdfcccc2018-10-05 20:58:37 +010031
32 // Helper functions
33 const BasicBlock *getEHPadUnwindDest(const BasicBlock *BB) const {
34 return EHPadUnwindMap.lookup(BB).get<const BasicBlock *>();
35 }
36 void setEHPadUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) {
37 EHPadUnwindMap[BB] = Dest;
38 }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010039 bool hasEHPadUnwindDest(const BasicBlock *BB) const {
40 return EHPadUnwindMap.count(BB);
41 }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010042
43 MachineBasicBlock *getEHPadUnwindDest(MachineBasicBlock *MBB) const {
44 return EHPadUnwindMap.lookup(MBB).get<MachineBasicBlock *>();
45 }
46 void setEHPadUnwindDest(MachineBasicBlock *MBB, MachineBasicBlock *Dest) {
47 EHPadUnwindMap[MBB] = Dest;
48 }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010049 bool hasEHPadUnwindDest(MachineBasicBlock *MBB) const {
50 return EHPadUnwindMap.count(MBB);
51 }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010052};
53
54// Analyze the IR in the given function to build WasmEHFuncInfo.
55void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo);
56
57} // namespace llvm
58
59#endif // LLVM_CODEGEN_WASMEHFUNCINFO_H