Question about dbg.value duplication and calculateDbgHistory (original) (raw)
October 5, 2024, 2:47pm 1
Hello,
I’ve been doing some work on NVPTX backend debuginfo recently. I added support for NVPTX to use a .debug_loc section, but variables are not getting the full lifetime ranges I expect.
In an example where the LLVM code has one dbg.value
for each formal parameter and local variable of a function, I’m ending up with ranges valid only for the first basic block in which they appear (IE the first basic block for parameters, and the basic block with the definition of a local variable). In DbgEntityHistoryCalculator.cpp, in llvm::calculateDbgHistory
, near the end, it loops over live entries and clobbers them. A comment says “Make sure locations for all variables are valid only until the end of the basic block”. If I comment out that clobbering code, I get ranges that cover the full range I expect. However, by logging the variables that go through that function, I see differences between NVPTX and X86 backends. With very similar examples, where each has only one dbg.value
per variable at the LLVM IR level, for X86 I see the function processes a copy of each variable in each basic block. Meanwhile for NVPTX I see each variable only once, in a single basic block. I guess there must be something that copies the dbg.value
s between basic blocks for X86 and not NVPTX, but I haven’t been able to find it, and I don’t understand why there would be copying and invalidating in each basic block instead of just leaving variables as valid between blocks.
Can anyone give me some pointers on where the code is that causes this behavior, or the reason behind it?
Thanks,
William Hatch
OCHyams October 7, 2024, 8:27am 2
That sounds like the LiveDebugValues (lib/CodeGen/LiveDebugValues.cpp) pass to me - worth checking if that’s running for you?
There’s two flavours, VarLocBasedImpl and InstrRefBasedImpl. The latter provides better coverage and more accurate locations but requires a little extra work, see the instr-ref docs.
Thank you, that was exactly the problem!