Assignment Tracking and CodeExtractor

I’ve recently seen that assignment tracking (Debug Info Assignment Tracking — LLVM 18.0.0git documentation) is now enabled by default (-fexperimental-assignment-tracking).

An llvm.dbg.assign instruction is linked to a store instruction using a DIAssignID metadata, and both instructions are required to reside in the same function (enforced by the Verifier). When using the CodeExtractor, this requirement might be validated.

In our case we had a loop with a store instruction and its matching llvm.dbg.assign instruction. After LICM only the store was hoisted, keeping the dbg.assign in the the same location. We then extracted the loop to a different function using CodeExtractor, which also extracted the dbg.assign instruction, without the store, thus breaking the above requirement.

Is it a common issue?
Thanks,
Ziv

Hi,

Thanks for raising this issue!

It sounds like the CodeExtractor should be updated to handle this case. I’m not familiar with the CodeExtractor code but from a quick look, I imagine we could fixup the cloned dbg.assign intrinsics in fixupDebugInfoPostExtraction. I think running the function fixupAssignments (currently a static function in InlineFunction.cpp) would work. That function scans given blocks for DIAssignID uses (by dbg.assign intrinsics) and attachments (on instructions), replacing them with a new DIAssignID.

We might need to move fixupAssignments (or split the core functionality out into a shared helper) in to DebugInfo.h/cpp with the other Assignment Tracking helper functions.

Is this something you would be able to look into?

Thanks,
Orlando