Search code examples
gccg++clangllvm

List of optimizations available in clang and llvm opt


It is possible to get the list of optimizers available in GCC/G++ with gcc --help=optimizers. The legal values and parameters range are also defined in params.def. Is there such a command and params.def file available for clang too?


Solution

  • 1- For Clang use:

    clang -OX -mllvm -debug-pass=Arguments foo.c
    

    or

    clang -OX -mllvm -debug-pass=Structure foo.c
    

    where X can be Os,O1,O2,O3 and O4 (-O4 is equivalent to -O3 except the fact that it performs LTO (link time optimization) when compiled object files from source files emit LLVM IR instead of object code)

    You will have two sets of Pass Arguments in which the first is the global kernel passes and the second is the function pass.

    2- For Opt use:

    llvm-as < /dev/null | opt -OX -disable-output -debug-pass=Arguments
    

    where X can be Os,O1,O2 and O3

    Update as of LLVM-15x:

    Since the new pass manager is set to be the default pass manager, the answer above only prints the legacy pass manager passes. In order to see the new pass manager passes with opt, try:

    opt --print-passes   "Print available passes that can be specified in -passes=foo and exit"
    

    or

    llvm-as < /dev/null | opt -OX --print-pipeline-passes    "Print a '-passes' compatible string describing the pipeline (best-effort only)"