-
-
Notifications
You must be signed in to change notification settings - Fork 15k
llvm.dbg.value should be used instead of llvm.dbg.declare wherever possible. #68817
Copy link
Copy link
Open
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)Area: Debugging information in compiled programs (DWARF, PDB, etc.)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)Area: Debugging information in compiled programs (DWARF, PDB, etc.)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
(I'm opening this issue because I can't find a pre-existing one)
llvm.dbg.declaredescribes the location in memory of a debuginfo variable, whereasllvm.dbg.valuedescribes the value itself directly. Today we only use the former, which means that in debug mode, all named variables are placed on the stack, even if they're simple scalars (e.g. integers).Ideally, we'd use
llvm.dbg.valuein the same situations where we skip creating a stack slot (e.g. LLVMalloca), i.e. for scalars, vectors and pairs of scalars.However, this is much harder than I expected, mostly due to LLVM being too eager to throw away
llvm.dbg.valueif computing the value can be avoided (i.e. it's not used by anything else).I think
llvm.dbg.declareonly fares better because atopt-level=0, the lack of SROA meansallocas are kept around pretty much completely intact.FastISel(used atopt-level=0) throws away any non-trivialllvm.dbg.value, but disabling it with-C llvm-args=-fast-isel=0only helps some simple cases (such as a reference to another stack variable - IMOFastISelshould be improved to handle those, I don't see why it couldn't).In general, it looks like Instruction Selection ("
ISel") in LLVM ignoresllvm.dbg.values while building all of the machine instructions for a BB, and only afterwards does it come back to thellvm.dbg.values and lower them toDBG_VALUE, using the value only if it already exists (i.e. something else needs that same value, at runtime), and otherwise it leads to<optimized out>vars.Maybe the upcoming
GlobalISelapproach handlesllvm.dbg.valuebetter, but I would need to targetAArch64to even try it out, from what I hear (I might still do it out of curiosity).While investigating this I also came across #8855 (comment) - but setting
AlwaysPreservetotrueonly keeps the debuginfo variable around, it doesn't help at all with keeping any value alive (so you end up with<optimized out>in the debugger, instead of the variable missing).I haven't seen anything that would make
llvm.dbg.valuekeep the value alive so it's guaranteed to be available to the debugger, but if there is such a thing, it's probably the way to go, if we want to avoid relying on the stack so much.cc @nikomatsakis @michaelwoerister @hanna-kruppe