This is an archive of the discontinued LLVM Phabricator instance.

[IR]PATCH 2/2: Add MDNode::printTree and dumpTree
ClosedPublic

Authored by myhsu on Sep 20 2021, 4:27 PM.

Details

Summary

This patch adds the functionalities to print MDNode in tree shape. For example, instead of printing a MDNode like this:

<0x5643e1166888> = !DILocalVariable(name: "foo", arg: 2, scope: <0x5643e11c9740>, file: <0x5643e11c6ec0>, line: 8, type: <0x5643e11ca8e0>, flags: DIFlagPublic | DIFlagFwdDecl, align: 8)

The printTree/dumpTree functions can give you:

<0x5643e1166888> = !DILocalVariable(name: "foo", arg: 2, scope: <0x5643e11c9740>, file: <0x5643e11c6ec0>, line: 8, type: <0x5643e11ca8e0>, flags: DIFlagPublic | DIFlagFwdDecl, align: 8)
  <0x5643e11c9740> = distinct !DISubprogram(scope: null, spFlags: 0)
  <0x5643e11c6ec0> = distinct !DIFile(filename: "file.c", directory: "/path/to/dir")
  <0x5643e11ca8e0> = distinct !DIDerivedType(tag: DW_TAG_pointer_type, baseType: <0x5643e11668d8>, size: 1, align: 2)
    <0x5643e11668d8> = !DIBasicType(tag: DW_TAG_unspecified_type, name: "basictype")

Which is useful when using it in debugger. Where sometimes printing the whole module to see all MDNodes is too expensive.

Diff Detail

Event Timeline

myhsu created this revision.Sep 20 2021, 4:27 PM
myhsu requested review of this revision.Sep 20 2021, 4:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 20 2021, 4:27 PM

I like this! Can you add a testcase where the MDNode graph has cycles?

myhsu updated this revision to Diff 375410.Sep 27 2021, 2:40 PM

Add another unittest to test the case where there is a cycle in the MDNode to be printed by printTree.

aprantl accepted this revision.Oct 1 2021, 1:53 PM
aprantl added inline comments.
llvm/include/llvm/IR/Metadata.h
1047

Nit, I think this can be \{. Looks more TeXy.

llvm/lib/IR/AsmWriter.cpp
4670

///

This revision is now accepted and ready to land.Oct 1 2021, 1:53 PM
myhsu updated this revision to Diff 376735.Oct 2 2021, 9:19 PM
myhsu marked 2 inline comments as done.

Minor formatting updates.

This revision was automatically updated to reflect the committed changes.