Skip to content

Commit 1991779

Browse files
committed
Make llvm_enzyme a regular cargo feature
This makes it clearer that it is set by the build system rather than by the rustc that compiles the current rustc. It also avoids bootstrap needing to pass --check-cfg llvm_enzyme to rustc.
1 parent d1ed52b commit 1991779

File tree

11 files changed

+23
-15
lines changed

11 files changed

+23
-15
lines changed

compiler/rustc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ features = ['unprefixed_malloc_on_supported_platforms']
3030
check_only = ['rustc_driver_impl/check_only']
3131
jemalloc = ['dep:tikv-jemalloc-sys']
3232
llvm = ['rustc_driver_impl/llvm']
33+
llvm_enzyme = ['rustc_driver_impl/llvm_enzyme']
3334
max_level_info = ['rustc_driver_impl/max_level_info']
3435
rustc_randomized_layouts = ['rustc_driver_impl/rustc_randomized_layouts']
3536
# tidy-alphabetical-end

compiler/rustc_builtin_macros/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
3333
thin-vec = "0.2.12"
3434
tracing = "0.1"
3535
# tidy-alphabetical-end
36+
37+
[features]
38+
# tidy-alphabetical-start
39+
llvm_enzyme = []
40+
# tidy-alphabetical-end

compiler/rustc_builtin_macros/src/autodiff.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ mod llvm_enzyme {
209209
mut item: Annotatable,
210210
mode: DiffMode,
211211
) -> Vec<Annotatable> {
212-
if cfg!(not(llvm_enzyme)) {
212+
// FIXME(bjorn3) maybe have the backend directly tell if autodiff is supported?
213+
if cfg!(not(feature = "llvm_enzyme")) {
213214
ecx.sess.dcx().emit_err(errors::AutoDiffSupportNotBuild { span: meta_item.span });
214215
return vec![item];
215216
}

compiler/rustc_codegen_llvm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ tracing = "0.1"
4646
[features]
4747
# tidy-alphabetical-start
4848
check_only = ["rustc_llvm/check_only"]
49+
llvm_enzyme = []
4950
# tidy-alphabetical-end
5051

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ pub(crate) fn run_pass_manager(
617617
crate::builder::gpu_offload::handle_gpu_code(cgcx, &cx);
618618
}
619619

620-
if cfg!(llvm_enzyme) && enable_ad && !thin {
620+
if cfg!(feature = "llvm_enzyme") && enable_ad && !thin {
621621
let opt_stage = llvm::OptStage::FatLTO;
622622
let stage = write::AutodiffStage::PostAD;
623623
if !config.autodiff.contains(&config::AutoDiff::NoPostopt) {

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ pub(crate) unsafe fn llvm_optimize(
574574
// FIXME(ZuseZ4): In a future update we could figure out how to only optimize individual functions getting
575575
// differentiated.
576576

577-
let consider_ad = cfg!(llvm_enzyme) && config.autodiff.contains(&config::AutoDiff::Enable);
577+
let consider_ad =
578+
cfg!(feature = "llvm_enzyme") && config.autodiff.contains(&config::AutoDiff::Enable);
578579
let run_enzyme = autodiff_stage == AutodiffStage::DuringAD;
579580
let print_before_enzyme = config.autodiff.contains(&config::AutoDiff::PrintModBefore);
580581
let print_after_enzyme = config.autodiff.contains(&config::AutoDiff::PrintModAfter);
@@ -740,7 +741,8 @@ pub(crate) fn optimize(
740741

741742
// If we know that we will later run AD, then we disable vectorization and loop unrolling.
742743
// Otherwise we pretend AD is already done and run the normal opt pipeline (=PostAD).
743-
let consider_ad = cfg!(llvm_enzyme) && config.autodiff.contains(&config::AutoDiff::Enable);
744+
let consider_ad =
745+
cfg!(feature = "llvm_enzyme") && config.autodiff.contains(&config::AutoDiff::Enable);
744746
let autodiff_stage = if consider_ad { AutodiffStage::PreAD } else { AutodiffStage::PostAD };
745747
// The embedded bitcode is used to run LTO/ThinLTO.
746748
// The bitcode obtained during the `codegen` phase is no longer suitable for performing LTO.

compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ pub(crate) enum LLVMRustVerifierFailureAction {
5959
LLVMReturnStatusAction = 2,
6060
}
6161

62-
#[cfg(llvm_enzyme)]
62+
#[cfg(feature = "llvm_enzyme")]
6363
pub(crate) use self::Enzyme_AD::*;
6464

65-
#[cfg(llvm_enzyme)]
65+
#[cfg(feature = "llvm_enzyme")]
6666
pub(crate) mod Enzyme_AD {
6767
use std::ffi::{CString, c_char};
6868

@@ -134,10 +134,10 @@ pub(crate) mod Enzyme_AD {
134134
}
135135
}
136136

137-
#[cfg(not(llvm_enzyme))]
137+
#[cfg(not(feature = "llvm_enzyme"))]
138138
pub(crate) use self::Fallback_AD::*;
139139

140-
#[cfg(not(llvm_enzyme))]
140+
#[cfg(not(feature = "llvm_enzyme"))]
141141
pub(crate) mod Fallback_AD {
142142
#![allow(unused_variables)]
143143

compiler/rustc_driver_impl/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ ctrlc = "3.4.4"
7474
# tidy-alphabetical-start
7575
check_only = ['rustc_interface/check_only']
7676
llvm = ['rustc_interface/llvm']
77+
llvm_enzyme = ['rustc_interface/llvm_enzyme']
7778
max_level_info = ['rustc_log/max_level_info']
7879
rustc_randomized_layouts = [
7980
'rustc_index/rustc_randomized_layouts',

compiler/rustc_interface/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ rustc_abi = { path = "../rustc_abi" }
5858
# tidy-alphabetical-start
5959
check_only = ['rustc_codegen_llvm?/check_only']
6060
llvm = ['dep:rustc_codegen_llvm']
61+
llvm_enzyme = ['rustc_builtin_macros/llvm_enzyme', 'rustc_codegen_llvm/llvm_enzyme']
6162
# tidy-alphabetical-end

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,10 +1357,6 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
13571357
cargo.env("RUSTC_VERIFY_LLVM_IR", "1");
13581358
}
13591359

1360-
if builder.config.llvm_enzyme {
1361-
cargo.rustflag("--cfg=llvm_enzyme");
1362-
}
1363-
13641360
// These conditionals represent a tension between three forces:
13651361
// - For non-check builds, we need to define some LLVM-related environment
13661362
// variables, requiring LLVM to have been built.

0 commit comments

Comments
 (0)