在发出的 LLVM IR 上执行了哪些 LLVM 传递?

What LLVM passes are performed on emitted LLVM IR?

如果我用 cargo rustc -- --emit=llvm-ir 编译,编译器将发出 LLVM IR。

Here are the LLVM passes that Rust uses. 在发出的 IR 上执行了哪些 LLVM 传递(如果有)?

有什么方法可以指定您希望在发射 IR 之前执行哪些通道?

What LLVM passes, if any, have been performed on the emitted IR?

如果您使用夜间编译器,您可以使用 -Z print-llvm-passes 让 LLVM 打印出 运行 的遍数。我建议也传入 -Z no-parallel-llvm-C codegen-units=1 以使输出更清晰且重复更少。

$ rustc -C codegen-units=1 -Z no-parallel-llvm -Z print-llvm-passes 1.rs

Pass Arguments:  -tti -targetlibinfo -verify -ee-instrument
Target Transform Information
Target Library Information
  FunctionPass Manager
    Module Verifier
    Instrument function entry/exit with calls to e.g. mcount() (pre inlining)
Pass Arguments:  -tti -assumption-cache-tracker -profile-summary-info -targetlibinfo -forceattrs -basiccg -always-inline
Target Transform Information
Assumption Cache Tracker
Profile summary info
Target Library Information
  ModulePass Manager
    Force set function attributes
    CallGraph Construction
    Call Graph SCC Pass Manager
      Inliner for always_inline functions
...

-Z print-llvm-passes 标志等同于 -C llvm-args=-debug-pass=Structure,可在稳定的 rustc 上使用。但是,如果没有 -Z no-parallel-llvm,输出将非常不可读。)


Is there any way to specify what passes you would like performed before emitting IR?

您可以使用 -C passes argument. You may also clear the default optimization passes with -C no-prepopulate-passes 添加额外的通道。示例:

$ rustc -C passes=print-alias-sets 1.rs

Alias sets for function 'Alias sets for function '_ZN3std3sys4unix7process14process_common8ExitCode6as_i3217h65e06df78d6f4a47E':
_ZN3std2rt10lang_start17hd8fe8cd552faf2aaE':
...