File indexing completed on 2026-05-10 08:43:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CODEGEN_DEBUGHANDLERBASE_H
0015 #define LLVM_CODEGEN_DEBUGHANDLERBASE_H
0016
0017 #include "llvm/CodeGen/AsmPrinterHandler.h"
0018 #include "llvm/CodeGen/DbgEntityHistoryCalculator.h"
0019 #include "llvm/CodeGen/LexicalScopes.h"
0020 #include "llvm/IR/DebugInfoMetadata.h"
0021 #include "llvm/IR/DebugLoc.h"
0022 #include <optional>
0023
0024 namespace llvm {
0025
0026 class AsmPrinter;
0027 class MachineInstr;
0028 class MachineModuleInfo;
0029
0030
0031 struct DbgVariableLocation {
0032
0033 unsigned Register;
0034
0035
0036
0037 SmallVector<int64_t, 1> LoadChain;
0038
0039
0040 std::optional<llvm::DIExpression::FragmentInfo> FragmentInfo;
0041
0042
0043
0044
0045
0046
0047 static std::optional<DbgVariableLocation>
0048 extractFromMachineInstruction(const MachineInstr &Instruction);
0049 };
0050
0051
0052
0053 class DebugHandlerBase : public AsmPrinterHandler {
0054 protected:
0055 DebugHandlerBase(AsmPrinter *A);
0056
0057
0058 AsmPrinter *Asm = nullptr;
0059
0060
0061 MachineModuleInfo *MMI = nullptr;
0062
0063
0064
0065
0066
0067 DebugLoc PrevInstLoc;
0068 MCSymbol *PrevLabel = nullptr;
0069 const MachineBasicBlock *PrevInstBB = nullptr;
0070
0071
0072
0073 const MachineInstr *PrologEndLoc;
0074
0075
0076 const MachineBasicBlock *EpilogBeginBlock = nullptr;
0077
0078
0079 const MachineInstr *CurMI = nullptr;
0080
0081 LexicalScopes LScopes;
0082
0083
0084
0085 DbgValueHistoryMap DbgValues;
0086
0087
0088 DbgLabelInstrMap DbgLabels;
0089
0090
0091
0092
0093 DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
0094
0095
0096 DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
0097
0098
0099
0100 void identifyScopeMarkers();
0101
0102
0103 void requestLabelBeforeInsn(const MachineInstr *MI) {
0104 LabelsBeforeInsn.insert(std::make_pair(MI, nullptr));
0105 }
0106
0107
0108 void requestLabelAfterInsn(const MachineInstr *MI) {
0109 LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
0110 }
0111
0112 virtual void beginFunctionImpl(const MachineFunction *MF) = 0;
0113 virtual void endFunctionImpl(const MachineFunction *MF) = 0;
0114 virtual void skippedNonDebugFunction() {}
0115
0116 private:
0117 InstructionOrdering InstOrdering;
0118
0119
0120 public:
0121 virtual ~DebugHandlerBase() override;
0122
0123 void beginModule(Module *M) override;
0124
0125 void beginInstruction(const MachineInstr *MI) override;
0126 void endInstruction() override;
0127
0128 void beginFunction(const MachineFunction *MF) override;
0129 void endFunction(const MachineFunction *MF) override;
0130
0131 void beginBasicBlockSection(const MachineBasicBlock &MBB) override;
0132 void endBasicBlockSection(const MachineBasicBlock &MBB) override;
0133
0134
0135 MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
0136
0137
0138 MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
0139
0140
0141 static uint64_t getBaseTypeSize(const DIType *Ty);
0142
0143
0144 static bool isUnsignedDIType(const DIType *Ty);
0145
0146 const InstructionOrdering &getInstOrdering() const { return InstOrdering; }
0147 };
0148
0149 }
0150
0151 #endif