[opt][NewPM] Add a --print-passes flag to print all available passes
authorArthur Eubanks <aeubanks@google.com>
Fri, 5 Feb 2021 03:34:09 +0000 (19:34 -0800)
committerArthur Eubanks <aeubanks@google.com>
Wed, 10 Feb 2021 19:22:12 +0000 (11:22 -0800)
commit5d960cba34682d0d4e0cd56837131888eb647c62
treef378cebbd782be2d6f0c1597cb9fa1407e7320f4
parentfc4d780eaf52cb2361579dcc8d5073e662a950e5
[opt][NewPM] Add a --print-passes flag to print all available passes

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.

Also, this only works for passes specified in PassRegistry.def. If we
want to print other custom registered passes, we'll need a different
mechanism.

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D96101
llvm/include/llvm/Passes/PassBuilder.h
llvm/lib/Passes/PassBuilder.cpp
llvm/test/Other/print-passes.ll [new file with mode: 0644]
llvm/tools/opt/NewPMDriver.cpp
llvm/tools/opt/NewPMDriver.h
llvm/tools/opt/opt.cpp