This is an archive of the discontinued LLVM Phabricator instance.

Add a -verify-after-all option
AbandonedPublic

Authored by sanjoy on Jun 5 2016, 2:54 PM.

Details

Summary

When investigating PR27997 I notied that there is no easy way in opt or
clang to verify the IR after each transform pass. There is a
-verify-each option in opt, but

  • When running opt -O3 it appends the verifier pass after the whole -O3 pipeline, not after each individual transform pass
  • It is in opt so isn't accessible from clang via -mllvm

With -verify-after-all, triaging bugs like PR27997 should become
easier, since we'd be able to run something like `clang -O3 -mllvm
-verify-after-all -mllvm -print-after-all` to quickly discover which
pass broke SSA, if any.

Depends on D21004

Diff Detail

Event Timeline

sanjoy updated this revision to Diff 59676.Jun 5 2016, 2:54 PM
sanjoy retitled this revision from to Add a -verify-after-all option.
sanjoy updated this object.
sanjoy added a subscriber: llvm-commits.
davide accepted this revision.Jun 5 2016, 2:57 PM
davide edited edge metadata.

This is very good. In fact, I have a patch that accomplish exactly the same locally (but I was always too lazy to upstream it). In my patch, I just used -verify-after, and I have preference for that as it's shorter, but I don't want to start a bike shed here, so up to you.

This revision is now accepted and ready to land.Jun 5 2016, 2:57 PM
mehdi_amini edited edge metadata.Jun 5 2016, 2:59 PM

I'd rather keep the name "verify-each" or "verify-after-each" (the "after-all" sounds odd to me) and nuke the opt option which seems redundant now.

davide added a comment.Jun 5 2016, 3:00 PM

Oh, also, do you have any (easy way) to add a test for this option?

sanjoy added a comment.Jun 5 2016, 3:17 PM

I'd rather keep the name "verify-each" or "verify-after-each" (the "after-all" sounds odd to me) and nuke the opt option which seems redundant now.

I named this keeping consistent with the similar -print-after-all option (in the future we might even want a -verify-after=... option like we have for -print-after=... today).

I do plan to nuke the opt -verify-each once this change is in.

sanjoy added a comment.Jun 5 2016, 3:18 PM

Oh, also, do you have any (easy way) to add a test for this option?

I can add a test that makes sure the function exists and is supported by opt (do you want me to do that?), but I don't see how I can test for a bad transform without adding a deliberately broken pass (which seems overkill). But suggestions are welcome.

davide added a comment.Jun 5 2016, 3:22 PM

Oh, also, do you have any (easy way) to add a test for this option?

I can add a test that makes sure the function exists and is supported by opt (do you want me to do that?), but I don't see how I can test for a bad transform without adding a deliberately broken pass (which seems overkill). But suggestions are welcome.

Something that tests the basic functionality works is fine. I really don't think adding a broken pass is needed.

-dump-pass=Structure could be a good test. There are already test that checks the pass pipeline that may be extended to test this option I think.

sanjoy planned changes to this revision.Jun 5 2016, 5:38 PM

This patch isn't quite right as is -- it breaks out of a loop pass manager, i.e. if I had e.g. -indvars -loop-rotate now I will have -indvars < verify function > -loop-rotate with the < verify function > in the middle running outside the LoopPass; and the -loop-rotate and -indvars running in different loop pass managers when earlier they'd run in the same loop pass manager. I think this can be quite misleading since it will change the optimizations that fire when -verify-after-all is enabled.

I think I'll have to have something like createPrinterPass so that the above does not happen.

davide added a comment.Jun 5 2016, 6:10 PM

This is very good. In fact, I have a patch that accomplish exactly the same locally (but I was always too lazy to upstream it). In my patch, I just used -verify-after, and I have preference for that as it's shorter, but I don't want to start a bike shed here, so up to you.

This patch isn't quite right as is -- it breaks out of a loop pass manager, i.e. if I had e.g. -indvars -loop-rotate now I will have -indvars < verify function > -loop-rotate with the < verify function > in the middle running outside the LoopPass; and the -loop-rotate and -indvars running in different loop pass managers when earlier they'd run in the same loop pass manager. I think this can be quite misleading since it will change the optimizations that fire when -verify-after-all is enabled.

I think I'll have to have something like createPrinterPass so that the above does not happen.

I just used this for function passes so I never noticed the problem, but yes, I agree it can happen.
Can you please elaborate on how you plan to use createPrinterPass ?

sanjoy added a comment.Jun 5 2016, 6:26 PM

I just used this for function passes so I never noticed the problem, but yes, I agree it can happen.
Can you please elaborate on how you plan to use createPrinterPass ?

I don't plan to use createPrinterPass, but add a virtual function similar to it as PassManager::createVerifierPass that creates and returns a verifier pass of the right type (i.e. ModulePass, FunctionPass or LoopPass).

davide added a comment.Jun 5 2016, 6:33 PM

I just used this for function passes so I never noticed the problem, but yes, I agree it can happen.
Can you please elaborate on how you plan to use createPrinterPass ?

I don't plan to use createPrinterPass, but add a virtual function similar to it as PassManager::createVerifierPass that creates and returns a verifier pass of the right type (i.e. ModulePass, FunctionPass or LoopPass).

Thanks. I assume this will also extend to CGSCCPass when one will be available, right?
Anyway, I'll defer the judgement of this patch to Chandler as I don't (yet) understand all the interactions between the PMs, clearly =)

davide requested changes to this revision.Jun 5 2016, 6:34 PM
davide edited edge metadata.
chandlerc edited edge metadata.Jun 6 2016, 5:34 PM

(FWIW, +1 to the idea of using the virtual function to get the correct kind of verifier pass)

sanjoy abandoned this revision.Sep 30 2016, 11:15 AM

I'm not working on this actively now, so abandoning for now. Will reopen if that changes.