Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 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" |
Bob Haarman | 223303c | 2017-08-29 20:59:25 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/Optional.h" |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/LexicalScopes.h" |
Benjamin Kramer | 3a16e2a | 2016-02-18 18:02:48 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineInstr.h" |
Bob Haarman | 223303c | 2017-08-29 20:59:25 +0000 | [diff] [blame] | 23 | #include "llvm/IR/DebugInfoMetadata.h" |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 24 | |
| 25 | namespace llvm { |
| 26 | |
| 27 | class AsmPrinter; |
Bob Haarman | 223303c | 2017-08-29 20:59:25 +0000 | [diff] [blame] | 28 | class MachineInstr; |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 29 | class MachineModuleInfo; |
| 30 | |
Bob Haarman | 223303c | 2017-08-29 20:59:25 +0000 | [diff] [blame] | 31 | /// Represents the location at which a variable is stored. |
| 32 | struct DbgVariableLocation { |
Bob Haarman | 223303c | 2017-08-29 20:59:25 +0000 | [diff] [blame] | 33 | /// Base register. |
| 34 | unsigned Register; |
| 35 | |
Reid Kleckner | 08f5fd5 | 2017-08-31 15:56:49 +0000 | [diff] [blame] | 36 | /// Chain of offsetted loads necessary to load the value if it lives in |
| 37 | /// memory. Every load except for the last is pointer-sized. |
| 38 | SmallVector<int64_t, 1> LoadChain; |
Bob Haarman | 223303c | 2017-08-29 20:59:25 +0000 | [diff] [blame] | 39 | |
| 40 | /// Present if the location is part of a larger variable. |
| 41 | llvm::Optional<llvm::DIExpression::FragmentInfo> FragmentInfo; |
| 42 | |
Bob Haarman | 1a4cbbe | 2017-08-30 17:50:21 +0000 | [diff] [blame] | 43 | /// Extract a VariableLocation from a MachineInstr. |
| 44 | /// This will only work if Instruction is a debug value instruction |
| 45 | /// and the associated DIExpression is in one of the supported forms. |
| 46 | /// If these requirements are not met, the returned Optional will not |
| 47 | /// have a value. |
| 48 | static Optional<DbgVariableLocation> |
| 49 | extractFromMachineInstruction(const MachineInstr &Instruction); |
Bob Haarman | 223303c | 2017-08-29 20:59:25 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 52 | /// Base class for debug information backends. Common functionality related to |
| 53 | /// tracking which variables and scopes are alive at a given PC live here. |
Benjamin Kramer | e3b963d | 2016-02-11 15:41:56 +0000 | [diff] [blame] | 54 | class DebugHandlerBase : public AsmPrinterHandler { |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 55 | protected: |
| 56 | DebugHandlerBase(AsmPrinter *A); |
| 57 | |
| 58 | /// Target of debug info emission. |
| 59 | AsmPrinter *Asm; |
| 60 | |
| 61 | /// Collected machine module information. |
| 62 | MachineModuleInfo *MMI; |
| 63 | |
| 64 | /// Previous instruction's location information. This is used to |
Paul Robinson | ac7fe5e | 2016-12-12 20:49:11 +0000 | [diff] [blame] | 65 | /// determine label location to indicate scope boundaries in debug info. |
| 66 | /// We track the previous instruction's source location (if not line 0), |
| 67 | /// whether it was a label, and its parent BB. |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 68 | DebugLoc PrevInstLoc; |
| 69 | MCSymbol *PrevLabel = nullptr; |
Paul Robinson | ac7fe5e | 2016-12-12 20:49:11 +0000 | [diff] [blame] | 70 | const MachineBasicBlock *PrevInstBB = nullptr; |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 71 | |
| 72 | /// This location indicates end of function prologue and beginning of |
| 73 | /// function body. |
| 74 | DebugLoc PrologEndLoc; |
| 75 | |
| 76 | /// If nonnull, stores the current machine instruction we're processing. |
| 77 | const MachineInstr *CurMI = nullptr; |
| 78 | |
| 79 | LexicalScopes LScopes; |
| 80 | |
| 81 | /// History of DBG_VALUE and clobber instructions for each user |
| 82 | /// variable. Variables are listed in order of appearance. |
| 83 | DbgValueHistoryMap DbgValues; |
| 84 | |
| 85 | /// Maps instruction with label emitted before instruction. |
| 86 | /// FIXME: Make this private from DwarfDebug, we have the necessary accessors |
| 87 | /// for it. |
| 88 | DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn; |
| 89 | |
| 90 | /// Maps instruction with label emitted after instruction. |
| 91 | DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn; |
| 92 | |
| 93 | /// Indentify instructions that are marking the beginning of or |
| 94 | /// ending of a scope. |
| 95 | void identifyScopeMarkers(); |
| 96 | |
| 97 | /// Ensure that a label will be emitted before MI. |
| 98 | void requestLabelBeforeInsn(const MachineInstr *MI) { |
| 99 | LabelsBeforeInsn.insert(std::make_pair(MI, nullptr)); |
| 100 | } |
| 101 | |
| 102 | /// Ensure that a label will be emitted after MI. |
| 103 | void requestLabelAfterInsn(const MachineInstr *MI) { |
| 104 | LabelsAfterInsn.insert(std::make_pair(MI, nullptr)); |
| 105 | } |
| 106 | |
David Blaikie | b2fbb4b | 2017-02-16 18:48:33 +0000 | [diff] [blame] | 107 | virtual void beginFunctionImpl(const MachineFunction *MF) = 0; |
| 108 | virtual void endFunctionImpl(const MachineFunction *MF) = 0; |
| 109 | virtual void skippedNonDebugFunction() {} |
| 110 | |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 111 | // AsmPrinterHandler overrides. |
| 112 | public: |
| 113 | void beginInstruction(const MachineInstr *MI) override; |
| 114 | void endInstruction() override; |
| 115 | |
| 116 | void beginFunction(const MachineFunction *MF) override; |
| 117 | void endFunction(const MachineFunction *MF) override; |
| 118 | |
| 119 | /// Return Label preceding the instruction. |
| 120 | MCSymbol *getLabelBeforeInsn(const MachineInstr *MI); |
| 121 | |
| 122 | /// Return Label immediately following the instruction. |
| 123 | MCSymbol *getLabelAfterInsn(const MachineInstr *MI); |
| 124 | |
Amjad Aboud | acee568 | 2016-07-12 12:06:34 +0000 | [diff] [blame] | 125 | /// If this type is derived from a base type then return base type size. |
| 126 | static uint64_t getBaseTypeSize(const DITypeRef TyRef); |
Reid Kleckner | f9c275f | 2016-02-10 20:55:49 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | } |
| 130 | |
| 131 | #endif |