Skip to content
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

Deprecate no-op codegen option -Cinline-threshold=... #124712

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,6 @@ pub(crate) unsafe fn llvm_optimize(

let llvm_plugins = config.llvm_plugins.join(",");

// FIXME: NewPM doesn't provide a facility to pass custom InlineParams.
// We would have to add upstream support for this first, before we can support
// config.inline_threshold and our more aggressive default thresholds.
let result = llvm::LLVMRustOptimize(
module.module_llvm.llmod(),
&*module.module_llvm.tm,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ pub struct ModuleConfig {
pub vectorize_loop: bool,
pub vectorize_slp: bool,
pub merge_functions: bool,
pub inline_threshold: Option<u32>,
pub emit_lifetime_markers: bool,
pub llvm_plugins: Vec<String>,
}
Expand Down Expand Up @@ -280,7 +279,6 @@ impl ModuleConfig {
}
},

inline_threshold: sess.opts.cg.inline_threshold,
emit_lifetime_markers: sess.emit_lifetime_markers(),
llvm_plugins: if_regular!(sess.opts.unstable_opts.llvm_plugins.clone(), vec![]),
}
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,11 @@ pub fn describe_flag_categories(early_dcx: &EarlyDiagCtxt, matches: &Matches) ->
}

if cg_flags.iter().any(|x| *x == "no-stack-check") {
early_dcx.early_warn("the --no-stack-check flag is deprecated and does nothing");
early_dcx.early_warn("the `-Cno-stack-check` flag is deprecated and does nothing");
}

if cg_flags.iter().any(|x| x.starts_with("inline-threshold")) {
early_dcx.early_warn("the `-Cinline-threshold` flag is deprecated and does nothing (consider using `-Cllvm-args=--inline-threshold=...`)");
}

if cg_flags.iter().any(|x| *x == "passes=list") {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,8 @@ options! {
incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
"enable incremental compilation"),
inline_threshold: Option<u32> = (None, parse_opt_number, [TRACKED],
Copy link
Member

@fmease fmease Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR: If the deprecation ends up getting accepted (rather than the remapping), please emit a warning like -Cno-stack-check does (and unlike -Car=... which we might want to change in a separate PR).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, including regression test.

Note that I also added this commit to this PR:

commit 651ff643ae68438213bded335ef47cc9c50d3039
Author: Martin Nordholts <martin.nordholts@codetale.se>
Date:   Fri Jun 14 19:48:40 2024 +0200

    Fix typo in `-Cno-stack-check` deprecation warning

    The flag `--no-stack-check` does not exist:

        $ rustc --no-stack-check
        error: Unrecognized option: 'no-stack-check'. Did you mean `-C no-stack-check`?

"set the threshold for inlining a function"),
"this option is deprecated and does nothing \
(consider using `-Cllvm-args=--inline-threshold=...`)"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this have any effect if they do?

Copy link
Member Author

@Enselic Enselic May 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that makes a difference. Building e.g. libstd with -Cllvm-args=--inline-threshold=100000 vs -Cllvm-args=--inline-threshold=2 reliably makes a big difference in the size of .text, namely 1594 kB vs 367 kB:

$ RUSTFLAGS="-Ccodegen-units=1 -Cllvm-args=--inline-threshold=100000" ./x build --stage 0 library/std
$ size ./build/x86_64-unknown-linux-gnu/stage0-std/x86_64-unknown-linux-gnu/release/libstd.rlib
   text   ...
      0   ...
1594437   ...
$ RUSTFLAGS="-Ccodegen-units=1 -Cllvm-args=--inline-threshold=2" ./x build --stage 0 library/std
$ size ./build/x86_64-unknown-linux-gnu/stage0-std/x86_64-unknown-linux-gnu/release/libstd.rlib
   text   ...
      0   ...
 367682   ...

Another example is bat with 33 MB vs 5.4 MB:

$ RUSTFLAGS="-Cllvm-args=--inline-threshold=2" cargo build --release
$ ls -hl target/release/bat
-rwxr-xr-x 2 martin martin 5.4M May  5 10:58 target/release/bat
$ RUSTFLAGS="-Cllvm-args=--inline-threshold=100000" cargo build --release
$ ls -hl target/release/bat
-rwxr-xr-x 2 martin martin 33M May  5 11:13 target/release/bat

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh neat, I'm surprised it does anything!

#[rustc_lint_opt_deny_field_access("use `Session::instrument_coverage` instead of this field")]
instrument_coverage: InstrumentCoverage = (InstrumentCoverage::No, parse_instrument_coverage, [TRACKED],
"instrument the generated code to support LLVM source-based code coverage reports \
Expand Down
17 changes: 3 additions & 14 deletions src/doc/rustc/src/codegen-options/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,9 @@ incremental files will be stored.

## inline-threshold

This option lets you set the default threshold for inlining a function. It
takes an unsigned integer as a value. Inlining is based on a cost model, where
a higher threshold will allow more inlining.

The default depends on the [opt-level](#opt-level):

| opt-level | Threshold |
|-----------|-----------|
| 0 | N/A, only inlines always-inline functions |
| 1 | N/A, only inlines always-inline functions and LLVM lifetime intrinsics |
| 2 | 225 |
| 3 | 275 |
| s | 75 |
| z | 25 |
This option is deprecated and does nothing.

Consider using `-Cllvm-args=--inline-threshold=...`.

## instrument-coverage

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/codegen/issue-82833-slice-miscompile.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ run-pass
//@ compile-flags: -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Copt-level=0 -Cdebuginfo=2
//@ compile-flags: -Ccodegen-units=1 -Cllvm-args=--inline-threshold=0 -Clink-dead-code -Copt-level=0 -Cdebuginfo=2

// Make sure LLVM does not miscompile this.

Expand Down
4 changes: 4 additions & 0 deletions tests/ui/deprecation/deprecated_inline_threshold.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//@ check-pass
//@ compile-flags: -Cinline-threshold=666

fn main() {}
2 changes: 2 additions & 0 deletions tests/ui/deprecation/deprecated_inline_threshold.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
warning: the `-Cinline-threshold` flag is deprecated and does nothing (consider using `-Cllvm-args=--inline-threshold=...`)

Loading