Flags O1, O2, O3

I am trying to get a pass list for O1 level optimization using opt and clang. I am using the following command line
for clang: clang -O1 -mllvm -debug-pass=Arguments helloworld.c
for opt opt -O1 -disable-output -print-pipeline-passes < /dev/null

Why the pass list are different?

Any help is appreciated.

Thanks

clang and opt don’t build the exact same pipeline. clang builds an LLVM optimization pipeline internally, which is mostly built off of the items in llvm/lib/Passes/PassBuilderPipelines.cpp. However, clang is free to add its own passes as well, there’s a few of them in clang/lib/CodeGen/BackendUtil.cpp for example.

Thanks for your response .

Is there any way to get all the passes executed for different optimization levels O1,O2, and O3 with clang?

Run time is also different in LLVM binary and opt binary.

If you have new enough clang, you can add -mllvm -print-pipeline-passes to a command line to get the pipeline run: Compiler Explorer

Note this only prints out the passes that run in the new pass manager. The legacy pass manager is still used for code generation (approximately that run by llc), which you can query with -mllvm -debug-pass=Structure.