This is an archive of the discontinued LLVM Phabricator instance.

[opt][NewPM] Add a --print-passes flag to print all available passes
ClosedPublic

Authored by aeubanks on Feb 4 2021, 8:07 PM.

Details

Summary

It seems nicer to list passes given a flag rather than displaying all
passes in opt --help.

This is awkwardly structured because a PassBuilder is required, but
reusing the PassBuilder in runPassPipeline() doesn't work because we
read the input IR before getting to runPassPipeline(). So printing the
list of passes needs to happen before reading the input IR. If we remove
the legacy PM code in main() and move everything from NewPMDriver.cpp
into opt.cpp, we can create the PassBuilder before reading IR and check
if we should print the list of passes and exit. But until then this hack
seems fine.

Compared to the legacy PM, the new PM passes are lacking descriptions.
We'll need to figure out a way to add descriptions if we think this is
important.

Diff Detail

Event Timeline

aeubanks created this revision.Feb 4 2021, 8:07 PM
aeubanks requested review of this revision.Feb 4 2021, 8:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 4 2021, 8:07 PM
bjope added a subscriber: uabelho.Feb 5 2021, 12:44 AM
bjope added inline comments.Feb 7 2021, 3:06 PM
llvm/test/Other/print-passes.ll
7

Should analysis passes perhaps be printed as require<name>?

asbirlea accepted this revision.Feb 9 2021, 4:32 PM
This revision is now accepted and ready to land.Feb 9 2021, 4:32 PM
aeubanks updated this revision to Diff 322764.Feb 10 2021, 11:19 AM

mention in the -passes help description about require<>

aeubanks added inline comments.Feb 10 2021, 11:21 AM
llvm/test/Other/print-passes.ll
7

Technically require<foo> is a pass that just runs foo, so that's separate. I added in the --help for -passes that you can specify require<foo>.

This revision was landed with ongoing or failed builds.Feb 10 2021, 11:22 AM
This revision was automatically updated to reflect the committed changes.
bjope added inline comments.Feb 10 2021, 11:58 AM
llvm/test/Other/print-passes.ll
7

But you can't for example do -passes="aa" so you need to write -passes="require<aa>". If comparing with the print passes they are listed as for example "print<loops>". So it is a bit inconsistent (or maybe I am missing something).

One idea was to use the output from -print-passes in scripts to randomly generate strings to use in -passes. It will be slightly more complicated if one need to parse the headings in the output to find which passes that need an enclosing require<>.

aeubanks added inline comments.Feb 10 2021, 1:41 PM
llvm/test/Other/print-passes.ll
7

print<loops> is a name that happens to have < inside it, it's not special in any way.

Is it helpful to run arbitrary analyses? It seems more fruitful to just run random passes and have them query analyses as needed. Although there are special cases required, like making sure GlobalsAA and ProfileSummaryAnalysis are available before running function passes (see the uses of RequireAnalysisPass in PassBuilder).

Alternatively, rather than randomly constructing the list of passes outside LLVM via text, it could be interesting to do that within PassBuilder.

aeubanks added inline comments.Feb 11 2021, 2:54 PM
llvm/test/Other/print-passes.ll
7

I just found out about llvm-opt-fuzzer. Looks like we could do something like this there.