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/SmallVector.h"
18 #include "llvm/ADT/TinyPtrVector.h"
19 #include "llvm/ADT/DenseMap.h"
30 enum ActionType { Catch, Cleanup };
34 ActionHandler(BasicBlock *BB, ActionType Type)
35 : StartBB(BB), Type(Type), EHState(-1), HandlerBlockOrFunc(nullptr) {}
37 ActionType getType() const { return Type; }
38 BasicBlock *getStartBlock() const { return StartBB; }
40 bool hasBeenProcessed() { return HandlerBlockOrFunc != nullptr; }
42 void setHandlerBlockOrFunc(Constant *F) { HandlerBlockOrFunc = F; }
43 Constant *getHandlerBlockOrFunc() { return HandlerBlockOrFunc; }
45 void setEHState(int State) { EHState = State; }
46 int getEHState() const { return EHState; }
53 // Can be either a BlockAddress or a Function depending on the EH personality.
54 Constant *HandlerBlockOrFunc;
57 class CatchHandler : public ActionHandler {
59 CatchHandler(BasicBlock *BB, Constant *Selector, BasicBlock *NextBB)
60 : ActionHandler(BB, ActionType::Catch), Selector(Selector),
61 NextBB(NextBB), ExceptionObjectVar(nullptr) {}
63 // Method for support type inquiry through isa, cast, and dyn_cast:
64 static inline bool classof(const ActionHandler *H) {
65 return H->getType() == ActionType::Catch;
68 Constant *getSelector() const { return Selector; }
69 BasicBlock *getNextBB() const { return NextBB; }
71 const Value *getExceptionVar() { return ExceptionObjectVar; }
72 TinyPtrVector<BasicBlock *> &getReturnTargets() { return ReturnTargets; }
74 void setExceptionVar(const Value *Val) { ExceptionObjectVar = Val; }
75 void setReturnTargets(TinyPtrVector<BasicBlock *> &Targets) {
76 ReturnTargets = Targets;
82 const Value *ExceptionObjectVar;
83 TinyPtrVector<BasicBlock *> ReturnTargets;
86 class CleanupHandler : public ActionHandler {
88 CleanupHandler(BasicBlock *BB) : ActionHandler(BB, ActionType::Cleanup) {}
90 // Method for support type inquiry through isa, cast, and dyn_cast:
91 static inline bool classof(const ActionHandler *H) {
92 return H->getType() == ActionType::Cleanup;
96 // The following structs respresent the .xdata for functions using C++
97 // exceptions on Windows.
99 struct WinEHUnwindMapEntry {
104 struct WinEHHandlerType {
106 GlobalVariable *TypeDescriptor;
112 struct WinEHTryBlockMapEntry {
116 SmallVector<WinEHHandlerType, 1> HandlerArray;
119 struct WinEHFuncInfo {
120 DenseMap<const LandingPadInst *, int> LandingPadStateMap;
121 DenseMap<const Function *, int> CatchHandlerParentFrameObjIdx;
122 DenseMap<const Function *, int> CatchHandlerParentFrameObjOffset;
123 SmallVector<WinEHUnwindMapEntry, 4> UnwindMap;
124 SmallVector<WinEHTryBlockMapEntry, 4> TryBlockMap;
125 SmallVector<std::pair<MCSymbol *, int>, 4> IPToStateList;
126 int UnwindHelpFrameIdx;
127 int UnwindHelpFrameOffset;
129 WinEHFuncInfo() : UnwindHelpFrameIdx(INT_MAX), UnwindHelpFrameOffset(-1) {}
133 #endif // LLVM_CODEGEN_WINEHFUNCINFO_H