blob: aa979349edfd01a493f81148f487267676d7b192 [file] [log] [blame]
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001//===--- llvm/CodeGen/WasmEHFuncInfo.h --------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Data structures for Wasm exception handling schemes.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CODEGEN_WASMEHFUNCINFO_H
15#define LLVM_CODEGEN_WASMEHFUNCINFO_H
16
Andrew Scullcdfcccc2018-10-05 20:58:37 +010017#include "llvm/ADT/DenseMap.h"
Andrew Scull0372a572018-11-16 15:47:06 +000018#include "llvm/ADT/PointerUnion.h"
Andrew Scullcdfcccc2018-10-05 20:58:37 +010019#include "llvm/CodeGen/MachineBasicBlock.h"
20#include "llvm/IR/BasicBlock.h"
21
22namespace llvm {
23
24using BBOrMBB = PointerUnion<const BasicBlock *, MachineBasicBlock *>;
25
26struct WasmEHFuncInfo {
27 // When there is an entry <A, B>, if an exception is not caught by A, it
28 // should next unwind to the EH pad B.
29 DenseMap<BBOrMBB, BBOrMBB> EHPadUnwindMap;
30 // For entry <A, B>, A is a BB with an instruction that may throw
31 // (invoke/cleanupret in LLVM IR, call/rethrow in the backend) and B is an EH
32 // pad that A unwinds to.
33 DenseMap<BBOrMBB, BBOrMBB> ThrowUnwindMap;
34
35 // Helper functions
36 const BasicBlock *getEHPadUnwindDest(const BasicBlock *BB) const {
37 return EHPadUnwindMap.lookup(BB).get<const BasicBlock *>();
38 }
39 void setEHPadUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) {
40 EHPadUnwindMap[BB] = Dest;
41 }
42 const BasicBlock *getThrowUnwindDest(BasicBlock *BB) const {
43 return ThrowUnwindMap.lookup(BB).get<const BasicBlock *>();
44 }
45 void setThrowUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) {
46 ThrowUnwindMap[BB] = Dest;
47 }
48 bool hasEHPadUnwindDest(const BasicBlock *BB) const {
49 return EHPadUnwindMap.count(BB);
50 }
51 bool hasThrowUnwindDest(const BasicBlock *BB) const {
52 return ThrowUnwindMap.count(BB);
53 }
54
55 MachineBasicBlock *getEHPadUnwindDest(MachineBasicBlock *MBB) const {
56 return EHPadUnwindMap.lookup(MBB).get<MachineBasicBlock *>();
57 }
58 void setEHPadUnwindDest(MachineBasicBlock *MBB, MachineBasicBlock *Dest) {
59 EHPadUnwindMap[MBB] = Dest;
60 }
61 MachineBasicBlock *getThrowUnwindDest(MachineBasicBlock *MBB) const {
62 return ThrowUnwindMap.lookup(MBB).get<MachineBasicBlock *>();
63 }
64 void setThrowUnwindDest(MachineBasicBlock *MBB, MachineBasicBlock *Dest) {
65 ThrowUnwindMap[MBB] = Dest;
66 }
67 bool hasEHPadUnwindDest(MachineBasicBlock *MBB) const {
68 return EHPadUnwindMap.count(MBB);
69 }
70 bool hasThrowUnwindDest(MachineBasicBlock *MBB) const {
71 return ThrowUnwindMap.count(MBB);
72 }
73};
74
75// Analyze the IR in the given function to build WasmEHFuncInfo.
76void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo);
77
78} // namespace llvm
79
80#endif // LLVM_CODEGEN_WASMEHFUNCINFO_H