Metadata/DebugInfo in *.ll file

Hi list,

I found relevant documentation regarding DebugInfo creation in the LLVM IR bytecode. It can be done for compileunits, functions, and other constructs, with the help of DIBuilder class. However I can’t save debug information related to individual llvm::Instructions. I tried DebugLoc, DILocation setting directly with setMetadata(). I tried other ways, for e.g.: insertDbgValueIntrinsic(). If I set invalid parameters for the call, then the LLVM passes warn me, correctly, so at least I see in the log, that LLVM tries to assign debuginfo to given instruction. If however I set valid parameters, then I suppose, that the passes drop the debuginfo related to an Instruction.

Do you know a surefire way to avoid the drop of instruction related debuginfo?

Thanks for your time,
Norbert

I believe the only thing you can add directly to an Instruction is the source location (via setDebugLoc, not setMetadata).

All other instruction-related debug info is currently conveyed by debug-info intrinsics, and the association is by one of the intrinsic operands being the Instruction.

Is this for a front-end? Typically front-ends only add dbg.declare intrinsics, which are attached to the alloca for the relevant variable.

–paulr

Generally, a good strategy is to look at what Clang generates for similar code and mimic that in your IR generator.

-- adrian

Yes, this is for a front-end-ish project. I generate LLVM IR from assembly. The result is optimized through several builtin passes, like simplify cfg, value propagation, simple const propagation, etc. I tried setDebugLoc, but it gets dropped. Aside from simplify CFG, I can’t see where this happens, and it is already dropped before simplify cfg. It looks like I would be better off adding instruction metadata after generating IR, outside LLVM, instead of forcing it to process things backwards.

Adrian Prantl <aprantl@apple.com> ezt írta (időpont: 2019. jan. 14., H, 17:26):

Yes, this is for a front-end-ish project. I generate LLVM IR from assembly.
The result is optimized through several builtin passes, like simplify cfg, value propagation,
simple const propagation, etc. I tried setDebugLoc, but it gets dropped.

Pretty sure this is just a bug in LLVM.
Some pointers:
https://reviews.llvm.org/D40512
https://llvm.org/devmtg/2018-04/slides/Bedwell-Measuring_the_User_Debugging_Experience.pdf
https://lists.llvm.org/pipermail/llvm-dev/2018-August/125780.html
https://bugs.llvm.org/show_bug.cgi?id=38768

Would be a good idea for you to verify that it still happens with
trunk, come up with a minimal test case, and file a bug.

Aside from simplify CFG,
I can't see where this happens, and it is already dropped before simplify cfg.
It looks like I would be better off adding instruction metadata after generating IR, outside LLVM,
instead of forcing it to process things backwards.

Adrian Prantl <aprantl@apple.com> ezt írta (időpont: 2019. jan. 14., H, 17:26):

Generally, a good strategy is to look at what Clang generates for similar code and mimic that in your IR generator.

-- adrian

Roman.