LLVM 19.0.0git
DebugHandlerBase.h
Go to the documentation of this file.
1//===-- llvm/CodeGen/DebugHandlerBase.h -----------------------*- C++ -*--===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Common functionality for different debug information format backends.
10// LLVM currently supports DWARF and CodeView.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CODEGEN_DEBUGHANDLERBASE_H
15#define LLVM_CODEGEN_DEBUGHANDLERBASE_H
16
21#include "llvm/IR/DebugLoc.h"
22#include <optional>
23
24namespace llvm {
25
26class AsmPrinter;
27class MachineInstr;
28class MachineModuleInfo;
29
30/// Represents the location at which a variable is stored.
32 /// Base register.
33 unsigned Register;
34
35 /// Chain of offsetted loads necessary to load the value if it lives in
36 /// memory. Every load except for the last is pointer-sized.
38
39 /// Present if the location is part of a larger variable.
40 std::optional<llvm::DIExpression::FragmentInfo> FragmentInfo;
41
42 /// Extract a VariableLocation from a MachineInstr.
43 /// This will only work if Instruction is a debug value instruction
44 /// and the associated DIExpression is in one of the supported forms.
45 /// If these requirements are not met, the returned Optional will not
46 /// have a value.
47 static std::optional<DbgVariableLocation>
49};
50
51/// Base class for debug information backends. Common functionality related to
52/// tracking which variables and scopes are alive at a given PC live here.
54protected:
56
57 /// Target of debug info emission.
58 AsmPrinter *Asm = nullptr;
59
60 /// Collected machine module information.
62
63 /// Previous instruction's location information. This is used to
64 /// determine label location to indicate scope boundaries in debug info.
65 /// We track the previous instruction's source location (if not line 0),
66 /// whether it was a label, and its parent BB.
68 MCSymbol *PrevLabel = nullptr;
69 const MachineBasicBlock *PrevInstBB = nullptr;
70
71 /// This location indicates end of function prologue and beginning of
72 /// function body.
74
75 /// This block includes epilogue instructions.
77
78 /// If nonnull, stores the current machine instruction we're processing.
79 const MachineInstr *CurMI = nullptr;
80
82
83 /// History of DBG_VALUE and clobber instructions for each user
84 /// variable. Variables are listed in order of appearance.
86
87 /// Mapping of inlined labels and DBG_LABEL machine instruction.
89
90 /// Maps instruction with label emitted before instruction.
91 /// FIXME: Make this private from DwarfDebug, we have the necessary accessors
92 /// for it.
94
95 /// Maps instruction with label emitted after instruction.
97
98 /// Indentify instructions that are marking the beginning of or
99 /// ending of a scope.
101
102 /// Ensure that a label will be emitted before MI.
104 LabelsBeforeInsn.insert(std::make_pair(MI, nullptr));
105 }
106
107 /// Ensure that a label will be emitted after MI.
109 LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
110 }
111
112 virtual void beginFunctionImpl(const MachineFunction *MF) = 0;
113 virtual void endFunctionImpl(const MachineFunction *MF) = 0;
114 virtual void skippedNonDebugFunction() {}
115
116private:
117 InstructionOrdering InstOrdering;
118
119 // AsmPrinterHandler overrides.
120public:
121 void beginModule(Module *M) override;
122
123 void beginInstruction(const MachineInstr *MI) override;
124 void endInstruction() override;
125
126 void beginFunction(const MachineFunction *MF) override;
127 void endFunction(const MachineFunction *MF) override;
128
129 void beginBasicBlockSection(const MachineBasicBlock &MBB) override;
130 void endBasicBlockSection(const MachineBasicBlock &MBB) override;
131
132 /// Return Label preceding the instruction.
134
135 /// Return Label immediately following the instruction.
137
138 /// If this type is derived from a base type then return base type size.
139 static uint64_t getBaseTypeSize(const DIType *Ty);
140
141 /// Return true if type encoding is unsigned.
142 static bool isUnsignedDIType(const DIType *Ty);
143
144 const InstructionOrdering &getInstOrdering() const { return InstOrdering; }
145};
146
147} // namespace llvm
148
149#endif
MachineBasicBlock & MBB
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
IRTranslator LLVM IR MI
Collects and handles AsmPrinter objects required to build debug or EH information.
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:85
Base class for types.
For each inlined instance of a source-level label, keep the corresponding DBG_LABEL instruction.
For each user variable, keep a list of instruction ranges where this variable is accessible.
Base class for debug information backends.
static bool isUnsignedDIType(const DIType *Ty)
Return true if type encoding is unsigned.
const MachineInstr * CurMI
If nonnull, stores the current machine instruction we're processing.
AsmPrinter * Asm
Target of debug info emission.
virtual void endFunctionImpl(const MachineFunction *MF)=0
MCSymbol * getLabelBeforeInsn(const MachineInstr *MI)
Return Label preceding the instruction.
MachineModuleInfo * MMI
Collected machine module information.
void endBasicBlockSection(const MachineBasicBlock &MBB) override
Process the end of a basic-block-section within a function.
void identifyScopeMarkers()
Indentify instructions that are marking the beginning of or ending of a scope.
virtual void skippedNonDebugFunction()
void endFunction(const MachineFunction *MF) override
Gather post-function debug information.
DebugLoc PrevInstLoc
Previous instruction's location information.
void beginFunction(const MachineFunction *MF) override
Gather pre-function debug information.
void endInstruction() override
Process end of an instruction.
DebugLoc PrologEndLoc
This location indicates end of function prologue and beginning of function body.
MCSymbol * getLabelAfterInsn(const MachineInstr *MI)
Return Label immediately following the instruction.
void beginInstruction(const MachineInstr *MI) override
Process beginning of an instruction.
const MachineBasicBlock * PrevInstBB
virtual void beginFunctionImpl(const MachineFunction *MF)=0
void requestLabelAfterInsn(const MachineInstr *MI)
Ensure that a label will be emitted after MI.
void beginBasicBlockSection(const MachineBasicBlock &MBB) override
Process the beginning of a new basic-block-section within a function.
DbgValueHistoryMap DbgValues
History of DBG_VALUE and clobber instructions for each user variable.
DbgLabelInstrMap DbgLabels
Mapping of inlined labels and DBG_LABEL machine instruction.
DenseMap< const MachineInstr *, MCSymbol * > LabelsBeforeInsn
Maps instruction with label emitted before instruction.
void beginModule(Module *M) override
const InstructionOrdering & getInstOrdering() const
DenseMap< const MachineInstr *, MCSymbol * > LabelsAfterInsn
Maps instruction with label emitted after instruction.
void requestLabelBeforeInsn(const MachineInstr *MI)
Ensure that a label will be emitted before MI.
const MachineBasicBlock * EpilogBeginBlock
This block includes epilogue instructions.
static uint64_t getBaseTypeSize(const DIType *Ty)
If this type is derived from a base type then return base type size.
A debug info location.
Definition: DebugLoc.h:33
Record instruction ordering so we can query their relative positions within a function.
LexicalScopes - This class provides interface to collect and use lexical scoping information from mac...
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
Representation of each machine instruction.
Definition: MachineInstr.h:69
This class contains meta information specific to a module.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Represents the location at which a variable is stored.
std::optional< llvm::DIExpression::FragmentInfo > FragmentInfo
Present if the location is part of a larger variable.
unsigned Register
Base register.
static std::optional< DbgVariableLocation > extractFromMachineInstruction(const MachineInstr &Instruction)
Extract a VariableLocation from a MachineInstr.
SmallVector< int64_t, 1 > LoadChain
Chain of offsetted loads necessary to load the value if it lives in memory.