Search code examples
optimizationllvmllvm-clangllvm-irbitcode

How to make the LLVM Opt tool to report which analysis passes successfully used by each optimization -O1, -O2, etc?


I wonder if it is possible to make the LLVM opt tool to report in detail which optimization passes are successfully used during each optimization level like -O1,-O2, etc.

For example, here is the naive bitcode of the file foo.bc:

define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 0, i32* %1, align 4
  store i32 1, i32* %2, align 4
  store i32 1, i32* %3, align 4
  %4 = load i32, i32* %2, align 4
  ret i32 %4
}

And here is the bitcode obtained after running opt -O1 foo.bc -o foo.opt.bc

; Function Attrs: noinline norecurse nounwind readnone uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
  ret i32 1
}

How can I obtain information about passes applied by LLVM opt in the above optimization?

I tried to use several flags of opt of LLVM 10.0, such as --pass-remarks-filter, --debugify-each, --verify-each, --lto-pass-remarks-filter, etc but none of them work.

Does anyone know how to get such kind of information?


Solution

  • The -time-passes option gives you that (and the time taken per pass).

    This option is available in many LLVM tools, but is not listed in the manual, as it intended as a debugging tool for compiler/pass authors.