llvm.org GIT mirror llvm / d3046a2
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351843 91177308-0d34-0410-b5e6-96231b3b80d8 Alexey Bataev 1 year, 10 months ago
7 changed file(s) with 66 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
225225
226226 void EmitToStreamer(MCStreamer &S, const MCInst &Inst);
227227
228 /// Emits inital debug location directive.
229 void emitInitialRawDwarfLocDirective(const MachineFunction &MF);
230
228231 /// Return the current section we are emitting to.
229232 const MCSection *getCurrentSection() const;
230233
230230 S.EmitInstruction(Inst, getSubtargetInfo());
231231 }
232232
233 void AsmPrinter::emitInitialRawDwarfLocDirective(const MachineFunction &MF) {
234 assert(DD && "Dwarf debug file is not defined.");
235 assert(OutStreamer->hasRawTextSupport() && "Expected assembly output mode.");
236 (void)DD->emitInitialLocDirective(MF, /*CUID=*/0);
237 }
238
233239 /// getCurrentSection() - Return the current section we are emitting to.
234240 const MCSection *AsmPrinter::getCurrentSection() const {
235241 return OutStreamer->getCurrentSectionOnly();
15191519 return DebugLoc();
15201520 }
15211521
1522 /// Register a source line with debug info. Returns the unique label that was
1523 /// emitted and which provides correspondence to the source line list.
1524 static void recordSourceLine(AsmPrinter &Asm, unsigned Line, unsigned Col,
1525 const MDNode *S, unsigned Flags, unsigned CUID,
1526 uint16_t DwarfVersion,
1527 ArrayRef> DCUs) {
1528 StringRef Fn;
1529 unsigned FileNo = 1;
1530 unsigned Discriminator = 0;
1531 if (auto *Scope = cast_or_null(S)) {
1532 Fn = Scope->getFilename();
1533 if (Line != 0 && DwarfVersion >= 4)
1534 if (auto *LBF = dyn_cast(Scope))
1535 Discriminator = LBF->getDiscriminator();
1536
1537 FileNo = static_cast(*DCUs[CUID])
1538 .getOrCreateSourceID(Scope->getFile());
1539 }
1540 Asm.OutStreamer->EmitDwarfLocDirective(FileNo, Line, Col, Flags, 0,
1541 Discriminator, Fn);
1542 }
1543
1544 DebugLoc DwarfDebug::emitInitialLocDirective(const MachineFunction &MF,
1545 unsigned CUID) {
1546 // Get beginning of function.
1547 if (DebugLoc PrologEndLoc = findPrologueEndLoc(&MF)) {
1548 // Ensure the compile unit is created if the function is called before
1549 // beginFunction().
1550 (void)getOrCreateDwarfCompileUnit(
1551 MF.getFunction().getSubprogram()->getUnit());
1552 // We'd like to list the prologue as "not statements" but GDB behaves
1553 // poorly if we do that. Revisit this with caution/GDB (7.5+) testing.
1554 const DISubprogram *SP = PrologEndLoc->getInlinedAtScope()->getSubprogram();
1555 ::recordSourceLine(*Asm, SP->getScopeLine(), 0, SP, DWARF2_FLAG_IS_STMT,
1556 CUID, getDwarfVersion(), getUnits());
1557 return PrologEndLoc;
1558 }
1559 return DebugLoc();
1560 }
1561
15221562 // Gather pre-function debug information. Assumes being called immediately
15231563 // after the function entry point has been emitted.
15241564 void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
15411581 Asm->OutStreamer->getContext().setDwarfCompileUnitID(CU.getUniqueID());
15421582
15431583 // Record beginning of function.
1544 PrologEndLoc = findPrologueEndLoc(MF);
1545 if (PrologEndLoc) {
1546 // We'd like to list the prologue as "not statements" but GDB behaves
1547 // poorly if we do that. Revisit this with caution/GDB (7.5+) testing.
1548 auto *SP = PrologEndLoc->getInlinedAtScope()->getSubprogram();
1549 recordSourceLine(SP->getScopeLine(), 0, SP, DWARF2_FLAG_IS_STMT);
1550 }
1584 PrologEndLoc = emitInitialLocDirective(
1585 *MF, Asm->OutStreamer->getContext().getDwarfCompileUnitID());
15511586 }
15521587
15531588 void DwarfDebug::skippedNonDebugFunction() {
16451680 // emitted and which provides correspondence to the source line list.
16461681 void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
16471682 unsigned Flags) {
1648 StringRef Fn;
1649 unsigned FileNo = 1;
1650 unsigned Discriminator = 0;
1651 if (auto *Scope = cast_or_null(S)) {
1652 Fn = Scope->getFilename();
1653 if (Line != 0 && getDwarfVersion() >= 4)
1654 if (auto *LBF = dyn_cast(Scope))
1655 Discriminator = LBF->getDiscriminator();
1656
1657 unsigned CUID = Asm->OutStreamer->getContext().getDwarfCompileUnitID();
1658 FileNo = static_cast(*InfoHolder.getUnits()[CUID])
1659 .getOrCreateSourceID(Scope->getFile());
1660 }
1661 Asm->OutStreamer->EmitDwarfLocDirective(FileNo, Line, Col, Flags, 0,
1662 Discriminator, Fn);
1683 ::recordSourceLine(*Asm, Line, Col, S, Flags,
1684 Asm->OutStreamer->getContext().getDwarfCompileUnitID(),
1685 getDwarfVersion(), getUnits());
16631686 }
16641687
16651688 //===----------------------------------------------------------------------===//
591591 /// Emit all Dwarf sections that should come after the content.
592592 void endModule() override;
593593
594 /// Emits inital debug location directive.
595 DebugLoc emitInitialLocDirective(const MachineFunction &MF, unsigned CUID);
596
594597 /// Process beginning of an instruction.
595598 void beginInstruction(const MachineInstr *MI) override;
596599
471471 // Emit open brace for function body.
472472 OutStreamer->EmitRawText(StringRef("{\n"));
473473 setAndEmitFunctionVirtualRegisters(*MF);
474 // Emit initial .loc debug directive for correct relocation symbol data.
475 if (MMI && MMI->hasDebugInfo())
476 emitInitialRawDwarfLocDirective(*MF);
474477 }
475478
476479 bool NVPTXAsmPrinter::runOnMachineFunction(MachineFunction &F) {
55 ; CHECK: .param .b32 b_param_0
66 ; CHECK: )
77 ; CHECK: {
8 ; CHECK: .loc 1 1 0
89 ; CHECK: Lfunc_begin0:
910 ; CHECK: .loc 1 1 0
1011 ; CHECK: .loc 1 1 0
2627 ; CHECK: .param .b32 d_param_0
2728 ; CHECK: )
2829 ; CHECK: {
30 ; CHECK: .loc 1 3 0
2931 ; CHECK: Lfunc_begin2:
3032 ; CHECK: .loc 1 3 0
3133 ; CHECK: ret;
1010
1111 ; CHECK: .visible .func (.param .b32 func_retval0) _Z3bari(
1212 ; CHECK: {
13 ; CHECK: .loc [[CU1:[0-9]+]] 1 0
1314 ; CHECK: Lfunc_begin0:
14 ; CHECK: .loc [[CU1:[0-9]+]] 1 0
15 ; CHECK: .loc [[CU1]] 1 0
1516
1617 ; CHECK: //DEBUG_VALUE: bar:b <- {{[0-9]+}}
1718 ; CHECK: //DEBUG_VALUE: bar:b <- {{[0-9]+}}
3839
3940 ; CHECK: .visible .func _Z3baz1A(
4041 ; CHECK: {
42 ; CHECK: .loc [[CU2:[0-9]+]] 6 0
4143 ; CHECK: Lfunc_begin1:
42 ; CHECK: .loc [[CU2:[0-9]+]] 6 0
44 ; CHECK: .loc [[CU2]] 6 0
4345 ; CHECK: //DEBUG_VALUE: baz:z <- {{[0-9]+}}
4446 ; CHECK: //DEBUG_VALUE: baz:z <- {{[0-9]+}}
4547 ; CHECK: .loc [[CU2]] 10 0