Skip to content

Commit 9b9d651

Browse files
committed
Attempt to clarify LTO and codegen-units.
1 parent c6bfe28 commit 9b9d651

File tree

1 file changed

+21
-10
lines changed
  • src/doc/rustc/src/codegen-options

1 file changed

+21
-10
lines changed

src/doc/rustc/src/codegen-options/index.md

+21-10
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,18 @@ This flag may take one of the following values:
7474
This is similar to "fat", but takes substantially less time to run while
7575
still achieving performance gains similar to "fat".
7676

77-
If `-C lto` is not specified, then the compiler will attempt to perform "thin local LTO"
78-
which performs "thin" LTO on the local crate only across its [codegen
79-
units](#codegen-units). In this case, LTO is disabled if codegen units is 1 or
80-
optimizations are disabled ([`-C opt-level=0`](#opt-level)).
77+
If `-C lto` is not specified, then the compiler will attempt to perform "thin
78+
local LTO" which performs "thin" LTO on the local crate only across its
79+
[codegen units](#codegen-units). When `-C lto` is not specified, LTO is
80+
disabled if codegen units is 1 or optimizations are disabled ([`-C
81+
opt-level=0`](#opt-level)). That is:
82+
83+
* When `-C lto` is not specified:
84+
* `codegen-units=1`: Disables LTO.
85+
* `opt-level=0`: Disables LTO.
86+
* When `-C lto=true`:
87+
* `lto=true`: 16 codegen units, performs fat LTO across crates.
88+
* `codegen-units=1` + `lto=true`: 1 codegen unit, fat LTO across crates.
8189

8290
See also [linker-plugin-lto](#linker-plugin-lto) for cross-language LTO.
8391

@@ -237,14 +245,17 @@ flag][option-emit] for more information.
237245

238246
## codegen-units
239247

240-
This flag lets you control how many threads are used when doing code
241-
generation. It takes an integer greater than 0.
248+
This flag controls how many code generation units the crate is split into. It
249+
takes an integer greater than 0.
242250

243-
Increasing parallelism may speed up compile times, but may also produce slower
244-
code. Setting this to 1 may improve the performance of generated code, but may
245-
be slower to compile.
251+
When a crate is split into multiple codegen units, LLVM is able to process
252+
them in parallel. Increasing parallelism may speed up compile times, but may
253+
also produce slower code. Setting this to 1 may improve the performance of
254+
generated code, but may be slower to compile.
246255

247-
The default, if not specified, is 16.
256+
The default, if not specified, is 16. This flag is ignored if
257+
[incremental](#incremental) is enabled, in which case an internal heuristic is
258+
used to split the crate.
248259

249260
## remark
250261

0 commit comments

Comments
 (0)