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"
21 #include "llvm/IR/Instructions.h"
26 class CatchReturnInst;
35 class MachineBasicBlock;
38 // The following structs respresent the .xdata tables for various
39 // Windows-related EH personalities.
41 typedef PointerUnion<const BasicBlock *, MachineBasicBlock *> MBBOrBasicBlock;
43 struct CxxUnwindMapEntry {
45 MBBOrBasicBlock Cleanup;
48 /// Similar to CxxUnwindMapEntry, but supports SEH filters.
49 struct SEHUnwindMapEntry {
50 /// If unwinding continues through this handler, transition to the handler at
51 /// this state. This indexes into SEHUnwindMap.
54 bool IsFinally = false;
56 /// Holds the filter expression function.
57 const Function *Filter = nullptr;
59 /// Holds the __except or __finally basic block.
60 MBBOrBasicBlock Handler;
63 struct WinEHHandlerType {
65 /// The CatchObj starts out life as an LLVM alloca and is eventually turned
68 const AllocaInst *Alloca;
71 GlobalVariable *TypeDescriptor;
72 MBBOrBasicBlock Handler;
75 struct WinEHTryBlockMapEntry {
79 SmallVector<WinEHHandlerType, 1> HandlerArray;
82 enum class ClrHandlerType { Catch, Finally, Fault, Filter };
84 struct ClrEHUnwindMapEntry {
85 MBBOrBasicBlock Handler;
87 int HandlerParentState; ///< Outer handler enclosing this entry's handler
88 int TryParentState; ///< Outer try region enclosing this entry's try region,
89 ///< treating later catches on same try as "outer"
90 ClrHandlerType HandlerType;
93 struct WinEHFuncInfo {
94 DenseMap<const Instruction *, int> EHPadStateMap;
95 DenseMap<const FuncletPadInst *, int> FuncletBaseStateMap;
96 DenseMap<const InvokeInst *, int> InvokeStateMap;
97 DenseMap<MCSymbol *, std::pair<int, MCSymbol *>> LabelToStateMap;
98 SmallVector<CxxUnwindMapEntry, 4> CxxUnwindMap;
99 SmallVector<WinEHTryBlockMapEntry, 4> TryBlockMap;
100 SmallVector<SEHUnwindMapEntry, 4> SEHUnwindMap;
101 SmallVector<ClrEHUnwindMapEntry, 4> ClrEHUnwindMap;
102 int UnwindHelpFrameIdx = INT_MAX;
103 int PSPSymFrameIdx = INT_MAX;
105 int getLastStateNumber() const { return CxxUnwindMap.size() - 1; }
107 void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin,
108 MCSymbol *InvokeEnd);
110 int EHRegNodeFrameIndex = INT_MAX;
111 int EHRegNodeEndOffset = INT_MAX;
112 int EHGuardFrameIndex = INT_MAX;
113 int SEHSetFrameOffset = INT_MAX;
118 /// Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which
119 /// describes the state numbers and tables used by __CxxFrameHandler3. This
120 /// analysis assumes that WinEHPrepare has already been run.
121 void calculateWinCXXEHStateNumbers(const Function *ParentFn,
122 WinEHFuncInfo &FuncInfo);
124 void calculateSEHStateNumbers(const Function *ParentFn,
125 WinEHFuncInfo &FuncInfo);
127 void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo);
129 #endif // LLVM_CODEGEN_WINEHFUNCINFO_H