LLVM  9.0.0svn
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"
17 #include "llvm/ADT/PointerUnion.h"
19 #include "llvm/IR/BasicBlock.h"
20 
21 namespace llvm {
22 
23 enum EventTag { CPP_EXCEPTION = 0, C_LONGJMP = 1 };
24 
26 
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.
31  // For entry <A, B>, A is a BB with an instruction that may throw
32  // (invoke/cleanupret in LLVM IR, call/rethrow in the backend) and B is an EH
33  // pad that A unwinds to.
35 
36  // Helper functions
37  const BasicBlock *getEHPadUnwindDest(const BasicBlock *BB) const {
38  return EHPadUnwindMap.lookup(BB).get<const BasicBlock *>();
39  }
40  void setEHPadUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) {
41  EHPadUnwindMap[BB] = Dest;
42  }
44  return ThrowUnwindMap.lookup(BB).get<const BasicBlock *>();
45  }
46  void setThrowUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) {
47  ThrowUnwindMap[BB] = Dest;
48  }
49  bool hasEHPadUnwindDest(const BasicBlock *BB) const {
50  return EHPadUnwindMap.count(BB);
51  }
52  bool hasThrowUnwindDest(const BasicBlock *BB) const {
53  return ThrowUnwindMap.count(BB);
54  }
55 
57  return EHPadUnwindMap.lookup(MBB).get<MachineBasicBlock *>();
58  }
60  EHPadUnwindMap[MBB] = Dest;
61  }
63  return ThrowUnwindMap.lookup(MBB).get<MachineBasicBlock *>();
64  }
66  ThrowUnwindMap[MBB] = Dest;
67  }
69  return EHPadUnwindMap.count(MBB);
70  }
72  return ThrowUnwindMap.count(MBB);
73  }
74 };
75 
76 // Analyze the IR in the given function to build WasmEHFuncInfo.
77 void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo);
78 
79 } // namespace llvm
80 
81 #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:23
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:57
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:86