简体   繁体   English

rustc 中的优化级别 `-Os` 和 `-Oz` 有什么作用?

[英]What do the optimization levels `-Os` and `-Oz` do in rustc?

Executing rustc -C help shows (among other things):执行rustc -C help显示(除其他外):

-C opt-level=val       -- optimize with possible levels 0-3, s, or z

The levels 0 to 3 are fairly intuitive, I think: the higher the level, the more aggressive optimizations will be performed.我认为 0 到 3 级相当直观:级别越高,执行的优化就越积极。 However, I have no clue what the s and z options are doing and I couldn't find Rust-related information about them.但是,我不知道sz选项在做什么,而且我找不到关于它们的 Rust 相关信息。

It seems like you are not the only one confused, as described in a Rust issue .正如Rust 问题中所述您似乎并不是唯一一个感到困惑的人。 It seems to follow the same pattern as Clang:它似乎遵循与 Clang 相同的模式:

  • Os For optimising the size when compiling. Os用于优化编译时的大小。
  • Oz For even more size optimisation. Oz进行更多尺寸优化。

Looking at these and these lines in Rust's source code, I can say that s means optimize for size, and z means optimize for size some more.查看 Rust 源代码中的这些这些行,我可以说s表示针对大小进行优化,而z表示针对大小进行更多优化。

All optimizations seem to be performed by the LLVM code-generation engine.所有优化似乎都由 LLVM 代码生成引擎执行。

These two sequences, Os and Oz, within LLVM, are pretty similar. LLVM 中的这两个序列 Os 和 Oz 非常相似。 Oz invokes 260 passes (I am using LLVM 12.0), whereas Os invokes 264. Oz' sequence of analyses and optimizations is almost a strict subsequence of Os', except for one pass (opt -loops), which appears in a different place within Os. Oz 调用 260 次传递(我使用的是 LLVM 12.0),而 Os 调用 264 次。Oz 的分析和优化序列几乎是 Os' 的严格子序列,除了一次传递(opt -loops),它出现在内部的不同位置操作系统This said, notice that the effects of the optimizations can still be different, because they use different cost models, eg, constants that determine the behavior of optimizations.这就是说,请注意优化的效果仍然可能不同,因为它们使用不同的成本模型,例如,确定优化行为的常数。 Thus, optimizations that have impact on size, like loop unrolling and inlining can behave differently in these two sequences.因此,对大小有影响的优化,如循环展开和内联,在这两个序列中的行为可能不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改默认的 rustc / Cargo 链接器? - How do I change the default rustc / Cargo linker? 如何指定交叉编译rustc时要使用的编译器? - How do I specify the compiler to use when cross-compiling rustc? 使用rustc_serialize反序列化JSON对象:为什么我需要实现PartialEq? - Deserialising JSON object with rustc_serialize: why do I need to implement PartialEq? 使用 rustc 编译代码时如何指定要使用的版本? - How do I specify the edition to use when compiling code using rustc? 我们如何为同一台 linux 机器上的所有用户安装 rustc、cargo? - How do we install rustc, cargo for all the users in the same linux machine? 如何配置SublimeLinter-contrib-rustc以找到“活塞”箱? - How do I configure SublimeLinter-contrib-rustc to find the “piston” crate? 如何相对于项目位置进行 rustc-link-search? - How do I make rustc-link-search relative to the project location? 试图对 Vec() 的成员进行可变借用,但 rustc 认为我正在尝试可变借用 Vec() - Trying to do a mutable borrow of members of a Vec() but rustc thinks I'm trying to mutable borrow the Vec() 将rustc安装在其他用户的主目录中时,如何执行? - How do you execute rustc when it is installed in another users's home directory? 使用优化时,rustc 是否总是忽略内联(从不)? - Does rustc always ignore inline(never) when optimization is used?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM