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;
41 struct CxxUnwindMapEntry {
43 MBBOrBasicBlock Cleanup;
46 /// Similar to CxxUnwindMapEntry, but supports SEH filters.
47 struct SEHUnwindMapEntry {
48 /// If unwinding continues through this handler, transition to the handler at
49 /// this state. This indexes into SEHUnwindMap.
52 bool IsFinally = false;
54 /// Holds the filter expression function.
55 const Function *Filter = nullptr;
57 /// Holds the __except or __finally basic block.
58 MBBOrBasicBlock Handler;
61 struct WinEHHandlerType {
63 /// The CatchObj starts out life as an LLVM alloca and is eventually turned
66 const AllocaInst *Alloca;
69 GlobalVariable *TypeDescriptor;
70 MBBOrBasicBlock Handler;
73 struct WinEHTryBlockMapEntry {
77 SmallVector<WinEHHandlerType, 1> HandlerArray;
80 enum class ClrHandlerType { Catch, Finally, Fault, Filter };
82 struct ClrEHUnwindMapEntry {
83 MBBOrBasicBlock Handler;
86 ClrHandlerType HandlerType;
89 struct WinEHFuncInfo {
90 DenseMap<const Instruction *, int> EHPadStateMap;
91 DenseMap<const CatchReturnInst *, const BasicBlock *>
92 CatchRetSuccessorColorMap;
93 DenseMap<MCSymbol *, std::pair<int, MCSymbol *>> InvokeToStateMap;
94 SmallVector<CxxUnwindMapEntry, 4> CxxUnwindMap;
95 SmallVector<WinEHTryBlockMapEntry, 4> TryBlockMap;
96 SmallVector<SEHUnwindMapEntry, 4> SEHUnwindMap;
97 SmallVector<ClrEHUnwindMapEntry, 4> ClrEHUnwindMap;
98 int UnwindHelpFrameIdx = INT_MAX;
99 int PSPSymFrameIdx = INT_MAX;
101 int getLastStateNumber() const { return CxxUnwindMap.size() - 1; }
103 void addIPToStateRange(const BasicBlock *PadBB, MCSymbol *InvokeBegin,
104 MCSymbol *InvokeEnd);
106 int EHRegNodeFrameIndex = INT_MAX;
107 int EHRegNodeEndOffset = INT_MAX;
112 /// Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which
113 /// describes the state numbers and tables used by __CxxFrameHandler3. This
114 /// analysis assumes that WinEHPrepare has already been run.
115 void calculateWinCXXEHStateNumbers(const Function *ParentFn,
116 WinEHFuncInfo &FuncInfo);
118 void calculateSEHStateNumbers(const Function *ParentFn,
119 WinEHFuncInfo &FuncInfo);
121 void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo);
123 void calculateCatchReturnSuccessorColors(const Function *Fn,
124 WinEHFuncInfo &FuncInfo);
126 #endif // LLVM_CODEGEN_WINEHFUNCINFO_H