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