LLVM 20.0.0git
WasmEHFuncInfo.h
Go to the documentation of this file.
1//===--- llvm/CodeGen/WasmEHFuncInfo.h --------------------------*- C++ -*-===//
2//
3// 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
6//
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
16#include "llvm/ADT/DenseMap.h"
19
20namespace llvm {
21
22class BasicBlock;
23class Function;
24class MachineBasicBlock;
25
26namespace WebAssembly {
27enum Tag { CPP_EXCEPTION = 0, C_LONGJMP = 1 };
28}
29
31
33 // When there is an entry <A, B>, if an exception is not caught by A, it
34 // should next unwind to the EH pad B.
37
38 // Helper functions
39 const BasicBlock *getUnwindDest(const BasicBlock *BB) const {
41 return cast<const BasicBlock *>(SrcToUnwindDest.lookup(BB));
42 }
45 const auto &Set = UnwindDestToSrcs.lookup(BB);
47 for (const auto P : Set)
48 Ret.insert(cast<const BasicBlock *>(P));
49 return Ret;
50 }
51 void setUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) {
52 SrcToUnwindDest[BB] = Dest;
53 UnwindDestToSrcs[Dest].insert(BB);
54 }
55 bool hasUnwindDest(const BasicBlock *BB) const {
56 return SrcToUnwindDest.count(BB);
57 }
58 bool hasUnwindSrcs(const BasicBlock *BB) const {
59 return UnwindDestToSrcs.count(BB);
60 }
61
64 return cast<MachineBasicBlock *>(SrcToUnwindDest.lookup(MBB));
65 }
69 const auto &Set = UnwindDestToSrcs.lookup(MBB);
71 for (const auto P : Set)
72 Ret.insert(cast<MachineBasicBlock *>(P));
73 return Ret;
74 }
76 SrcToUnwindDest[MBB] = Dest;
77 UnwindDestToSrcs[Dest].insert(MBB);
78 }
80 return SrcToUnwindDest.count(MBB);
81 }
83 return UnwindDestToSrcs.count(MBB);
84 }
85};
86
87// Analyze the IR in the given function to build WasmEHFuncInfo.
88void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo);
89
90} // namespace llvm
91
92#endif // LLVM_CODEGEN_WASMEHFUNCINFO_H
MachineBasicBlock & MBB
This file defines the DenseMap class.
#define F(x, y, z)
Definition: MD5.cpp:55
#define P(N)
This file defines the PointerUnion class, which is a discriminated union of pointer types.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallPtrSet class.
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:519
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo)
SmallPtrSet< const BasicBlock *, 4 > getUnwindSrcs(const BasicBlock *BB) const
DenseMap< BBOrMBB, SmallPtrSet< BBOrMBB, 4 > > UnwindDestToSrcs
const BasicBlock * getUnwindDest(const BasicBlock *BB) const
bool hasUnwindSrcs(const BasicBlock *BB) const
bool hasUnwindDest(MachineBasicBlock *MBB) const
SmallPtrSet< MachineBasicBlock *, 4 > getUnwindSrcs(MachineBasicBlock *MBB) const
void setUnwindDest(MachineBasicBlock *MBB, MachineBasicBlock *Dest)
bool hasUnwindSrcs(MachineBasicBlock *MBB) const
void setUnwindDest(const BasicBlock *BB, const BasicBlock *Dest)
MachineBasicBlock * getUnwindDest(MachineBasicBlock *MBB) const
bool hasUnwindDest(const BasicBlock *BB) const
DenseMap< BBOrMBB, BBOrMBB > SrcToUnwindDest