Skip to content

Commit 6e74905

Browse files
committed
Set lto="fat" automatically when compiling with RUSTFLAGS="-Zautodiff=Enable".
1 parent 9311767 commit 6e74905

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ codegen_ssa_aix_strip_not_used = using host's `strip` binary to cross-compile to
88
99
codegen_ssa_archive_build_failure = failed to build archive at `{$path}`: {$error}
1010
11-
codegen_ssa_autodiff_without_lto = using the autodiff feature requires using fat-lto
12-
1311
codegen_ssa_bare_instruction_set = `#[instruction_set]` requires an argument
1412
1513
codegen_ssa_binary_output_to_tty = option `-o` or `--emit` is used to write binary output type `{$shorthand}` to stdout, but stdout is a tty

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ pub(crate) struct CguNotRecorded<'a> {
3737
pub cgu_name: &'a str,
3838
}
3939

40-
#[derive(Diagnostic)]
41-
#[diag(codegen_ssa_autodiff_without_lto)]
42-
pub struct AutodiffWithoutLto;
43-
4440
#[derive(Diagnostic)]
4541
#[diag(codegen_ssa_unknown_reuse_kind)]
4642
pub(crate) struct UnknownReuseKind {

compiler/rustc_session/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,11 @@ impl Options {
15091509
pub fn get_symbol_mangling_version(&self) -> SymbolManglingVersion {
15101510
self.cg.symbol_mangling_version.unwrap_or(SymbolManglingVersion::Legacy)
15111511
}
1512+
1513+
#[inline]
1514+
pub fn autodiff_enabled(&self) -> bool {
1515+
self.unstable_opts.autodiff.contains(&AutoDiff::Enable)
1516+
}
15121517
}
15131518

15141519
impl UnstableOptions {

compiler/rustc_session/src/session.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,13 @@ impl Session {
600600

601601
/// Calculates the flavor of LTO to use for this compilation.
602602
pub fn lto(&self) -> config::Lto {
603+
// Autodiff currently requires fat-lto to have access to the llvm-ir of all (indirectly) used functions and types.
604+
// fat-lto is the easiest solution to this requirement, but quite expensive.
605+
// FIXME(autodiff): Make autodiff also work with embed-bc instead of fat-lto.
606+
if self.opts.autodiff_enabled() {
607+
return config::Lto::Fat;
608+
}
609+
603610
// If our target has codegen requirements ignore the command line
604611
if self.target.requires_lto {
605612
return config::Lto::Fat;

0 commit comments

Comments
 (0)