This is an archive of the discontinued LLVM Phabricator instance.

[MachineInstr] Add a dumpr method
ClosedPublic

Authored by qcolombet on Feb 24 2020, 5:36 PM.

Details

Summary

Add a dump method that recursively prints an instruction and all
the instructions defining its operands and so on.

This is helpful when looking at combiner issue.

NFC

Diff Detail

Event Timeline

qcolombet created this revision.Feb 24 2020, 5:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 24 2020, 5:36 PM
arsenm added inline comments.Feb 24 2020, 5:45 PM
llvm/include/llvm/CodeGen/MachineInstr.h
1545

I think defaulting to UINT_MAX would be simpler than the optional here, especially since debuggers are really bad at calling functions with nontrivial arguments

llvm/lib/CodeGen/MachineInstr.cpp
1474–1476

Can you avoid doing this manually with formatted_raw_ostream?

qcolombet marked 2 inline comments as done.Feb 24 2020, 8:02 PM
qcolombet added inline comments.
llvm/include/llvm/CodeGen/MachineInstr.h
1545

Good point, will change that.

llvm/lib/CodeGen/MachineInstr.cpp
1474–1476

Forgot about that one. Looking.

qcolombet updated this revision to Diff 246365.Feb 24 2020, 8:33 PM
  • Use UINT_MAX instead of Optional to ease the use of the method in the debugger
  • Use the dedicated formatted_raw_ostream to pad column
qcolombet updated this revision to Diff 246366.Feb 24 2020, 8:40 PM
qcolombet marked 2 inline comments as done.
  • Handle PhysReg and Non-SSA code in general

Here are a few examples of the dump we get:

  • No Depth limit:
(lldb) p MI.dumpr(MRI, -1)
%1:_(<4 x s16>) = G_BUILD_VECTOR %6:_(s16), %7:_(s16), %8:_(s16), %9:_(s16)
  %6:_(s16) = G_FPTRUNC %17:_(s32)
    %17:_(s32) = COPY $s0
  %7:_(s16) = G_FPTRUNC %15:_(s32)
    %15:_(s32) = COPY $s0
  %8:_(s16) = G_FPTRUNC %13:_(s32)
    %13:_(s32) = COPY $s0
  %9:_(s16) = G_FPTRUNC %11:_(s32)
    %11:_(s32) = COPY $s0
  • Depth limit of 2:
(lldb) p MI.dumpr(MRI, 2)
%1:_(<4 x s16>) = G_BUILD_VECTOR %6:_(s16), %7:_(s16), %8:_(s16), %9:_(s16)
  %6:_(s16) = G_FPTRUNC %17:_(s32)
  %7:_(s16) = G_FPTRUNC %15:_(s32)
  %8:_(s16) = G_FPTRUNC %13:_(s32)
  %9:_(s16) = G_FPTRUNC %11:_(s32)
arsenm accepted this revision.Feb 25 2020, 7:54 AM

LGTM with nit

llvm/lib/CodeGen/MachineInstr.cpp
1483

Reg.isPhysical

1485–1486

I think the !( looks weird so you could juts move the assignment to the definition

This revision is now accepted and ready to land.Feb 25 2020, 7:54 AM
qcolombet marked 2 inline comments as done.Feb 25 2020, 10:20 AM
This revision was automatically updated to reflect the committed changes.