LLVM  10.0.0svn
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 {
99  int UnwindHelpFrameIdx = std::numeric_limits<int>::max();
100  int PSPSymFrameIdx = std::numeric_limits<int>::max();
101 
102  int getLastStateNumber() const { return CxxUnwindMap.size() - 1; }
103 
104  void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin,
105  MCSymbol *InvokeEnd);
106 
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();
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
MBBOrBasicBlock Handler
Definition: WinEHFuncInfo.h:82
SmallVector< WinEHHandlerType, 1 > HandlerArray
Definition: WinEHFuncInfo.h:76
int getLastStateNumber() const
DenseMap< MCSymbol *, std::pair< int, MCSymbol * > > LabelToStateMap
Definition: WinEHFuncInfo.h:94
MBBOrBasicBlock Cleanup
Definition: WinEHFuncInfo.h:42
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Various leaf nodes.
Definition: ISDOpcodes.h:59
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
SmallVector< SEHUnwindMapEntry, 4 > SEHUnwindMap
Definition: WinEHFuncInfo.h:97
DenseMap< const FuncletPadInst *, int > FuncletBaseStateMap
Definition: WinEHFuncInfo.h:92
const AllocaInst * Alloca
Definition: WinEHFuncInfo.h:65
MBBOrBasicBlock Handler
Holds the __except or __finally basic block.
Definition: WinEHFuncInfo.h:57
void calculateSEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
int TryParentState
Outer try region enclosing this entry&#39;s try region, treating later catches on same try as "outer"...
Definition: WinEHFuncInfo.h:85
ClrHandlerType
Definition: WinEHFuncInfo.h:79
Similar to CxxUnwindMapEntry, but supports SEH filters.
Definition: WinEHFuncInfo.h:46
SmallVector< ClrEHUnwindMapEntry, 4 > ClrEHUnwindMap
Definition: WinEHFuncInfo.h:98
DenseMap< const Instruction *, int > EHPadStateMap
Definition: WinEHFuncInfo.h:91
DenseMap< const InvokeInst *, int > InvokeStateMap
Definition: WinEHFuncInfo.h:93
void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo)
size_t size() const
Definition: SmallVector.h:52
MBBOrBasicBlock Handler
Definition: WinEHFuncInfo.h:69
void calculateWinCXXEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
Analyze the IR in ParentFn and it&#39;s handlers to build WinEHFuncInfo, which describes the state number...
SmallVector< CxxUnwindMapEntry, 4 > CxxUnwindMap
Definition: WinEHFuncInfo.h:95
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:336
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
int HandlerParentState
Outer handler enclosing this entry&#39;s handler.
Definition: WinEHFuncInfo.h:84
SmallVector< WinEHTryBlockMapEntry, 4 > TryBlockMap
Definition: WinEHFuncInfo.h:96
GlobalVariable * TypeDescriptor
Definition: WinEHFuncInfo.h:68
ClrHandlerType HandlerType
Definition: WinEHFuncInfo.h:87
Invoke instruction.
an instruction to allocate memory on the stack
Definition: Instructions.h:59
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:156