1*9880d681SAndroid Build Coastguard Worker //===-- llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.h --------*- 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 // Common functionality for different debug information format backends. 11*9880d681SAndroid Build Coastguard Worker // LLVM currently supports DWARF and CodeView. 12*9880d681SAndroid Build Coastguard Worker // 13*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 14*9880d681SAndroid Build Coastguard Worker 15*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DEBUGHANDLERBASE_H 16*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_CODEGEN_ASMPRINTER_DEBUGHANDLERBASE_H 17*9880d681SAndroid Build Coastguard Worker 18*9880d681SAndroid Build Coastguard Worker #include "AsmPrinterHandler.h" 19*9880d681SAndroid Build Coastguard Worker #include "DbgValueHistoryCalculator.h" 20*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/LexicalScopes.h" 21*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineInstr.h" 22*9880d681SAndroid Build Coastguard Worker 23*9880d681SAndroid Build Coastguard Worker namespace llvm { 24*9880d681SAndroid Build Coastguard Worker 25*9880d681SAndroid Build Coastguard Worker class AsmPrinter; 26*9880d681SAndroid Build Coastguard Worker class MachineModuleInfo; 27*9880d681SAndroid Build Coastguard Worker 28*9880d681SAndroid Build Coastguard Worker /// Base class for debug information backends. Common functionality related to 29*9880d681SAndroid Build Coastguard Worker /// tracking which variables and scopes are alive at a given PC live here. 30*9880d681SAndroid Build Coastguard Worker class DebugHandlerBase : public AsmPrinterHandler { 31*9880d681SAndroid Build Coastguard Worker protected: 32*9880d681SAndroid Build Coastguard Worker DebugHandlerBase(AsmPrinter *A); 33*9880d681SAndroid Build Coastguard Worker 34*9880d681SAndroid Build Coastguard Worker /// Target of debug info emission. 35*9880d681SAndroid Build Coastguard Worker AsmPrinter *Asm; 36*9880d681SAndroid Build Coastguard Worker 37*9880d681SAndroid Build Coastguard Worker /// Collected machine module information. 38*9880d681SAndroid Build Coastguard Worker MachineModuleInfo *MMI; 39*9880d681SAndroid Build Coastguard Worker 40*9880d681SAndroid Build Coastguard Worker /// Previous instruction's location information. This is used to 41*9880d681SAndroid Build Coastguard Worker /// determine label location to indicate scope boundries in dwarf 42*9880d681SAndroid Build Coastguard Worker /// debug info. 43*9880d681SAndroid Build Coastguard Worker DebugLoc PrevInstLoc; 44*9880d681SAndroid Build Coastguard Worker MCSymbol *PrevLabel = nullptr; 45*9880d681SAndroid Build Coastguard Worker 46*9880d681SAndroid Build Coastguard Worker /// This location indicates end of function prologue and beginning of 47*9880d681SAndroid Build Coastguard Worker /// function body. 48*9880d681SAndroid Build Coastguard Worker DebugLoc PrologEndLoc; 49*9880d681SAndroid Build Coastguard Worker 50*9880d681SAndroid Build Coastguard Worker /// If nonnull, stores the current machine instruction we're processing. 51*9880d681SAndroid Build Coastguard Worker const MachineInstr *CurMI = nullptr; 52*9880d681SAndroid Build Coastguard Worker 53*9880d681SAndroid Build Coastguard Worker LexicalScopes LScopes; 54*9880d681SAndroid Build Coastguard Worker 55*9880d681SAndroid Build Coastguard Worker /// History of DBG_VALUE and clobber instructions for each user 56*9880d681SAndroid Build Coastguard Worker /// variable. Variables are listed in order of appearance. 57*9880d681SAndroid Build Coastguard Worker DbgValueHistoryMap DbgValues; 58*9880d681SAndroid Build Coastguard Worker 59*9880d681SAndroid Build Coastguard Worker /// Maps instruction with label emitted before instruction. 60*9880d681SAndroid Build Coastguard Worker /// FIXME: Make this private from DwarfDebug, we have the necessary accessors 61*9880d681SAndroid Build Coastguard Worker /// for it. 62*9880d681SAndroid Build Coastguard Worker DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn; 63*9880d681SAndroid Build Coastguard Worker 64*9880d681SAndroid Build Coastguard Worker /// Maps instruction with label emitted after instruction. 65*9880d681SAndroid Build Coastguard Worker DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn; 66*9880d681SAndroid Build Coastguard Worker 67*9880d681SAndroid Build Coastguard Worker /// Indentify instructions that are marking the beginning of or 68*9880d681SAndroid Build Coastguard Worker /// ending of a scope. 69*9880d681SAndroid Build Coastguard Worker void identifyScopeMarkers(); 70*9880d681SAndroid Build Coastguard Worker 71*9880d681SAndroid Build Coastguard Worker /// Ensure that a label will be emitted before MI. requestLabelBeforeInsn(const MachineInstr * MI)72*9880d681SAndroid Build Coastguard Worker void requestLabelBeforeInsn(const MachineInstr *MI) { 73*9880d681SAndroid Build Coastguard Worker LabelsBeforeInsn.insert(std::make_pair(MI, nullptr)); 74*9880d681SAndroid Build Coastguard Worker } 75*9880d681SAndroid Build Coastguard Worker 76*9880d681SAndroid Build Coastguard Worker /// Ensure that a label will be emitted after MI. requestLabelAfterInsn(const MachineInstr * MI)77*9880d681SAndroid Build Coastguard Worker void requestLabelAfterInsn(const MachineInstr *MI) { 78*9880d681SAndroid Build Coastguard Worker LabelsAfterInsn.insert(std::make_pair(MI, nullptr)); 79*9880d681SAndroid Build Coastguard Worker } 80*9880d681SAndroid Build Coastguard Worker 81*9880d681SAndroid Build Coastguard Worker // AsmPrinterHandler overrides. 82*9880d681SAndroid Build Coastguard Worker public: 83*9880d681SAndroid Build Coastguard Worker void beginInstruction(const MachineInstr *MI) override; 84*9880d681SAndroid Build Coastguard Worker void endInstruction() override; 85*9880d681SAndroid Build Coastguard Worker 86*9880d681SAndroid Build Coastguard Worker void beginFunction(const MachineFunction *MF) override; 87*9880d681SAndroid Build Coastguard Worker void endFunction(const MachineFunction *MF) override; 88*9880d681SAndroid Build Coastguard Worker 89*9880d681SAndroid Build Coastguard Worker /// Return Label preceding the instruction. 90*9880d681SAndroid Build Coastguard Worker MCSymbol *getLabelBeforeInsn(const MachineInstr *MI); 91*9880d681SAndroid Build Coastguard Worker 92*9880d681SAndroid Build Coastguard Worker /// Return Label immediately following the instruction. 93*9880d681SAndroid Build Coastguard Worker MCSymbol *getLabelAfterInsn(const MachineInstr *MI); 94*9880d681SAndroid Build Coastguard Worker 95*9880d681SAndroid Build Coastguard Worker /// Determine the relative position of the pieces described by P1 and P2. 96*9880d681SAndroid Build Coastguard Worker /// Returns -1 if P1 is entirely before P2, 0 if P1 and P2 overlap, 97*9880d681SAndroid Build Coastguard Worker /// 1 if P1 is entirely after P2. 98*9880d681SAndroid Build Coastguard Worker static int pieceCmp(const DIExpression *P1, const DIExpression *P2); 99*9880d681SAndroid Build Coastguard Worker 100*9880d681SAndroid Build Coastguard Worker /// Determine whether two variable pieces overlap. 101*9880d681SAndroid Build Coastguard Worker static bool piecesOverlap(const DIExpression *P1, const DIExpression *P2); 102*9880d681SAndroid Build Coastguard Worker 103*9880d681SAndroid Build Coastguard Worker /// If this type is derived from a base type then return base type size. 104*9880d681SAndroid Build Coastguard Worker static uint64_t getBaseTypeSize(const DITypeRef TyRef); 105*9880d681SAndroid Build Coastguard Worker }; 106*9880d681SAndroid Build Coastguard Worker 107*9880d681SAndroid Build Coastguard Worker } 108*9880d681SAndroid Build Coastguard Worker 109*9880d681SAndroid Build Coastguard Worker #endif 110