This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Print empty MDTuples wrapped in MetadataAsValue inline
AbandonedPublic

Authored by Orlando on Jan 3 2023, 9:03 AM.

Details

Summary

This improves the readability of debugging intrinsics. Instead of:

call void @llvm.dbg.value(metadata !2, ...)
!2 = !{}

We will see:

call void @llvm.dbg.value(metadata !{}, ...)
!2 = !{}

Note that we still get a numbered metadata entry for the node even if it's not
used elsewhere. This is to avoid adding more context to the print functions.

This is already legal IR - LLVM can parse and understand it - so there is no
need to update the parser.

The next patches in this stack will make such empty metadata operands more
common and semantically important.

Related to https://discourse.llvm.org/t/auto-undef-debug-uses-of-a-deleted-value

Diff Detail

Event Timeline

Orlando created this revision.Jan 3 2023, 9:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 3 2023, 9:03 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
Orlando requested review of this revision.Jan 3 2023, 9:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 3 2023, 9:03 AM

Largely LGTM, but with a potential error that needs looking at.

llvm/lib/IR/AsmWriter.cpp
4884–4885

Setting this to false, while it makes total sense to me, caused an error in the LLDB test suite last time it was done[0][1]. Off the top of my head I'm not sure under what circumstances exactly we're calling printMetadataImpl directly for a LocalAsMetadata or DIArgList, but (much as a pain as it is) it probably needs to be verified that this error won't come up again - happy to investigate further myself if needed.

[0] https://reviews.llvm.org/D104827#2856347
[1] https://reviews.llvm.org/D104827#2898216

I agree with Stephen, it's good but flipping the FromValue flag doesn't seem right.

llvm/lib/IR/AsmWriter.cpp
4884–4885

Yeah, changing this feels at risk of being overkill -- I can understand why we want the condition that FromValue is true when printing inline, but why does this call-site need to change for that? Possibly printMetadataImpl needs to take a FromValue argument itself and push the decision making higher up the call stack?

llvm/test/DebugInfo/Generic/empty-metadata-roundtrip.ll
7

Worth using the term "cosmetic" to fully communicate that there's no functional impact of this behaviour?

Orlando updated this revision to Diff 509007.Mar 28 2023, 7:44 AM

Rather than using FromValue to determine whether the node should be printed inline I've added a parameter AsOperand to WriteAsOperandInternal, which is true when printing metadata with Metadata::printAsOperand and when printing MetadataAsValue wrapped operands through the Value * version of WriteAsOperandInternal.

Orlando updated this revision to Diff 509012.Mar 28 2023, 7:49 AM

+ Update test comment.

Orlando marked an inline comment as done.Mar 28 2023, 7:49 AM
StephenTozer accepted this revision.Mar 29 2023, 2:12 AM

Changes LGTM.

This revision is now accepted and ready to land.Mar 29 2023, 2:12 AM
This revision was landed with ongoing or failed builds.Apr 25 2023, 6:14 AM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Apr 25 2023, 6:30 AM

This breaks check-clang, eg http://45.33.8.238/linux/105304/step_7.txt

Please take a look and revert for now if it takes a while to fix.

Orlando added a comment.EditedApr 25 2023, 6:40 AM

Thanks for the heads up @thakis. Looks like there are simply some more tests that need updating to the new formatting, but I've reverted for now as it tripped several bots.

Orlando added a comment.EditedApr 25 2023, 7:18 AM

This patch prints the tuple as !{} even if it's distinct, which I thought was reasonable when writing the patch. If a distinct empty tuple is used multiple times or is attached to multiple instructions however it might be useful to have the metadata ID printed, to make debugging easier.

(example bot failure with distinct empty metadata: In https://lab.llvm.org/buildbot/#/builders/245/builds/7602/steps/5/logs/FAIL__Clang__type-metadata_cpp - the distinct MD is not used in multiple places in this case but it seems like a possibility)

With that in mind I think we should either further restrict this to non-distinct empty MD tuples (IMO still useful) or drop this patch (just continue to use metadata references, so !2 inline and !2 = !{} (+-distinct) in the metadata list).

Does anyone have any strong feelings? @jmorse, @StephenTozer ?

If not, then, although I do prefer the inline printing aesthetically, I think that the extra code isn't worth it for the slight readability improvement (and test-writing convenience of not needing to check the metadata reference), and vote that we drop this.

Orlando reopened this revision.Apr 27 2023, 8:02 AM
This revision is now accepted and ready to land.Apr 27 2023, 8:02 AM
Orlando abandoned this revision.Apr 27 2023, 8:02 AM

Abandoning this (see previous comment)