[DebugInfo] Print empty MDTuples wrapped in MetadataAsValue inline
authorOCHyams <orlando.hyams@sony.com>
Tue, 25 Apr 2023 10:24:30 +0000 (11:24 +0100)
committerOCHyams <orlando.hyams@sony.com>
Tue, 25 Apr 2023 13:13:47 +0000 (14:13 +0100)
commit1e6fe677f8aa98518e05218affa16e468819f5ed
tree0e7b15122bf4563ecf46c9b7a383317c01e0bf70
parent4b1532a46f66eb71bf80458fa67b86c618803b95
[DebugInfo] Print empty MDTuples wrapped in MetadataAsValue inline

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

Reviewed By: StephenTozer

Differential Revision: https://reviews.llvm.org/D140900
llvm/lib/IR/AsmWriter.cpp
llvm/test/DebugInfo/Generic/empty-metadata-roundtrip.ll [new file with mode: 0644]
llvm/test/Transforms/GlobalOpt/localize-constexpr-debuginfo.ll
llvm/test/Transforms/GlobalOpt/metadata.ll
llvm/test/Transforms/LoopIdiom/debug-line.ll
llvm/unittests/IR/MetadataTest.cpp