LLVM  8.0.1
WasmEHFuncInfo.h
Go to the documentation of this file.
1 //===--- 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 
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/PointerUnion.h"
20 #include "llvm/IR/BasicBlock.h"
21 
22 namespace llvm {
23 
24 enum EventTag { CPP_EXCEPTION = 0, C_LONGJMP = 1 };
25 
27 
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.
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.
36 
37  // Helper functions
38  const BasicBlock *getEHPadUnwindDest(const BasicBlock *BB) const {
39  return EHPadUnwindMap.lookup(BB).get<const BasicBlock *>();
40  }
41  void setEHPadUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) {
42  EHPadUnwindMap[BB] = Dest;
43  }
45  return ThrowUnwindMap.lookup(BB).get<const BasicBlock *>();
46  }
47  void setThrowUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) {
48  ThrowUnwindMap[BB] = Dest;
49  }
50  bool hasEHPadUnwindDest(const BasicBlock *BB) const {
51  return EHPadUnwindMap.count(BB);
52  }
53  bool hasThrowUnwindDest(const BasicBlock *BB) const {
54  return ThrowUnwindMap.count(BB);
55  }
56 
58  return EHPadUnwindMap.lookup(MBB).get<MachineBasicBlock *>();
59  }
61  EHPadUnwindMap[MBB] = Dest;
62  }
64  return ThrowUnwindMap.lookup(MBB).get<MachineBasicBlock *>();
65  }
67  ThrowUnwindMap[MBB] = Dest;
68  }
70  return EHPadUnwindMap.count(MBB);
71  }
73  return ThrowUnwindMap.count(MBB);
74  }
75 };
76 
77 // Analyze the IR in the given function to build WasmEHFuncInfo.
78 void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo);
79 
80 } // namespace llvm
81 
82 #endif // LLVM_CODEGEN_WASMEHFUNCINFO_H
const BasicBlock * getThrowUnwindDest(BasicBlock *BB) const
bool hasEHPadUnwindDest(const BasicBlock *BB) const
This class represents lattice values for constants.
Definition: AllocatorList.h:24
F(f)
bool hasThrowUnwindDest(MachineBasicBlock *MBB) const
void setEHPadUnwindDest(MachineBasicBlock *MBB, MachineBasicBlock *Dest)
DenseMap< BBOrMBB, BBOrMBB > EHPadUnwindMap
DenseMap< BBOrMBB, BBOrMBB > ThrowUnwindMap
MachineBasicBlock * getThrowUnwindDest(MachineBasicBlock *MBB) const
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
void setEHPadUnwindDest(const BasicBlock *BB, const BasicBlock *Dest)
const BasicBlock * getEHPadUnwindDest(const BasicBlock *BB) const
bool hasThrowUnwindDest(const BasicBlock *BB) const
bool hasEHPadUnwindDest(MachineBasicBlock *MBB) const
void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:171
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:211
void setThrowUnwindDest(MachineBasicBlock *MBB, MachineBasicBlock *Dest)
void setThrowUnwindDest(const BasicBlock *BB, const BasicBlock *Dest)
MachineBasicBlock * getEHPadUnwindDest(MachineBasicBlock *MBB) const
A discriminated union of two pointer types, with the discriminator in the low bit of the pointer...
Definition: PointerUnion.h:87