1*9880d681SAndroid Build Coastguard Worker //===-- WinException.h - Windows Exception Handling ----------*- C++ -*--===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // This file contains support for writing windows exception info into asm files. 11*9880d681SAndroid Build Coastguard Worker // 12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_WIN64EXCEPTION_H 15*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_CODEGEN_ASMPRINTER_WIN64EXCEPTION_H 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Worker #include "EHStreamer.h" 18*9880d681SAndroid Build Coastguard Worker 19*9880d681SAndroid Build Coastguard Worker namespace llvm { 20*9880d681SAndroid Build Coastguard Worker class Function; 21*9880d681SAndroid Build Coastguard Worker class GlobalValue; 22*9880d681SAndroid Build Coastguard Worker class MachineFunction; 23*9880d681SAndroid Build Coastguard Worker class MCExpr; 24*9880d681SAndroid Build Coastguard Worker class Value; 25*9880d681SAndroid Build Coastguard Worker struct WinEHFuncInfo; 26*9880d681SAndroid Build Coastguard Worker 27*9880d681SAndroid Build Coastguard Worker class LLVM_LIBRARY_VISIBILITY WinException : public EHStreamer { 28*9880d681SAndroid Build Coastguard Worker /// Per-function flag to indicate if personality info should be emitted. 29*9880d681SAndroid Build Coastguard Worker bool shouldEmitPersonality = false; 30*9880d681SAndroid Build Coastguard Worker 31*9880d681SAndroid Build Coastguard Worker /// Per-function flag to indicate if the LSDA should be emitted. 32*9880d681SAndroid Build Coastguard Worker bool shouldEmitLSDA = false; 33*9880d681SAndroid Build Coastguard Worker 34*9880d681SAndroid Build Coastguard Worker /// Per-function flag to indicate if frame moves info should be emitted. 35*9880d681SAndroid Build Coastguard Worker bool shouldEmitMoves = false; 36*9880d681SAndroid Build Coastguard Worker 37*9880d681SAndroid Build Coastguard Worker /// True if this is a 64-bit target and we should use image relative offsets. 38*9880d681SAndroid Build Coastguard Worker bool useImageRel32 = false; 39*9880d681SAndroid Build Coastguard Worker 40*9880d681SAndroid Build Coastguard Worker /// Pointer to the current funclet entry BB. 41*9880d681SAndroid Build Coastguard Worker const MachineBasicBlock *CurrentFuncletEntry = nullptr; 42*9880d681SAndroid Build Coastguard Worker 43*9880d681SAndroid Build Coastguard Worker void emitCSpecificHandlerTable(const MachineFunction *MF); 44*9880d681SAndroid Build Coastguard Worker 45*9880d681SAndroid Build Coastguard Worker void emitSEHActionsForRange(const WinEHFuncInfo &FuncInfo, 46*9880d681SAndroid Build Coastguard Worker const MCSymbol *BeginLabel, 47*9880d681SAndroid Build Coastguard Worker const MCSymbol *EndLabel, int State); 48*9880d681SAndroid Build Coastguard Worker 49*9880d681SAndroid Build Coastguard Worker /// Emit the EH table data for 32-bit and 64-bit functions using 50*9880d681SAndroid Build Coastguard Worker /// the __CxxFrameHandler3 personality. 51*9880d681SAndroid Build Coastguard Worker void emitCXXFrameHandler3Table(const MachineFunction *MF); 52*9880d681SAndroid Build Coastguard Worker 53*9880d681SAndroid Build Coastguard Worker /// Emit the EH table data for _except_handler3 and _except_handler4 54*9880d681SAndroid Build Coastguard Worker /// personality functions. These are only used on 32-bit and do not use CFI 55*9880d681SAndroid Build Coastguard Worker /// tables. 56*9880d681SAndroid Build Coastguard Worker void emitExceptHandlerTable(const MachineFunction *MF); 57*9880d681SAndroid Build Coastguard Worker 58*9880d681SAndroid Build Coastguard Worker void emitCLRExceptionTable(const MachineFunction *MF); 59*9880d681SAndroid Build Coastguard Worker 60*9880d681SAndroid Build Coastguard Worker void computeIP2StateTable( 61*9880d681SAndroid Build Coastguard Worker const MachineFunction *MF, const WinEHFuncInfo &FuncInfo, 62*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<std::pair<const MCExpr *, int>> &IPToStateTable); 63*9880d681SAndroid Build Coastguard Worker 64*9880d681SAndroid Build Coastguard Worker /// Emits the label used with llvm.x86.seh.recoverfp, which is used by 65*9880d681SAndroid Build Coastguard Worker /// outlined funclets. 66*9880d681SAndroid Build Coastguard Worker void emitEHRegistrationOffsetLabel(const WinEHFuncInfo &FuncInfo, 67*9880d681SAndroid Build Coastguard Worker StringRef FLinkageName); 68*9880d681SAndroid Build Coastguard Worker 69*9880d681SAndroid Build Coastguard Worker const MCExpr *create32bitRef(const MCSymbol *Value); 70*9880d681SAndroid Build Coastguard Worker const MCExpr *create32bitRef(const GlobalValue *GV); 71*9880d681SAndroid Build Coastguard Worker const MCExpr *getLabelPlusOne(const MCSymbol *Label); 72*9880d681SAndroid Build Coastguard Worker const MCExpr *getOffset(const MCSymbol *OffsetOf, const MCSymbol *OffsetFrom); 73*9880d681SAndroid Build Coastguard Worker const MCExpr *getOffsetPlusOne(const MCSymbol *OffsetOf, 74*9880d681SAndroid Build Coastguard Worker const MCSymbol *OffsetFrom); 75*9880d681SAndroid Build Coastguard Worker 76*9880d681SAndroid Build Coastguard Worker /// Gets the offset that we should use in a table for a stack object with the 77*9880d681SAndroid Build Coastguard Worker /// given index. For targets using CFI (Win64, etc), this is relative to the 78*9880d681SAndroid Build Coastguard Worker /// established SP at the end of the prologue. For targets without CFI (Win32 79*9880d681SAndroid Build Coastguard Worker /// only), it is relative to the frame pointer. 80*9880d681SAndroid Build Coastguard Worker int getFrameIndexOffset(int FrameIndex, const WinEHFuncInfo &FuncInfo); 81*9880d681SAndroid Build Coastguard Worker 82*9880d681SAndroid Build Coastguard Worker public: 83*9880d681SAndroid Build Coastguard Worker //===--------------------------------------------------------------------===// 84*9880d681SAndroid Build Coastguard Worker // Main entry points. 85*9880d681SAndroid Build Coastguard Worker // 86*9880d681SAndroid Build Coastguard Worker WinException(AsmPrinter *A); 87*9880d681SAndroid Build Coastguard Worker ~WinException() override; 88*9880d681SAndroid Build Coastguard Worker 89*9880d681SAndroid Build Coastguard Worker /// Emit all exception information that should come after the content. 90*9880d681SAndroid Build Coastguard Worker void endModule() override; 91*9880d681SAndroid Build Coastguard Worker 92*9880d681SAndroid Build Coastguard Worker /// Gather pre-function exception information. Assumes being emitted 93*9880d681SAndroid Build Coastguard Worker /// immediately after the function entry point. 94*9880d681SAndroid Build Coastguard Worker void beginFunction(const MachineFunction *MF) override; 95*9880d681SAndroid Build Coastguard Worker 96*9880d681SAndroid Build Coastguard Worker /// Gather and emit post-function exception information. 97*9880d681SAndroid Build Coastguard Worker void endFunction(const MachineFunction *) override; 98*9880d681SAndroid Build Coastguard Worker 99*9880d681SAndroid Build Coastguard Worker /// \brief Emit target-specific EH funclet machinery. 100*9880d681SAndroid Build Coastguard Worker void beginFunclet(const MachineBasicBlock &MBB, MCSymbol *Sym) override; 101*9880d681SAndroid Build Coastguard Worker void endFunclet() override; 102*9880d681SAndroid Build Coastguard Worker }; 103*9880d681SAndroid Build Coastguard Worker } 104*9880d681SAndroid Build Coastguard Worker 105*9880d681SAndroid Build Coastguard Worker #endif 106*9880d681SAndroid Build Coastguard Worker 107