[llvm] [DWARF] Emit line 0 source locations for BB padding nops (PR #99496)
Nabeel Omer via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 23 08:07:43 PDT 2024
================
@@ -3668,3 +3668,19 @@ bool DwarfDebug::alwaysUseRanges(const DwarfCompileUnit &CU) const {
return true;
return false;
}
+
+void DwarfDebug::beginCodeAlignment(const MachineBasicBlock &MBB) {
+ auto *SP = MBB.getParent()->getFunction().getSubprogram();
+
+ bool NoDebug =
+ !SP || SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug;
+
+ if (NoDebug)
+ return;
+
+ auto PrevLoc = Asm->OutStreamer->getContext().getCurrentDwarfLoc();
+ Asm->OutStreamer->emitDwarfLocDirective(
----------------
omern1 wrote:
> That suggests you want to figure this out down in MC when you do know whether you will be emitting any nops.
That's going to be difficult because the line table has already been encoded by that time. In theory one could evaluate the line table to find the `MCDwarfLineAddrFragment` associated with the address that the nops are being emitted at but that doesn't seem sustainable.
> Or, possibly, when encoding the line table, look to see whether there's a line-0 immediately followed by a non-0 at the same offset, and suppress the line-0.
Dwarf line entries are encoded in a `MCDwarfLineAddrFragment` which contains an expression and fixups to compute the delta between the current symbol and the last symbol encoded with fixups and then eventually end up as a link-time relocation so the absolute address isn't known until that time.
This seems like a design problem in the MC layer, there isn't a way to correlate a fragment with it's DWARF-related counterpart. This is probably partly due to the fact that fragments don't normally need to change once they've been created. I don't think this is solvable within the scope of this patch.
https://github.com/llvm/llvm-project/pull/99496
More information about the llvm-commits
mailing list