This is an archive of the discontinued LLVM Phabricator instance.

[globalisel] Enable tracing the legalizer with --debug-only=legalize-mir
ClosedPublic

Authored by dsanders on Apr 6 2017, 3:31 AM.

Event Timeline

dsanders created this revision.Apr 6 2017, 3:31 AM
kristof.beyls added inline comments.Apr 6 2017, 5:23 AM
lib/CodeGen/GlobalISel/LegalizerHelper.cpp
69–70

This patch looks pretty straightforward.
I'm just wondering why you don't just directly print out the New MI here and instead use a data structure to record it and print it out later?

dsanders added inline comments.Apr 6 2017, 5:52 AM
lib/CodeGen/GlobalISel/LegalizerHelper.cpp
69–70

I didn't give it enough thought to notice it was redundant :-). I'll make it emit it directly once I've finished updating the other patches.

dsanders updated this revision to Diff 95550.Apr 18 2017, 3:57 AM

Refresh patch. No other changes made (see next comment).

dsanders added inline comments.Apr 18 2017, 3:58 AM
lib/CodeGen/GlobalISel/LegalizerHelper.cpp
69–70

I got around to trying to make this change and remembered why I recorded the MI and printed it out afterwards. The operands haven't been added to the instruction at the point that recordInsertions() is called so it only prints the opcode. This makes it hard to trace the changes the pass is making.

kristof.beyls added inline comments.Apr 18 2017, 5:44 AM
lib/CodeGen/GlobalISel/Legalizer.cpp
174

I think that just having an "unsigned DebugNewInstructionsIdx" or something similar could be enough to track the new MIs that are created but haven't been printed yet for debugging; no need for a separate SmallVector?
I think it makes the code slightly easier to understand, as it's then immediately clear that MI's from the WorkList are being printed, rather than having to look through code how this new data structure DebugReportList is being formed.

lib/CodeGen/GlobalISel/LegalizerHelper.cpp
69–70

Ah yes, that makes sense.

dsanders updated this revision to Diff 95566.Apr 18 2017, 7:30 AM

SmallVector -> number of new instructions emitted.

Also fixed a small issue I missed in the refresh. Now that the debug output
code is split across two files with different DEBUG_ONLY definitions you need
--debug-only=legalize-mir,legalizer to get useful debug output. legalize-mir
isn't a pass and doesn't provide useful debug output without legalizer so I've
made them both enable their debug output when given --debug-only=legalizer.

kristof.beyls accepted this revision.Apr 19 2017, 12:27 AM
kristof.beyls added inline comments.
lib/CodeGen/GlobalISel/Legalizer.cpp
204

Minor nitpick: maybe use auto& here to make the code slightly more readable?
Otherwise, LGTM.

This revision is now accepted and ready to land.Apr 19 2017, 12:27 AM
dsanders closed this revision.Apr 20 2017, 8:58 AM
dsanders added inline comments.Apr 20 2017, 9:01 AM
lib/CodeGen/GlobalISel/Legalizer.cpp
204

Thanks.

lib/CodeGen/GlobalISel/Legalizer.cpp
204

Quick question here - is it possible that one of the instructions could have been erased as it went through legalization (and we're trying to print it)?

kristof.beyls added inline comments.Apr 21 2017, 12:11 AM
lib/CodeGen/GlobalISel/Legalizer.cpp
204

I'm assuming that's not possible as the instructions being printed here are the ones added to the WorkList in this iteration, to be processed in future iterations. In other words, all of these MIs will be processed by legalizeInstrStep later on, so they shouldn't have been erased at this point.

dsanders added inline comments.Apr 21 2017, 12:57 AM
lib/CodeGen/GlobalISel/Legalizer.cpp
204

That's right. The only way it could see an erased instruction is if a single legalizer step created an instruction and erased it again. That would be wasteful and would break the work list too.