1 //===- llvm/CodeGen/WinEHFuncInfo.h -----------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // Data structures and associated state for Windows exception handling schemes.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CODEGEN_WINEHFUNCINFO_H
14 #define LLVM_CODEGEN_WINEHFUNCINFO_H
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/PointerUnion.h"
18 #include "llvm/ADT/SmallVector.h"
32 class MachineBasicBlock
;
35 // The following structs respresent the .xdata tables for various
36 // Windows-related EH personalities.
38 using MBBOrBasicBlock
= PointerUnion
<const BasicBlock
*, MachineBasicBlock
*>;
40 struct CxxUnwindMapEntry
{
42 MBBOrBasicBlock Cleanup
;
45 /// Similar to CxxUnwindMapEntry, but supports SEH filters.
46 struct SEHUnwindMapEntry
{
47 /// If unwinding continues through this handler, transition to the handler at
48 /// this state. This indexes into SEHUnwindMap.
51 bool IsFinally
= false;
53 /// Holds the filter expression function.
54 const Function
*Filter
= nullptr;
56 /// Holds the __except or __finally basic block.
57 MBBOrBasicBlock Handler
;
60 struct WinEHHandlerType
{
62 /// The CatchObj starts out life as an LLVM alloca and is eventually turned
65 const AllocaInst
*Alloca
;
68 GlobalVariable
*TypeDescriptor
;
69 MBBOrBasicBlock Handler
;
72 struct WinEHTryBlockMapEntry
{
76 SmallVector
<WinEHHandlerType
, 1> HandlerArray
;
79 enum class ClrHandlerType
{ Catch
, Finally
, Fault
, Filter
};
81 struct ClrEHUnwindMapEntry
{
82 MBBOrBasicBlock Handler
;
84 int HandlerParentState
; ///< Outer handler enclosing this entry's handler
85 int TryParentState
; ///< Outer try region enclosing this entry's try region,
86 ///< treating later catches on same try as "outer"
87 ClrHandlerType HandlerType
;
90 struct WinEHFuncInfo
{
91 DenseMap
<const Instruction
*, int> EHPadStateMap
;
92 DenseMap
<const FuncletPadInst
*, int> FuncletBaseStateMap
;
93 DenseMap
<const InvokeInst
*, int> InvokeStateMap
;
94 DenseMap
<MCSymbol
*, std::pair
<int, MCSymbol
*>> LabelToStateMap
;
95 SmallVector
<CxxUnwindMapEntry
, 4> CxxUnwindMap
;
96 SmallVector
<WinEHTryBlockMapEntry
, 4> TryBlockMap
;
97 SmallVector
<SEHUnwindMapEntry
, 4> SEHUnwindMap
;
98 SmallVector
<ClrEHUnwindMapEntry
, 4> ClrEHUnwindMap
;
99 int UnwindHelpFrameIdx
= std::numeric_limits
<int>::max();
100 int PSPSymFrameIdx
= std::numeric_limits
<int>::max();
102 int getLastStateNumber() const { return CxxUnwindMap
.size() - 1; }
104 void addIPToStateRange(const InvokeInst
*II
, MCSymbol
*InvokeBegin
,
105 MCSymbol
*InvokeEnd
);
107 int EHRegNodeFrameIndex
= std::numeric_limits
<int>::max();
108 int EHRegNodeEndOffset
= std::numeric_limits
<int>::max();
109 int EHGuardFrameIndex
= std::numeric_limits
<int>::max();
110 int SEHSetFrameOffset
= std::numeric_limits
<int>::max();
115 /// Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which
116 /// describes the state numbers and tables used by __CxxFrameHandler3. This
117 /// analysis assumes that WinEHPrepare has already been run.
118 void calculateWinCXXEHStateNumbers(const Function
*ParentFn
,
119 WinEHFuncInfo
&FuncInfo
);
121 void calculateSEHStateNumbers(const Function
*ParentFn
,
122 WinEHFuncInfo
&FuncInfo
);
124 void calculateClrEHStateNumbers(const Function
*Fn
, WinEHFuncInfo
&FuncInfo
);
126 } // end namespace llvm
128 #endif // LLVM_CODEGEN_WINEHFUNCINFO_H