X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=include%2Fllvm%2FCodeGen%2FWinEHFuncInfo.h;h=86ecce3561a606d924a2ccd3dd55fc7819dac9a4;hp=75638a058a3092186d014c9ba413cc8d9bfe3dc4;hb=52707d211b073942a461af811dcc442456a3064b;hpb=8f32e5f0d6f58bf19faeef36af60028c1ad7d21e diff --git a/include/llvm/CodeGen/WinEHFuncInfo.h b/include/llvm/CodeGen/WinEHFuncInfo.h index 75638a058a3..86ecce3561a 100644 --- a/include/llvm/CodeGen/WinEHFuncInfo.h +++ b/include/llvm/CodeGen/WinEHFuncInfo.h @@ -14,143 +14,101 @@ #ifndef LLVM_CODEGEN_WINEHFUNCINFO_H #define LLVM_CODEGEN_WINEHFUNCINFO_H +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/PointerUnion.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/TinyPtrVector.h" -#include "llvm/ADT/DenseMap.h" namespace llvm { +class AllocaInst; class BasicBlock; +class CatchReturnInst; class Constant; class Function; class GlobalVariable; class InvokeInst; class IntrinsicInst; class LandingPadInst; +class MCExpr; class MCSymbol; +class MachineBasicBlock; class Value; -enum ActionType { Catch, Cleanup }; - -class ActionHandler { -public: - ActionHandler(BasicBlock *BB, ActionType Type) - : StartBB(BB), Type(Type), EHState(-1), HandlerBlockOrFunc(nullptr) {} - - ActionType getType() const { return Type; } - BasicBlock *getStartBlock() const { return StartBB; } - - bool hasBeenProcessed() { return HandlerBlockOrFunc != nullptr; } +// The following structs respresent the .xdata tables for various +// Windows-related EH personalities. - void setHandlerBlockOrFunc(Constant *F) { HandlerBlockOrFunc = F; } - Constant *getHandlerBlockOrFunc() { return HandlerBlockOrFunc; } +typedef PointerUnion MBBOrBasicBlock; - void setEHState(int State) { EHState = State; } - int getEHState() const { return EHState; } - -private: - BasicBlock *StartBB; - ActionType Type; - int EHState; - - // Can be either a BlockAddress or a Function depending on the EH personality. - Constant *HandlerBlockOrFunc; -}; - -class CatchHandler : public ActionHandler { -public: - CatchHandler(BasicBlock *BB, Constant *Selector, BasicBlock *NextBB) - : ActionHandler(BB, ActionType::Catch), Selector(Selector), - NextBB(NextBB), ExceptionObjectVar(nullptr), - ExceptionObjectIndex(-1) {} - - // Method for support type inquiry through isa, cast, and dyn_cast: - static inline bool classof(const ActionHandler *H) { - return H->getType() == ActionType::Catch; - } - - Constant *getSelector() const { return Selector; } - BasicBlock *getNextBB() const { return NextBB; } - - const Value *getExceptionVar() { return ExceptionObjectVar; } - TinyPtrVector &getReturnTargets() { return ReturnTargets; } - - void setExceptionVar(const Value *Val) { ExceptionObjectVar = Val; } - void setExceptionVarIndex(int Index) { ExceptionObjectIndex = Index; } - int getExceptionVarIndex() const { return ExceptionObjectIndex; } - void setReturnTargets(TinyPtrVector &Targets) { - ReturnTargets = Targets; - } - -private: - Constant *Selector; - BasicBlock *NextBB; - // While catch handlers are being outlined the ExceptionObjectVar field will - // be populated with the instruction in the parent frame that corresponds - // to the exception object (or nullptr if the catch does not use an - // exception object) and the ExceptionObjectIndex field will be -1. - // When the parseEHActions function is called to populate a vector of - // instances of this class, the ExceptionObjectVar field will be nullptr - // and the ExceptionObjectIndex will be the index of the exception object in - // the parent function's localescape block. - const Value *ExceptionObjectVar; - int ExceptionObjectIndex; - TinyPtrVector ReturnTargets; +struct CxxUnwindMapEntry { + int ToState; + MBBOrBasicBlock Cleanup; }; -class CleanupHandler : public ActionHandler { -public: - CleanupHandler(BasicBlock *BB) : ActionHandler(BB, ActionType::Cleanup) {} +/// Similar to CxxUnwindMapEntry, but supports SEH filters. +struct SEHUnwindMapEntry { + /// If unwinding continues through this handler, transition to the handler at + /// this state. This indexes into SEHUnwindMap. + int ToState = -1; - // Method for support type inquiry through isa, cast, and dyn_cast: - static inline bool classof(const ActionHandler *H) { - return H->getType() == ActionType::Cleanup; - } -}; - -void parseEHActions(const IntrinsicInst *II, - SmallVectorImpl> &Actions); + bool IsFinally = false; -// The following structs respresent the .xdata for functions using C++ -// exceptions on Windows. + /// Holds the filter expression function. + const Function *Filter = nullptr; -struct WinEHUnwindMapEntry { - int ToState; - Function *Cleanup; + /// Holds the __except or __finally basic block. + MBBOrBasicBlock Handler; }; struct WinEHHandlerType { int Adjectives; + /// The CatchObj starts out life as an LLVM alloca and is eventually turned + /// frame index. + union { + const AllocaInst *Alloca; + int FrameIndex; + } CatchObj = {}; GlobalVariable *TypeDescriptor; - int CatchObjRecoverIdx; - Function *Handler; + MBBOrBasicBlock Handler; }; struct WinEHTryBlockMapEntry { - int TryLow; - int TryHigh; + int TryLow = -1; + int TryHigh = -1; + int CatchHigh = -1; SmallVector HandlerArray; }; +enum class ClrHandlerType { Catch, Finally, Fault, Filter }; + +struct ClrEHUnwindMapEntry { + MBBOrBasicBlock Handler; + uint32_t TypeToken; + int Parent; + ClrHandlerType HandlerType; +}; + struct WinEHFuncInfo { - DenseMap RootLPad; - DenseMap LastInvoke; - DenseMap HandlerEnclosedState; - DenseMap LastInvokeVisited; - DenseMap LandingPadStateMap; - DenseMap CatchHandlerParentFrameObjIdx; - DenseMap CatchHandlerParentFrameObjOffset; - DenseMap CatchHandlerMaxState; - DenseMap HandlerBaseState; - SmallVector UnwindMap; + DenseMap EHPadStateMap; + DenseMap FuncletBaseStateMap; + DenseMap InvokeStateMap; + DenseMap + CatchRetSuccessorColorMap; + DenseMap> LabelToStateMap; + SmallVector CxxUnwindMap; SmallVector TryBlockMap; - SmallVector, 4> IPToStateList; + SmallVector SEHUnwindMap; + SmallVector ClrEHUnwindMap; int UnwindHelpFrameIdx = INT_MAX; - int UnwindHelpFrameOffset = -1; - unsigned NumIPToStateFuncsVisited = 0; + int PSPSymFrameIdx = INT_MAX; + + int getLastStateNumber() const { return CxxUnwindMap.size() - 1; } + + void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin, + MCSymbol *InvokeEnd); - /// localescape index of the 32-bit EH registration node. Set by - /// WinEHStatePass and used indirectly by SEH filter functions of the parent. - int EHRegNodeEscapeIndex = INT_MAX; + int EHRegNodeFrameIndex = INT_MAX; + int EHRegNodeEndOffset = INT_MAX; + int SEHSetFrameOffset = INT_MAX; WinEHFuncInfo() {} }; @@ -161,5 +119,12 @@ struct WinEHFuncInfo { void calculateWinCXXEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo); +void calculateSEHStateNumbers(const Function *ParentFn, + WinEHFuncInfo &FuncInfo); + +void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo); + +void calculateCatchReturnSuccessorColors(const Function *Fn, + WinEHFuncInfo &FuncInfo); } #endif // LLVM_CODEGEN_WINEHFUNCINFO_H