Hi all, I am interested in tracking precisely locations of local variables / function parameters in the binary (whether the variable is on the stack, in a register, or maybe both). I know that this is part of the debug information, which can be potentially dropped by optimization passes. Is there any way to verify after each pass the location of the variable? I mean, right before any optimization, we can find the local variable i on the stack, and after -mem2reg, maybe the variable is now in an SSA register %i, then after Register Allocation, %I is mapped into the physical register r1 on ARM, for example. I think about implementing a pass that will be inserted after each optimization pass to verify that the variable is still there and get its location, but not sure how to do this precisely. I would appreciate any help/advice/pointer on how to tackle this. Thank you for your time Son Tuan Vu -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180316/8b482b1e/attachment.html>
The debug information does try to track what happens to parameters and local variables. In the IR this is done with llvm.dbg.value intrinsic functions, and in Machine IR this is done with DBG_VALUE instructions. These have operands that point to the metadata describing the variable, and the location or value of the variable. Ideally each optimization would preserve this information, unless the variable is actually "optimized away" at which point of course there is no location anymore. The assignment of stack locations or physical registers is done very late, so in earlier phases these locations simply don't exist yet. The location/value would be an IR value. But it sounds like you are mostly interested in making sure the information isn't dropped, and you can do that by looking at all of the dbg.value or DBG_VALUE instructions. Hope this helps, --paulr From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Son Tuan VU via llvm-dev Sent: Friday, March 16, 2018 2:22 PM To: llvm-dev Subject: [llvm-dev] Variable tracking in debug info Hi all, I am interested in tracking precisely locations of local variables / function parameters in the binary (whether the variable is on the stack, in a register, or maybe both). I know that this is part of the debug information, which can be potentially dropped by optimization passes. Is there any way to verify after each pass the location of the variable? I mean, right before any optimization, we can find the local variable i on the stack, and after -mem2reg, maybe the variable is now in an SSA register %i, then after Register Allocation, %I is mapped into the physical register r1 on ARM, for example. I think about implementing a pass that will be inserted after each optimization pass to verify that the variable is still there and get its location, but not sure how to do this precisely. I would appreciate any help/advice/pointer on how to tackle this. Thank you for your time Son Tuan Vu -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180320/46ea6a93/attachment.html>
Hello Paul, Thank you for your reply. I have some more questions inlined below.> The assignment of stack locations or physical registers is done very late, > so in earlier phases these locations simply don't exist yet. >Can you define more precisely "very late"? I guess it is in the register allocation phase in the backend? The location/value would be an IR value.>But then again, how can it be an IR value? There's no IR value in the backend isn't it?> But it sounds like you are mostly interested in making sure the > information isn't dropped, and you can do that by looking at all of the > dbg.value or DBG_VALUE instructions. >Yes this is exactly what I am looking for: ensure that we still have the location information after each optimization pass. And if a pass does drop the information, remove it from the pipeline. I guess this would be a first step towards building a -Og pipeline. Of course, if the variable is optimized out, all we need in the binary is just a Dwarf DIE with the declaration line to show that it exists in the source code, which is already done by LLVM. Hope this helps,> > --paulr > > >Thank you again for your help, Son Tuan Vu -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180321/119a6bf6/attachment-0001.html>