LLVM  3.7.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/SmallVector.h"
18 #include "llvm/ADT/TinyPtrVector.h"
19 #include "llvm/ADT/DenseMap.h"
20 
21 namespace llvm {
22 class BasicBlock;
23 class Constant;
24 class Function;
25 class GlobalVariable;
26 class InvokeInst;
27 class IntrinsicInst;
28 class LandingPadInst;
29 class MCSymbol;
30 class Value;
31 
33 
35 public:
37  : StartBB(BB), Type(Type), EHState(-1), HandlerBlockOrFunc(nullptr) {}
38 
39  ActionType getType() const { return Type; }
40  BasicBlock *getStartBlock() const { return StartBB; }
41 
42  bool hasBeenProcessed() { return HandlerBlockOrFunc != nullptr; }
43 
44  void setHandlerBlockOrFunc(Constant *F) { HandlerBlockOrFunc = F; }
45  Constant *getHandlerBlockOrFunc() { return HandlerBlockOrFunc; }
46 
47  void setEHState(int State) { EHState = State; }
48  int getEHState() const { return EHState; }
49 
50 private:
51  BasicBlock *StartBB;
53  int EHState;
54 
55  // Can be either a BlockAddress or a Function depending on the EH personality.
56  Constant *HandlerBlockOrFunc;
57 };
58 
59 class CatchHandler : public ActionHandler {
60 public:
61  CatchHandler(BasicBlock *BB, Constant *Selector, BasicBlock *NextBB)
62  : ActionHandler(BB, ActionType::Catch), Selector(Selector),
63  NextBB(NextBB), ExceptionObjectVar(nullptr),
64  ExceptionObjectIndex(-1) {}
65 
66  // Method for support type inquiry through isa, cast, and dyn_cast:
67  static inline bool classof(const ActionHandler *H) {
68  return H->getType() == ActionType::Catch;
69  }
70 
71  Constant *getSelector() const { return Selector; }
72  BasicBlock *getNextBB() const { return NextBB; }
73 
74  const Value *getExceptionVar() { return ExceptionObjectVar; }
75  TinyPtrVector<BasicBlock *> &getReturnTargets() { return ReturnTargets; }
76 
77  void setExceptionVar(const Value *Val) { ExceptionObjectVar = Val; }
78  void setExceptionVarIndex(int Index) { ExceptionObjectIndex = Index; }
79  int getExceptionVarIndex() const { return ExceptionObjectIndex; }
81  ReturnTargets = Targets;
82  }
83 
84 private:
85  Constant *Selector;
86  BasicBlock *NextBB;
87  // While catch handlers are being outlined the ExceptionObjectVar field will
88  // be populated with the instruction in the parent frame that corresponds
89  // to the exception object (or nullptr if the catch does not use an
90  // exception object) and the ExceptionObjectIndex field will be -1.
91  // When the parseEHActions function is called to populate a vector of
92  // instances of this class, the ExceptionObjectVar field will be nullptr
93  // and the ExceptionObjectIndex will be the index of the exception object in
94  // the parent function's localescape block.
95  const Value *ExceptionObjectVar;
96  int ExceptionObjectIndex;
97  TinyPtrVector<BasicBlock *> ReturnTargets;
98 };
99 
101 public:
103 
104  // Method for support type inquiry through isa, cast, and dyn_cast:
105  static inline bool classof(const ActionHandler *H) {
106  return H->getType() == ActionType::Cleanup;
107  }
108 };
109 
110 void parseEHActions(const IntrinsicInst *II,
111  SmallVectorImpl<std::unique_ptr<ActionHandler>> &Actions);
112 
113 // The following structs respresent the .xdata for functions using C++
114 // exceptions on Windows.
115 
117  int ToState;
119 };
120 
126 };
127 
129  int TryLow;
130  int TryHigh;
132 };
133 
147  int UnwindHelpFrameIdx = INT_MAX;
150 
151  /// localescape index of the 32-bit EH registration node. Set by
152  /// WinEHStatePass and used indirectly by SEH filter functions of the parent.
153  int EHRegNodeEscapeIndex = INT_MAX;
154 
156 };
157 
158 /// Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which
159 /// describes the state numbers and tables used by __CxxFrameHandler3. This
160 /// analysis assumes that WinEHPrepare has already been run.
161 void calculateWinCXXEHStateNumbers(const Function *ParentFn,
162  WinEHFuncInfo &FuncInfo);
163 
164 }
165 #endif // LLVM_CODEGEN_WINEHFUNCINFO_H
ActionType getType() const
Definition: WinEHFuncInfo.h:39
SmallVector< WinEHHandlerType, 1 > HandlerArray
Various leaf nodes.
Definition: ISDOpcodes.h:60
ActionHandler(BasicBlock *BB, ActionType Type)
Definition: WinEHFuncInfo.h:36
F(f)
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
Definition: TinyPtrVector.h:26
BasicBlock * getNextBB() const
Definition: WinEHFuncInfo.h:72
static bool classof(const ActionHandler *H)
Definition: WinEHFuncInfo.h:67
void setEHState(int State)
Definition: WinEHFuncInfo.h:47
TinyPtrVector< BasicBlock * > & getReturnTargets()
Definition: WinEHFuncInfo.h:75
CleanupHandler(BasicBlock *BB)
int EHRegNodeEscapeIndex
localescape index of the 32-bit EH registration node.
void setHandlerBlockOrFunc(Constant *F)
Definition: WinEHFuncInfo.h:44
DenseMap< const Function *, const InvokeInst * > LastInvoke
DenseMap< const LandingPadInst *, int > LandingPadStateMap
void setExceptionVar(const Value *Val)
Definition: WinEHFuncInfo.h:77
DenseMap< const Function *, int > CatchHandlerParentFrameObjIdx
LLVM Basic Block Representation.
Definition: BasicBlock.h:65
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
int getExceptionVarIndex() const
Definition: WinEHFuncInfo.h:79
This is an important base class in LLVM.
Definition: Constant.h:41
#define H(x, y, z)
Definition: MD5.cpp:53
static bool classof(const ActionHandler *H)
DenseMap< const Function *, int > CatchHandlerParentFrameObjOffset
const Value * getExceptionVar()
Definition: WinEHFuncInfo.h:74
DenseMap< const Function *, int > CatchHandlerMaxState
void calculateWinCXXEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which describes the state number...
int getEHState() const
Definition: WinEHFuncInfo.h:48
Constant * getHandlerBlockOrFunc()
Definition: WinEHFuncInfo.h:45
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
CatchHandler(BasicBlock *BB, Constant *Selector, BasicBlock *NextBB)
Definition: WinEHFuncInfo.h:61
void setExceptionVarIndex(int Index)
Definition: WinEHFuncInfo.h:78
SmallVector< WinEHTryBlockMapEntry, 4 > TryBlockMap
GlobalVariable * TypeDescriptor
DenseMap< const Function *, bool > LastInvokeVisited
void setReturnTargets(TinyPtrVector< BasicBlock * > &Targets)
Definition: WinEHFuncInfo.h:80
BasicBlock * getStartBlock() const
Definition: WinEHFuncInfo.h:40
unsigned NumIPToStateFuncsVisited
DenseMap< const Function *, int > HandlerEnclosedState
SmallVector< std::pair< MCSymbol *, int >, 4 > IPToStateList
LLVM Value Representation.
Definition: Value.h:69
Constant * getSelector() const
Definition: WinEHFuncInfo.h:71
DenseMap< const Function *, int > HandlerBaseState
SmallVector< WinEHUnwindMapEntry, 4 > UnwindMap
void parseEHActions(const IntrinsicInst *II, SmallVectorImpl< std::unique_ptr< ActionHandler >> &Actions)
DenseMap< const Function *, const LandingPadInst * > RootLPad