| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#ifndef LLVM_CODEGEN_WASMEHFUNCINFO_H |
| 14 |
#define LLVM_CODEGEN_WASMEHFUNCINFO_H |
| 15 |
|
| 16 |
#include "llvm/ADT/DenseMap.h" |
| 17 |
#include "llvm/ADT/PointerUnion.h" |
| 18 |
#include "llvm/ADT/SmallPtrSet.h" |
| 19 |
|
| 20 |
namespace llvm { |
| 21 |
|
| 22 |
class BasicBlock; |
| 23 |
class Function; |
| 24 |
class MachineBasicBlock; |
| 25 |
|
| 26 |
namespace WebAssembly { |
| 27 |
enum Tag { CPP_EXCEPTION = 0, C_LONGJMP = 1 }; |
| 28 |
} |
| 29 |
|
| 30 |
using BBOrMBB = PointerUnion<const BasicBlock *, MachineBasicBlock *>; |
| 31 |
|
| 32 |
struct WasmEHFuncInfo { |
| 33 |
|
| 34 |
|
| 35 |
DenseMap<BBOrMBB, BBOrMBB> SrcToUnwindDest; |
| 36 |
DenseMap<BBOrMBB, SmallPtrSet<BBOrMBB, 4>> UnwindDestToSrcs; |
| 37 |
|
| 38 |
|
| 39 |
const BasicBlock *getUnwindDest(const BasicBlock *BB) const { |
| 40 |
assert(hasUnwindDest(BB)); |
| 41 |
return SrcToUnwindDest.lookup(BB).get<const BasicBlock *>(); |
| 42 |
} |
| 43 |
SmallPtrSet<const BasicBlock *, 4> getUnwindSrcs(const BasicBlock *BB) const { |
| 44 |
assert(hasUnwindSrcs(BB)); |
| 45 |
const auto &Set = UnwindDestToSrcs.lookup(BB); |
| 46 |
SmallPtrSet<const BasicBlock *, 4> Ret; |
| 47 |
for (const auto P : Set) |
| 48 |
Ret.insert(P.get<const BasicBlock *>()); |
| 49 |
return Ret; |
| 50 |
} |
| 51 |
void setUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) { |
| 52 |
SrcToUnwindDest[BB] = Dest; |
| 53 |
if (!UnwindDestToSrcs.count(Dest)) |
| 54 |
UnwindDestToSrcs[Dest] = SmallPtrSet<BBOrMBB, 4>(); |
| 55 |
UnwindDestToSrcs[Dest].insert(BB); |
| 56 |
} |
| 57 |
bool hasUnwindDest(const BasicBlock *BB) const { |
| 58 |
return SrcToUnwindDest.count(BB); |
| 59 |
} |
| 60 |
bool hasUnwindSrcs(const BasicBlock *BB) const { |
| 61 |
return UnwindDestToSrcs.count(BB); |
| 62 |
} |
| 63 |
|
| 64 |
MachineBasicBlock *getUnwindDest(MachineBasicBlock *MBB) const { |
| 65 |
assert(hasUnwindDest(MBB)); |
| 66 |
return SrcToUnwindDest.lookup(MBB).get<MachineBasicBlock *>(); |
| 67 |
} |
| 68 |
SmallPtrSet<MachineBasicBlock *, 4> |
| 69 |
getUnwindSrcs(MachineBasicBlock *MBB) const { |
| 70 |
assert(hasUnwindSrcs(MBB)); |
| 71 |
const auto &Set = UnwindDestToSrcs.lookup(MBB); |
| 72 |
SmallPtrSet<MachineBasicBlock *, 4> Ret; |
| 73 |
for (const auto P : Set) |
| 74 |
Ret.insert(P.get<MachineBasicBlock *>()); |
| 75 |
return Ret; |
| 76 |
} |
| 77 |
void setUnwindDest(MachineBasicBlock *MBB, MachineBasicBlock *Dest) { |
| 78 |
SrcToUnwindDest[MBB] = Dest; |
| 79 |
if (!UnwindDestToSrcs.count(Dest)) |
| 80 |
UnwindDestToSrcs[Dest] = SmallPtrSet<BBOrMBB, 4>(); |
| 81 |
UnwindDestToSrcs[Dest].insert(MBB); |
| 82 |
} |
| 83 |
bool hasUnwindDest(MachineBasicBlock *MBB) const { |
| 84 |
return SrcToUnwindDest.count(MBB); |
| 85 |
} |
| 86 |
bool hasUnwindSrcs(MachineBasicBlock *MBB) const { |
| 87 |
return UnwindDestToSrcs.count(MBB); |
| 88 |
} |
| 89 |
}; |
| 90 |
|
| 91 |
|
| 92 |
void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo); |
| 93 |
|
| 94 |
} |
| 95 |
|
| 96 |
#endif |