[llvm] r351843 - [DEBUG_INFO, NVPTX] Fix relocation info.
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 22 09:24:16 PST 2019
Author: abataev
Date: Tue Jan 22 09:24:16 2019
New Revision: 351843
URL: http://llvm.org/viewvc/llvm-project?rev=351843&view=rev
Log:
[DEBUG_INFO, NVPTX] Fix relocation info.
Summary: Initial function labels must follow the debug location for the correct relocation info generation.
Reviewers: tra, jlebar, echristo
Subscribers: jholewinski, llvm-commits
Differential Revision: https://reviews.llvm.org/D45784
Modified:
llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/trunk/test/DebugInfo/NVPTX/cu-range-hole.ll
llvm/trunk/test/DebugInfo/NVPTX/debug-loc-offset.ll
Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=351843&r1=351842&r2=351843&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Tue Jan 22 09:24:16 2019
@@ -226,6 +226,9 @@ public:
void EmitToStreamer(MCStreamer &S, const MCInst &Inst);
+ /// Emits inital debug location directive.
+ void emitInitialRawDwarfLocDirective(const MachineFunction &MF);
+
/// Return the current section we are emitting to.
const MCSection *getCurrentSection() const;
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=351843&r1=351842&r2=351843&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Tue Jan 22 09:24:16 2019
@@ -231,6 +231,12 @@ void AsmPrinter::EmitToStreamer(MCStream
S.EmitInstruction(Inst, getSubtargetInfo());
}
+void AsmPrinter::emitInitialRawDwarfLocDirective(const MachineFunction &MF) {
+ assert(DD && "Dwarf debug file is not defined.");
+ assert(OutStreamer->hasRawTextSupport() && "Expected assembly output mode.");
+ (void)DD->emitInitialLocDirective(MF, /*CUID=*/0);
+}
+
/// getCurrentSection() - Return the current section we are emitting to.
const MCSection *AsmPrinter::getCurrentSection() const {
return OutStreamer->getCurrentSectionOnly();
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=351843&r1=351842&r2=351843&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Tue Jan 22 09:24:16 2019
@@ -1520,6 +1520,46 @@ static DebugLoc findPrologueEndLoc(const
return DebugLoc();
}
+/// Register a source line with debug info. Returns the unique label that was
+/// emitted and which provides correspondence to the source line list.
+static void recordSourceLine(AsmPrinter &Asm, unsigned Line, unsigned Col,
+ const MDNode *S, unsigned Flags, unsigned CUID,
+ uint16_t DwarfVersion,
+ ArrayRef<std::unique_ptr<DwarfCompileUnit>> DCUs) {
+ StringRef Fn;
+ unsigned FileNo = 1;
+ unsigned Discriminator = 0;
+ if (auto *Scope = cast_or_null<DIScope>(S)) {
+ Fn = Scope->getFilename();
+ if (Line != 0 && DwarfVersion >= 4)
+ if (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope))
+ Discriminator = LBF->getDiscriminator();
+
+ FileNo = static_cast<DwarfCompileUnit &>(*DCUs[CUID])
+ .getOrCreateSourceID(Scope->getFile());
+ }
+ Asm.OutStreamer->EmitDwarfLocDirective(FileNo, Line, Col, Flags, 0,
+ Discriminator, Fn);
+}
+
+DebugLoc DwarfDebug::emitInitialLocDirective(const MachineFunction &MF,
+ unsigned CUID) {
+ // Get beginning of function.
+ if (DebugLoc PrologEndLoc = findPrologueEndLoc(&MF)) {
+ // Ensure the compile unit is created if the function is called before
+ // beginFunction().
+ (void)getOrCreateDwarfCompileUnit(
+ MF.getFunction().getSubprogram()->getUnit());
+ // We'd like to list the prologue as "not statements" but GDB behaves
+ // poorly if we do that. Revisit this with caution/GDB (7.5+) testing.
+ const DISubprogram *SP = PrologEndLoc->getInlinedAtScope()->getSubprogram();
+ ::recordSourceLine(*Asm, SP->getScopeLine(), 0, SP, DWARF2_FLAG_IS_STMT,
+ CUID, getDwarfVersion(), getUnits());
+ return PrologEndLoc;
+ }
+ return DebugLoc();
+}
+
// Gather pre-function debug information. Assumes being called immediately
// after the function entry point has been emitted.
void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
@@ -1542,13 +1582,8 @@ void DwarfDebug::beginFunctionImpl(const
Asm->OutStreamer->getContext().setDwarfCompileUnitID(CU.getUniqueID());
// Record beginning of function.
- PrologEndLoc = findPrologueEndLoc(MF);
- if (PrologEndLoc) {
- // We'd like to list the prologue as "not statements" but GDB behaves
- // poorly if we do that. Revisit this with caution/GDB (7.5+) testing.
- auto *SP = PrologEndLoc->getInlinedAtScope()->getSubprogram();
- recordSourceLine(SP->getScopeLine(), 0, SP, DWARF2_FLAG_IS_STMT);
- }
+ PrologEndLoc = emitInitialLocDirective(
+ *MF, Asm->OutStreamer->getContext().getDwarfCompileUnitID());
}
void DwarfDebug::skippedNonDebugFunction() {
@@ -1646,21 +1681,9 @@ void DwarfDebug::endFunctionImpl(const M
// emitted and which provides correspondence to the source line list.
void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
unsigned Flags) {
- StringRef Fn;
- unsigned FileNo = 1;
- unsigned Discriminator = 0;
- if (auto *Scope = cast_or_null<DIScope>(S)) {
- Fn = Scope->getFilename();
- if (Line != 0 && getDwarfVersion() >= 4)
- if (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope))
- Discriminator = LBF->getDiscriminator();
-
- unsigned CUID = Asm->OutStreamer->getContext().getDwarfCompileUnitID();
- FileNo = static_cast<DwarfCompileUnit &>(*InfoHolder.getUnits()[CUID])
- .getOrCreateSourceID(Scope->getFile());
- }
- Asm->OutStreamer->EmitDwarfLocDirective(FileNo, Line, Col, Flags, 0,
- Discriminator, Fn);
+ ::recordSourceLine(*Asm, Line, Col, S, Flags,
+ Asm->OutStreamer->getContext().getDwarfCompileUnitID(),
+ getDwarfVersion(), getUnits());
}
//===----------------------------------------------------------------------===//
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=351843&r1=351842&r2=351843&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Tue Jan 22 09:24:16 2019
@@ -592,6 +592,9 @@ public:
/// Emit all Dwarf sections that should come after the content.
void endModule() override;
+ /// Emits inital debug location directive.
+ DebugLoc emitInitialLocDirective(const MachineFunction &MF, unsigned CUID);
+
/// Process beginning of an instruction.
void beginInstruction(const MachineInstr *MI) override;
Modified: llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp?rev=351843&r1=351842&r2=351843&view=diff
==============================================================================
--- llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/NVPTX/NVPTXAsmPrinter.cpp Tue Jan 22 09:24:16 2019
@@ -472,6 +472,9 @@ void NVPTXAsmPrinter::EmitFunctionEntryL
// Emit open brace for function body.
OutStreamer->EmitRawText(StringRef("{\n"));
setAndEmitFunctionVirtualRegisters(*MF);
+ // Emit initial .loc debug directive for correct relocation symbol data.
+ if (MMI && MMI->hasDebugInfo())
+ emitInitialRawDwarfLocDirective(*MF);
}
bool NVPTXAsmPrinter::runOnMachineFunction(MachineFunction &F) {
Modified: llvm/trunk/test/DebugInfo/NVPTX/cu-range-hole.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/NVPTX/cu-range-hole.ll?rev=351843&r1=351842&r2=351843&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/NVPTX/cu-range-hole.ll (original)
+++ llvm/trunk/test/DebugInfo/NVPTX/cu-range-hole.ll Tue Jan 22 09:24:16 2019
@@ -6,6 +6,7 @@
; CHECK: .param .b32 b_param_0
; CHECK: )
; CHECK: {
+; CHECK: .loc 1 1 0
; CHECK: Lfunc_begin0:
; CHECK: .loc 1 1 0
; CHECK: .loc 1 1 0
@@ -27,6 +28,7 @@
; CHECK: .param .b32 d_param_0
; CHECK: )
; CHECK: {
+; CHECK: .loc 1 3 0
; CHECK: Lfunc_begin2:
; CHECK: .loc 1 3 0
; CHECK: ret;
Modified: llvm/trunk/test/DebugInfo/NVPTX/debug-loc-offset.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/NVPTX/debug-loc-offset.ll?rev=351843&r1=351842&r2=351843&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/NVPTX/debug-loc-offset.ll (original)
+++ llvm/trunk/test/DebugInfo/NVPTX/debug-loc-offset.ll Tue Jan 22 09:24:16 2019
@@ -11,8 +11,9 @@
; CHECK: .visible .func (.param .b32 func_retval0) _Z3bari(
; CHECK: {
-; CHECK: Lfunc_begin0:
; CHECK: .loc [[CU1:[0-9]+]] 1 0
+; CHECK: Lfunc_begin0:
+; CHECK: .loc [[CU1]] 1 0
; CHECK: //DEBUG_VALUE: bar:b <- {{[0-9]+}}
; CHECK: //DEBUG_VALUE: bar:b <- {{[0-9]+}}
@@ -39,8 +40,9 @@ declare void @llvm.dbg.value(metadata, m
; CHECK: .visible .func _Z3baz1A(
; CHECK: {
-; CHECK: Lfunc_begin1:
; CHECK: .loc [[CU2:[0-9]+]] 6 0
+; CHECK: Lfunc_begin1:
+; CHECK: .loc [[CU2]] 6 0
; CHECK: //DEBUG_VALUE: baz:z <- {{[0-9]+}}
; CHECK: //DEBUG_VALUE: baz:z <- {{[0-9]+}}
; CHECK: .loc [[CU2]] 10 0
More information about the llvm-commits
mailing list