File indexing completed on 2026-05-10 08:43:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_CODEGEN_WINEHFUNCINFO_H
0014 #define LLVM_CODEGEN_WINEHFUNCINFO_H
0015
0016 #include "llvm/ADT/DenseMap.h"
0017 #include "llvm/ADT/PointerUnion.h"
0018 #include "llvm/ADT/SmallVector.h"
0019 #include <cstdint>
0020 #include <limits>
0021 #include <utility>
0022
0023 namespace llvm {
0024
0025 class AllocaInst;
0026 class BasicBlock;
0027 class FuncletPadInst;
0028 class Function;
0029 class GlobalVariable;
0030 class Instruction;
0031 class InvokeInst;
0032 class MachineBasicBlock;
0033 class MCSymbol;
0034
0035
0036
0037
0038 using MBBOrBasicBlock = PointerUnion<const BasicBlock *, MachineBasicBlock *>;
0039
0040 struct CxxUnwindMapEntry {
0041 int ToState;
0042 MBBOrBasicBlock Cleanup;
0043 };
0044
0045
0046 struct SEHUnwindMapEntry {
0047
0048
0049 int ToState = -1;
0050
0051 bool IsFinally = false;
0052
0053
0054 const Function *Filter = nullptr;
0055
0056
0057 MBBOrBasicBlock Handler;
0058 };
0059
0060 struct WinEHHandlerType {
0061 int Adjectives;
0062
0063
0064 union {
0065 const AllocaInst *Alloca;
0066 int FrameIndex;
0067 } CatchObj = {};
0068 GlobalVariable *TypeDescriptor;
0069 MBBOrBasicBlock Handler;
0070 };
0071
0072 struct WinEHTryBlockMapEntry {
0073 int TryLow = -1;
0074 int TryHigh = -1;
0075 int CatchHigh = -1;
0076 SmallVector<WinEHHandlerType, 1> HandlerArray;
0077 };
0078
0079 enum class ClrHandlerType { Catch, Finally, Fault, Filter };
0080
0081 struct ClrEHUnwindMapEntry {
0082 MBBOrBasicBlock Handler;
0083 uint32_t TypeToken;
0084 int HandlerParentState;
0085 int TryParentState;
0086
0087 ClrHandlerType HandlerType;
0088 };
0089
0090 struct WinEHFuncInfo {
0091 DenseMap<const Instruction *, int> EHPadStateMap;
0092 DenseMap<const FuncletPadInst *, int> FuncletBaseStateMap;
0093 DenseMap<const InvokeInst *, int> InvokeStateMap;
0094 DenseMap<MCSymbol *, std::pair<int, MCSymbol *>> LabelToStateMap;
0095 DenseMap<const BasicBlock *, int> BlockToStateMap;
0096 SmallVector<CxxUnwindMapEntry, 4> CxxUnwindMap;
0097 SmallVector<WinEHTryBlockMapEntry, 4> TryBlockMap;
0098 SmallVector<SEHUnwindMapEntry, 4> SEHUnwindMap;
0099 SmallVector<ClrEHUnwindMapEntry, 4> ClrEHUnwindMap;
0100 int UnwindHelpFrameIdx = std::numeric_limits<int>::max();
0101 int PSPSymFrameIdx = std::numeric_limits<int>::max();
0102
0103 int getLastStateNumber() const { return CxxUnwindMap.size() - 1; }
0104
0105 void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin,
0106 MCSymbol *InvokeEnd);
0107
0108 void addIPToStateRange(int State, MCSymbol *InvokeBegin, MCSymbol *InvokeEnd);
0109
0110 int EHRegNodeFrameIndex = std::numeric_limits<int>::max();
0111 int EHRegNodeEndOffset = std::numeric_limits<int>::max();
0112 int EHGuardFrameIndex = std::numeric_limits<int>::max();
0113 int SEHSetFrameOffset = std::numeric_limits<int>::max();
0114
0115 WinEHFuncInfo();
0116 };
0117
0118
0119
0120
0121 void calculateWinCXXEHStateNumbers(const Function *ParentFn,
0122 WinEHFuncInfo &FuncInfo);
0123
0124 void calculateSEHStateNumbers(const Function *ParentFn,
0125 WinEHFuncInfo &FuncInfo);
0126
0127 void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo);
0128
0129
0130 void calculateCXXStateForAsynchEH(const BasicBlock *BB, int State,
0131 WinEHFuncInfo &FuncInfo);
0132 void calculateSEHStateForAsynchEH(const BasicBlock *BB, int State,
0133 WinEHFuncInfo &FuncInfo);
0134
0135 }
0136
0137 #endif