LLVM  4.0.0
WinEHFuncInfo.h
Go to the documentation of this file.
1 //===-- llvm/CodeGen/WinEHFuncInfo.h ----------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Data structures and associated state for Windows exception handling schemes.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_WINEHFUNCINFO_H
15 #define LLVM_CODEGEN_WINEHFUNCINFO_H
16 
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/PointerUnion.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/TinyPtrVector.h"
21 #include "llvm/IR/Instructions.h"
22 
23 namespace llvm {
24 class AllocaInst;
25 class BasicBlock;
26 class CatchReturnInst;
27 class Constant;
28 class Function;
29 class GlobalVariable;
30 class InvokeInst;
31 class IntrinsicInst;
32 class LandingPadInst;
33 class MCExpr;
34 class MCSymbol;
35 class MachineBasicBlock;
36 class Value;
37 
38 // The following structs respresent the .xdata tables for various
39 // Windows-related EH personalities.
40 
42 
44  int ToState;
46 };
47 
48 /// Similar to CxxUnwindMapEntry, but supports SEH filters.
50  /// If unwinding continues through this handler, transition to the handler at
51  /// this state. This indexes into SEHUnwindMap.
52  int ToState = -1;
53 
54  bool IsFinally = false;
55 
56  /// Holds the filter expression function.
57  const Function *Filter = nullptr;
58 
59  /// Holds the __except or __finally basic block.
61 };
62 
65  /// The CatchObj starts out life as an LLVM alloca and is eventually turned
66  /// frame index.
67  union {
70  } CatchObj = {};
73 };
74 
76  int TryLow = -1;
77  int TryHigh = -1;
78  int CatchHigh = -1;
80 };
81 
83 
87  int HandlerParentState; ///< Outer handler enclosing this entry's handler
88  int TryParentState; ///< Outer try region enclosing this entry's try region,
89  ///< treating later catches on same try as "outer"
91 };
92 
93 struct WinEHFuncInfo {
102  int UnwindHelpFrameIdx = INT_MAX;
103  int PSPSymFrameIdx = INT_MAX;
104 
105  int getLastStateNumber() const { return CxxUnwindMap.size() - 1; }
106 
107  void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin,
108  MCSymbol *InvokeEnd);
109 
110  int EHRegNodeFrameIndex = INT_MAX;
111  int EHRegNodeEndOffset = INT_MAX;
112  int EHGuardFrameIndex = INT_MAX;
113  int SEHSetFrameOffset = INT_MAX;
114 
115  WinEHFuncInfo();
116 };
117 
118 /// Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which
119 /// describes the state numbers and tables used by __CxxFrameHandler3. This
120 /// analysis assumes that WinEHPrepare has already been run.
121 void calculateWinCXXEHStateNumbers(const Function *ParentFn,
122  WinEHFuncInfo &FuncInfo);
123 
124 void calculateSEHStateNumbers(const Function *ParentFn,
125  WinEHFuncInfo &FuncInfo);
126 
127 void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo);
128 }
129 #endif // LLVM_CODEGEN_WINEHFUNCINFO_H
MBBOrBasicBlock Handler
Definition: WinEHFuncInfo.h:85
SmallVector< WinEHHandlerType, 1 > HandlerArray
Definition: WinEHFuncInfo.h:79
DenseMap< MCSymbol *, std::pair< int, MCSymbol * > > LabelToStateMap
Definition: WinEHFuncInfo.h:97
MBBOrBasicBlock Cleanup
Definition: WinEHFuncInfo.h:45
Various leaf nodes.
Definition: ISDOpcodes.h:60
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
SmallVector< SEHUnwindMapEntry, 4 > SEHUnwindMap
DenseMap< const FuncletPadInst *, int > FuncletBaseStateMap
Definition: WinEHFuncInfo.h:95
const AllocaInst * Alloca
Definition: WinEHFuncInfo.h:68
MBBOrBasicBlock Handler
Holds the __except or __finally basic block.
Definition: WinEHFuncInfo.h:60
void calculateSEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
int TryParentState
Outer try region enclosing this entry's try region, treating later catches on same try as "outer"...
Definition: WinEHFuncInfo.h:88
int ToState
If unwinding continues through this handler, transition to the handler at this state.
Definition: WinEHFuncInfo.h:52
ClrHandlerType
Definition: WinEHFuncInfo.h:82
Similar to CxxUnwindMapEntry, but supports SEH filters.
Definition: WinEHFuncInfo.h:49
SmallVector< ClrEHUnwindMapEntry, 4 > ClrEHUnwindMap
DenseMap< const Instruction *, int > EHPadStateMap
Definition: WinEHFuncInfo.h:94
int getLastStateNumber() const
DenseMap< const InvokeInst *, int > InvokeStateMap
Definition: WinEHFuncInfo.h:96
void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo)
MBBOrBasicBlock Handler
Definition: WinEHFuncInfo.h:72
void calculateWinCXXEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which describes the state number...
SmallVector< CxxUnwindMapEntry, 4 > CxxUnwindMap
Definition: WinEHFuncInfo.h:98
const Function * Filter
Holds the filter expression function.
Definition: WinEHFuncInfo.h:57
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
int HandlerParentState
Outer handler enclosing this entry's handler.
Definition: WinEHFuncInfo.h:87
void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin, MCSymbol *InvokeEnd)
PointerUnion< const BasicBlock *, MachineBasicBlock * > MBBOrBasicBlock
Definition: WinEHFuncInfo.h:36
SmallVector< WinEHTryBlockMapEntry, 4 > TryBlockMap
Definition: WinEHFuncInfo.h:99
GlobalVariable * TypeDescriptor
Definition: WinEHFuncInfo.h:71
union llvm::WinEHHandlerType::@61 CatchObj
The CatchObj starts out life as an LLVM alloca and is eventually turned frame index.
ClrHandlerType HandlerType
Definition: WinEHFuncInfo.h:90
LLVM Value Representation.
Definition: Value.h:71
Invoke instruction.
an instruction to allocate memory on the stack
Definition: Instructions.h:60