1 //===-- llvm/CodeGen/WinEHFuncInfo.h ----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Data structures and associated state for Windows exception handling schemes.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_WINEHFUNCINFO_H
15 #define LLVM_CODEGEN_WINEHFUNCINFO_H
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/PointerUnion.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/TinyPtrVector.h"
25 class CatchReturnInst;
34 class MachineBasicBlock;
37 // The following structs respresent the .xdata tables for various
38 // Windows-related EH personalities.
40 typedef PointerUnion<const BasicBlock *, MachineBasicBlock *> MBBOrBasicBlock;
42 struct CxxUnwindMapEntry {
44 MBBOrBasicBlock Cleanup;
47 /// Similar to CxxUnwindMapEntry, but supports SEH filters.
48 struct SEHUnwindMapEntry {
49 /// If unwinding continues through this handler, transition to the handler at
50 /// this state. This indexes into SEHUnwindMap.
53 bool IsFinally = false;
55 /// Holds the filter expression function.
56 const Function *Filter = nullptr;
58 /// Holds the __except or __finally basic block.
59 MBBOrBasicBlock Handler;
62 struct WinEHHandlerType {
64 /// The CatchObj starts out life as an LLVM alloca and is eventually turned
67 const AllocaInst *Alloca;
70 GlobalVariable *TypeDescriptor;
71 MBBOrBasicBlock Handler;
74 struct WinEHTryBlockMapEntry {
78 SmallVector<WinEHHandlerType, 1> HandlerArray;
81 enum class ClrHandlerType { Catch, Finally, Fault, Filter };
83 struct ClrEHUnwindMapEntry {
84 MBBOrBasicBlock Handler;
86 int HandlerParentState; ///< Outer handler enclosing this entry's handler
87 int TryParentState; ///< Outer try region enclosing this entry's try region,
88 ///< treating later catches on same try as "outer"
89 ClrHandlerType HandlerType;
92 struct WinEHFuncInfo {
93 DenseMap<const Instruction *, int> EHPadStateMap;
94 DenseMap<const FuncletPadInst *, int> FuncletBaseStateMap;
95 DenseMap<const InvokeInst *, int> InvokeStateMap;
96 DenseMap<MCSymbol *, std::pair<int, MCSymbol *>> LabelToStateMap;
97 SmallVector<CxxUnwindMapEntry, 4> CxxUnwindMap;
98 SmallVector<WinEHTryBlockMapEntry, 4> TryBlockMap;
99 SmallVector<SEHUnwindMapEntry, 4> SEHUnwindMap;
100 SmallVector<ClrEHUnwindMapEntry, 4> ClrEHUnwindMap;
101 int UnwindHelpFrameIdx = INT_MAX;
102 int PSPSymFrameIdx = INT_MAX;
104 int getLastStateNumber() const { return CxxUnwindMap.size() - 1; }
106 void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin,
107 MCSymbol *InvokeEnd);
109 int EHRegNodeFrameIndex = INT_MAX;
110 int EHRegNodeEndOffset = INT_MAX;
111 int SEHSetFrameOffset = INT_MAX;
116 /// Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which
117 /// describes the state numbers and tables used by __CxxFrameHandler3. This
118 /// analysis assumes that WinEHPrepare has already been run.
119 void calculateWinCXXEHStateNumbers(const Function *ParentFn,
120 WinEHFuncInfo &FuncInfo);
122 void calculateSEHStateNumbers(const Function *ParentFn,
123 WinEHFuncInfo &FuncInfo);
125 void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo);
127 #endif // LLVM_CODEGEN_WINEHFUNCINFO_H