diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index a58739c9e65cb..a3c13fc4b0959 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -2064,6 +2064,10 @@ Please disable assertions with `rust.debug-assertions = false`. cmd.arg("--has-enzyme"); } + if builder.build.config.llvm_offload { + cmd.arg("--has-offload"); + } + if builder.config.cmd.bless() { cmd.arg("--bless"); } diff --git a/src/doc/rustc-dev-guide/src/tests/directives.md b/src/doc/rustc-dev-guide/src/tests/directives.md index c8b0072dc1010..4852c3623b05c 100644 --- a/src/doc/rustc-dev-guide/src/tests/directives.md +++ b/src/doc/rustc-dev-guide/src/tests/directives.md @@ -213,6 +213,8 @@ settings: that this directive can be overriden with the `--bypass-ignore-backends=[BACKEND]` command line flag. - `needs-backends` — only runs the test if current codegen backend is listed. +- `needs-offload` — ignores if our LLVM backend was not built with offload support. +- `needs-enzyme` — ignores if our Enzyme submodule was not built. The following directives will check LLVM support: diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 9473e51688cbb..5563abe92a80b 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -625,6 +625,9 @@ pub struct Config { /// Whether to run `enzyme` autodiff tests. pub has_enzyme: bool, + /// Whether to run `offload` autodiff tests. + pub has_offload: bool, + /// The current Rust channel info. /// /// FIXME: treat this more carefully; "stable", "beta" and "nightly" are definitely valid, but diff --git a/src/tools/compiletest/src/directives/cfg.rs b/src/tools/compiletest/src/directives/cfg.rs index e89c1330f4670..6431eb6b090b1 100644 --- a/src/tools/compiletest/src/directives/cfg.rs +++ b/src/tools/compiletest/src/directives/cfg.rs @@ -164,6 +164,7 @@ pub(crate) fn prepare_conditions(config: &Config) -> PreparedConditions { // FIXME(Zalathar): Support all known binary formats, not just ELF? builder.cond("elf", current.binary_format == "elf", "when the target binary format is ELF"); builder.cond("enzyme", config.has_enzyme, "when rustc is built with LLVM Enzyme"); + builder.cond("offload", config.has_offload, "when rustc is built with LLVM Offload"); // Technically the locally built compiler uses the "dev" channel rather than the "nightly" // channel, even though most people don't know or won't care about it. To avoid confusion, we diff --git a/src/tools/compiletest/src/directives/directive_names.rs b/src/tools/compiletest/src/directives/directive_names.rs index 282e2a131d932..9813ac7ff500d 100644 --- a/src/tools/compiletest/src/directives/directive_names.rs +++ b/src/tools/compiletest/src/directives/directive_names.rs @@ -165,6 +165,7 @@ pub(crate) const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ "needs-git-hash", "needs-llvm-components", "needs-llvm-zstd", + "needs-offload", "needs-profiler-runtime", "needs-relocation-model-pic", "needs-run-enabled", diff --git a/src/tools/compiletest/src/directives/needs.rs b/src/tools/compiletest/src/directives/needs.rs index 36c2ca62cd87a..32ce6cf7b9895 100644 --- a/src/tools/compiletest/src/directives/needs.rs +++ b/src/tools/compiletest/src/directives/needs.rs @@ -91,6 +91,11 @@ pub(super) fn handle_needs( condition: config.has_enzyme && config.default_codegen_backend.is_llvm(), ignore_reason: "ignored when LLVM Enzyme is disabled or LLVM is not the default codegen backend", }, + Need { + name: "needs-offload", + condition: config.has_offload && config.default_codegen_backend.is_llvm(), + ignore_reason: "ignored when LLVM Offload is disabled or LLVM is not the default codegen backend", + }, Need { name: "needs-run-enabled", condition: config.run_enabled(), diff --git a/src/tools/compiletest/src/lib.rs b/src/tools/compiletest/src/lib.rs index 83aee865e0102..a64c7850aad4d 100644 --- a/src/tools/compiletest/src/lib.rs +++ b/src/tools/compiletest/src/lib.rs @@ -104,6 +104,7 @@ fn parse_config(args: Vec) -> Config { .optopt("", "run", "whether to execute run-* tests", "auto | always | never") .optflag("", "ignored", "run tests marked as ignored") .optflag("", "has-enzyme", "run tests that require enzyme") + .optflag("", "has-offload", "run tests that require offload") .optflag("", "with-rustc-debug-assertions", "whether rustc was built with debug assertions") .optflag("", "with-std-debug-assertions", "whether std was built with debug assertions") .optflag("", "with-std-remap-debuginfo", "whether std was built with remapping") @@ -299,6 +300,7 @@ fn parse_config(args: Vec) -> Config { let with_std_remap_debuginfo = matches.opt_present("with-std-remap-debuginfo"); let mode = matches.opt_str("mode").unwrap().parse().expect("invalid mode"); let has_enzyme = matches.opt_present("has-enzyme"); + let has_offload = matches.opt_present("has-offload"); let filters = if mode == TestMode::RunMake { matches .free @@ -444,6 +446,7 @@ fn parse_config(args: Vec) -> Config { compare_mode, rustfix_coverage: matches.opt_present("rustfix-coverage"), has_enzyme, + has_offload, channel: matches.opt_str("channel").unwrap(), git_hash: matches.opt_present("git-hash"), edition: matches.opt_str("edition").as_deref().map(parse_edition), diff --git a/src/tools/compiletest/src/rustdoc_gui_test.rs b/src/tools/compiletest/src/rustdoc_gui_test.rs index 2b057bb35519a..4454ffb1f59e6 100644 --- a/src/tools/compiletest/src/rustdoc_gui_test.rs +++ b/src/tools/compiletest/src/rustdoc_gui_test.rs @@ -113,6 +113,7 @@ fn incomplete_config_for_rustdoc_gui_test() -> Config { compare_mode: Default::default(), rustfix_coverage: Default::default(), has_enzyme: Default::default(), + has_offload: Default::default(), channel: Default::default(), git_hash: Default::default(), cc: Default::default(),