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"
33 class MachineBasicBlock;
36 // The following structs respresent the .xdata tables for various
37 // Windows-related EH personalities.
39 typedef PointerUnion<const BasicBlock *, MachineBasicBlock *> MBBOrBasicBlock;
40 typedef PointerUnion<const Value *, const MachineBasicBlock *> ValueOrMBB;
42 struct CxxUnwindMapEntry {
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 int CatchObjRecoverIdx;
65 /// The CatchObj starts out life as an LLVM alloca, is turned into a frame
66 /// index, and after PEI, becomes a raw offset.
68 const AllocaInst *Alloca;
71 GlobalVariable *TypeDescriptor;
75 struct WinEHTryBlockMapEntry {
79 SmallVector<WinEHHandlerType, 1> HandlerArray;
82 enum class ClrHandlerType { Catch, Finally, Fault, Filter };
84 struct ClrEHUnwindMapEntry {
85 MBBOrBasicBlock Handler;
88 ClrHandlerType HandlerType;
91 struct WinEHFuncInfo {
92 DenseMap<const Instruction *, int> EHPadStateMap;
93 DenseMap<const CatchReturnInst *, const BasicBlock *>
94 CatchRetSuccessorColorMap;
95 DenseMap<MCSymbol *, std::pair<int, MCSymbol *>> InvokeToStateMap;
96 SmallVector<CxxUnwindMapEntry, 4> CxxUnwindMap;
97 SmallVector<WinEHTryBlockMapEntry, 4> TryBlockMap;
98 SmallVector<SEHUnwindMapEntry, 4> SEHUnwindMap;
99 SmallVector<ClrEHUnwindMapEntry, 4> ClrEHUnwindMap;
100 int UnwindHelpFrameIdx = INT_MAX;
102 int getLastStateNumber() const { return CxxUnwindMap.size() - 1; }
104 void addIPToStateRange(const BasicBlock *PadBB, MCSymbol *InvokeBegin,
105 MCSymbol *InvokeEnd);
107 /// localescape index of the 32-bit EH registration node. Set by
108 /// WinEHStatePass and used indirectly by SEH filter functions of the parent.
109 int EHRegNodeEscapeIndex = INT_MAX;
110 const AllocaInst *EHRegNode = nullptr;
111 int EHRegNodeFrameIndex = INT_MAX;
112 int EHRegNodeEndOffset = INT_MAX;
117 /// Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which
118 /// describes the state numbers and tables used by __CxxFrameHandler3. This
119 /// analysis assumes that WinEHPrepare has already been run.
120 void calculateWinCXXEHStateNumbers(const Function *ParentFn,
121 WinEHFuncInfo &FuncInfo);
123 void calculateSEHStateNumbers(const Function *ParentFn,
124 WinEHFuncInfo &FuncInfo);
126 void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo);
128 void calculateCatchReturnSuccessorColors(const Function *Fn,
129 WinEHFuncInfo &FuncInfo);
131 #endif // LLVM_CODEGEN_WINEHFUNCINFO_H