LLVM  14.0.0git
WinEHFuncInfo.h
Go to the documentation of this file.
1 //===- llvm/CodeGen/WinEHFuncInfo.h -----------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Data structures and associated state for Windows exception handling schemes.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CODEGEN_WINEHFUNCINFO_H
14 #define LLVM_CODEGEN_WINEHFUNCINFO_H
15 
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/PointerUnion.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include <cstdint>
20 #include <limits>
21 #include <utility>
22 
23 namespace llvm {
24 
25 class AllocaInst;
26 class BasicBlock;
27 class FuncletPadInst;
28 class Function;
29 class GlobalVariable;
30 class Instruction;
31 class InvokeInst;
32 class MachineBasicBlock;
33 class MCSymbol;
34 
35 // The following structs respresent the .xdata tables for various
36 // Windows-related EH personalities.
37 
39 
41  int ToState;
43 };
44 
45 /// Similar to CxxUnwindMapEntry, but supports SEH filters.
47  /// If unwinding continues through this handler, transition to the handler at
48  /// this state. This indexes into SEHUnwindMap.
49  int ToState = -1;
50 
51  bool IsFinally = false;
52 
53  /// Holds the filter expression function.
54  const Function *Filter = nullptr;
55 
56  /// Holds the __except or __finally basic block.
58 };
59 
62  /// The CatchObj starts out life as an LLVM alloca and is eventually turned
63  /// frame index.
64  union {
67  } CatchObj = {};
70 };
71 
73  int TryLow = -1;
74  int TryHigh = -1;
75  int CatchHigh = -1;
77 };
78 
80 
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"
88 };
89 
90 struct WinEHFuncInfo {
101 
102  int getLastStateNumber() const { return CxxUnwindMap.size() - 1; }
103 
104  void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin,
105  MCSymbol *InvokeEnd);
106 
111 
112  WinEHFuncInfo();
113 };
114 
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);
120 
121 void calculateSEHStateNumbers(const Function *ParentFn,
122  WinEHFuncInfo &FuncInfo);
123 
124 void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo);
125 
126 } // end namespace llvm
127 
128 #endif // LLVM_CODEGEN_WINEHFUNCINFO_H
llvm::ClrEHUnwindMapEntry::HandlerType
ClrHandlerType HandlerType
Definition: WinEHFuncInfo.h:87
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::WinEHFuncInfo::CxxUnwindMap
SmallVector< CxxUnwindMapEntry, 4 > CxxUnwindMap
Definition: WinEHFuncInfo.h:95
llvm::Function
Definition: Function.h:62
llvm::WinEHFuncInfo::ClrEHUnwindMap
SmallVector< ClrEHUnwindMapEntry, 4 > ClrEHUnwindMap
Definition: WinEHFuncInfo.h:98
llvm::WinEHFuncInfo::InvokeStateMap
DenseMap< const InvokeInst *, int > InvokeStateMap
Definition: WinEHFuncInfo.h:93
llvm::ClrEHUnwindMapEntry
Definition: WinEHFuncInfo.h:81
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::WinEHHandlerType::FrameIndex
int FrameIndex
Definition: WinEHFuncInfo.h:66
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::WinEHFuncInfo::addIPToStateRange
void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin, MCSymbol *InvokeEnd)
Definition: WinEHPrepare.cpp:1254
llvm::WinEHHandlerType
Definition: WinEHFuncInfo.h:60
llvm::WinEHFuncInfo::TryBlockMap
SmallVector< WinEHTryBlockMapEntry, 4 > TryBlockMap
Definition: WinEHFuncInfo.h:96
DenseMap.h
llvm::ClrEHUnwindMapEntry::Handler
MBBOrBasicBlock Handler
Definition: WinEHFuncInfo.h:82
llvm::CxxUnwindMapEntry::Cleanup
MBBOrBasicBlock Cleanup
Definition: WinEHFuncInfo.h:42
llvm::WinEHFuncInfo::FuncletBaseStateMap
DenseMap< const FuncletPadInst *, int > FuncletBaseStateMap
Definition: WinEHFuncInfo.h:92
llvm::WinEHFuncInfo::getLastStateNumber
int getLastStateNumber() const
Definition: WinEHFuncInfo.h:102
llvm::WinEHHandlerType::Adjectives
int Adjectives
Definition: WinEHFuncInfo.h:61
llvm::WinEHFuncInfo::EHRegNodeFrameIndex
int EHRegNodeFrameIndex
Definition: WinEHFuncInfo.h:107
llvm::ClrEHUnwindMapEntry::TryParentState
int TryParentState
Outer try region enclosing this entry's try region, treating later catches on same try as "outer".
Definition: WinEHFuncInfo.h:85
llvm::SEHUnwindMapEntry::Filter
const Function * Filter
Holds the filter expression function.
Definition: WinEHFuncInfo.h:54
llvm::WinEHFuncInfo::WinEHFuncInfo
WinEHFuncInfo()
Definition: WinEHPrepare.cpp:1262
llvm::ClrHandlerType::Fault
@ Fault
llvm::WinEHHandlerType::Alloca
const AllocaInst * Alloca
Definition: WinEHFuncInfo.h:65
llvm::WinEHHandlerType::TypeDescriptor
GlobalVariable * TypeDescriptor
Definition: WinEHFuncInfo.h:68
llvm::InvokeInst
Invoke instruction.
Definition: Instructions.h:3760
llvm::ClrHandlerType::Filter
@ Filter
llvm::WinEHTryBlockMapEntry
Definition: WinEHFuncInfo.h:72
llvm::ClrEHUnwindMapEntry::HandlerParentState
int HandlerParentState
Outer handler enclosing this entry's handler.
Definition: WinEHFuncInfo.h:84
llvm::WinEHFuncInfo
Definition: WinEHFuncInfo.h:90
llvm::SEHUnwindMapEntry::IsFinally
bool IsFinally
Definition: WinEHFuncInfo.h:51
llvm::CxxUnwindMapEntry::ToState
int ToState
Definition: WinEHFuncInfo.h:41
llvm::DenseMap
Definition: DenseMap.h:714
llvm::WinEHTryBlockMapEntry::HandlerArray
SmallVector< WinEHHandlerType, 1 > HandlerArray
Definition: WinEHFuncInfo.h:76
llvm::WinEHTryBlockMapEntry::TryHigh
int TryHigh
Definition: WinEHFuncInfo.h:74
llvm::WinEHFuncInfo::LabelToStateMap
DenseMap< MCSymbol *, std::pair< int, MCSymbol * > > LabelToStateMap
Definition: WinEHFuncInfo.h:94
PointerUnion.h
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
llvm::WinEHFuncInfo::UnwindHelpFrameIdx
int UnwindHelpFrameIdx
Definition: WinEHFuncInfo.h:99
llvm::WinEHFuncInfo::EHGuardFrameIndex
int EHGuardFrameIndex
Definition: WinEHFuncInfo.h:109
uint32_t
llvm::SEHUnwindMapEntry
Similar to CxxUnwindMapEntry, but supports SEH filters.
Definition: WinEHFuncInfo.h:46
llvm::WinEHFuncInfo::EHRegNodeEndOffset
int EHRegNodeEndOffset
Definition: WinEHFuncInfo.h:108
llvm::ClrHandlerType::Finally
@ Finally
llvm::SEHUnwindMapEntry::ToState
int ToState
If unwinding continues through this handler, transition to the handler at this state.
Definition: WinEHFuncInfo.h:49
llvm::SEHUnwindMapEntry::Handler
MBBOrBasicBlock Handler
Holds the __except or __finally basic block.
Definition: WinEHFuncInfo.h:57
llvm::PointerUnion< const BasicBlock *, MachineBasicBlock * >
llvm::WinEHFuncInfo::PSPSymFrameIdx
int PSPSymFrameIdx
Definition: WinEHFuncInfo.h:100
llvm::WinEHFuncInfo::SEHUnwindMap
SmallVector< SEHUnwindMapEntry, 4 > SEHUnwindMap
Definition: WinEHFuncInfo.h:97
llvm::WinEHTryBlockMapEntry::CatchHigh
int CatchHigh
Definition: WinEHFuncInfo.h:75
llvm::ClrEHUnwindMapEntry::TypeToken
uint32_t TypeToken
Definition: WinEHFuncInfo.h:83
llvm::ClrHandlerType
ClrHandlerType
Definition: WinEHFuncInfo.h:79
llvm::WinEHFuncInfo::EHPadStateMap
DenseMap< const Instruction *, int > EHPadStateMap
Definition: WinEHFuncInfo.h:91
llvm::CxxUnwindMapEntry
Definition: WinEHFuncInfo.h:40
llvm::WinEHTryBlockMapEntry::TryLow
int TryLow
Definition: WinEHFuncInfo.h:73
llvm::ClrHandlerType::Catch
@ Catch
llvm::WinEHHandlerType::CatchObj
union llvm::WinEHHandlerType::@227 CatchObj
The CatchObj starts out life as an LLVM alloca and is eventually turned frame index.
SmallVector.h
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::WinEHFuncInfo::SEHSetFrameOffset
int SEHSetFrameOffset
Definition: WinEHFuncInfo.h:110
llvm::WinEHHandlerType::Handler
MBBOrBasicBlock Handler
Definition: WinEHFuncInfo.h:69
llvm::AllocaInst
an instruction to allocate memory on the stack
Definition: Instructions.h:62
llvm::calculateSEHStateNumbers
void calculateSEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
Definition: WinEHPrepare.cpp:451
llvm::calculateWinCXXEHStateNumbers
void calculateWinCXXEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which describes the state number...
Definition: WinEHPrepare.cpp:469
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::ISD::MCSymbol
@ MCSymbol
Definition: ISDOpcodes.h:172
llvm::calculateClrEHStateNumbers
void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo)
Definition: WinEHPrepare.cpp:500