-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update codegen option documentation. #65136
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Ping from triage |
☔ The latest upstream changes (presumably #64925) made this pull request unmergeable. Please resolve the merge conflicts. |
5544008
to
e0559aa
Compare
r? @Dylan-DPC |
☔ The latest upstream changes (presumably #65716) made this pull request unmergeable. Please resolve the merge conflicts. |
e0559aa
to
4b04440
Compare
Hello from triage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Dylan-DPC I've left my comments in-line.
|
||
The default is 225. | ||
The default depends on the [opt-level](#opt-level). Current values are between | ||
25 to 275. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given this, should we indicate the scores on the optimisation level table above, or is this too subject to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm often reluctant to go into details on how optimizations work. The correct settings usually require experimentation, and heavily depend on the project. They also are very LLVM specific, and are complex. However, I can see how this is annoyingly vague. I added a table, it can be updated or removed in the future if it ever changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, this can be resolved then.
Co-Authored-By: Daniel Silverstone <[email protected]>
e5dbff4
to
c6bfe28
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for taking a look!
|
||
The default is 225. | ||
The default depends on the [opt-level](#opt-level). Current values are between | ||
25 to 275. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm often reluctant to go into details on how optimizations work. The correct settings usually require experimentation, and heavily depend on the project. They also are very LLVM specific, and are complex. However, I can see how this is annoyingly vague. I added a table, it can be updated or removed in the future if it ever changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this looks good.
Ping from triage - Thanks |
@bors r+ rollup |
📌 Commit c6bfe28 has been approved by |
units](#codegen-units). In this case, LTO is disabled if codegen units is 1 or | ||
optimizations are disabled ([`-C opt-level=0`](#opt-level)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this true?
I tried to set exclusive lto and codegen-units option and the binary size is
increased than when I set both lto=true and codegen-units=1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By "exclusive LTO", do you mean not including the flag? Can you clarify which commands you ran?
I would expect it to be larger, since lto=true is "fat", and without the flag it is only "thin local", which does less optimization.
Here is the logic this is referring to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By "exclusive" I mean I either set lto or codegen-units.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I set these options in Cargo.toml, not via rustc arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not sure I understand the confusion here. lto=true
+ codegen-units=1
should be the smallest. It does fat LTO, and with 1 CGU per crate, so it has more optimization potential (but is very slow to compile). That is:
codegen-units=1
: Disables LTO, so won't have cross-crate optimizations.lto=true
: 16 cgus, performs fat LTO across crates.codegen-units=1
+lto=true
: 1 cgu, fat LTO across crates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO adding that to the documentation seems really helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll try to make it a little clearer.
@bors r- |
@lzutao @Dylan-DPC can you take a look at the last commit and see if it helps? Not sure if that really clarifies it not. |
If `-C lto` is not specified, then the compiler will attempt to perform "thin | ||
local LTO" which performs "thin" LTO on the local crate only across its | ||
[codegen units](#codegen-units). When `-C lto` is not specified, LTO is | ||
disabled if codegen units is 1 or optimizations are disabled ([`-C | ||
opt-level=0`](#opt-level)). That is: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this?
[codegen-units] and [opt-level] also affects on how compiler perform LTO:
* When `-C lto` is not specified:
- `codegen-units=1`: Disables LTO.
- `opt-level=0`: Disables LTO.
* When `-C lto=true`:
- `codegen-units=1`: perform fat LTO across crates with 1 codegen unit. Some people prefers to do it in cargo release profile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. That's clearer.
3538ffb
to
9b9d651
Compare
@lzutao ping me when you think this is ready to be merged |
@Dylan-DPC My pleasure. I think this PR is ready to merge. |
@bors: r+ rollup |
📌 Commit 9b9d651 has been approved by |
…an-DPC Update codegen option documentation. Some documentation updates: - Add more detail to codegen options. - Add missing options: - `force-frame-pointers` - `default-linker-libraries` - `linker-plugin-lto` - Add fragment anchors for all command-line-arguments. - Add some cross links between options.
Rollup of 10 pull requests Successful merges: - #65136 (Update codegen option documentation.) - #65574 (docs: improve disclaimer regarding LinkedList) - #65720 (Add FFI bindings for LLVM's Module::getInstructionCount()) - #65905 ([doc] fixes for unix/vxworks `OpenOptionsExt::mode`) - #65962 (Fix logic in example.) - #66019 (Improved std::iter::Chain documentation) - #66038 (doc(str): show example of chars().count() under len()) - #66042 (Suggest correct code when encountering an incorrect trait bound referencing the current trait) - #66073 (Do not needlessly write-lock) - #66096 (Add a failing UI test for multiple loops of all kinds in a `const`) Failed merges: r? @ghost
Some documentation updates:
force-frame-pointers
default-linker-libraries
linker-plugin-lto