Skip to content

Commit 36c458d

Browse files
committed
Allow building rustc's LLVM with Offload support
1 parent 52fd998 commit 36c458d

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

config.example.toml

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
# Wheter to build Enzyme as AutoDiff backend.
8585
#enzyme = false
8686

87+
# Whether to build LLVM with support for it's gpu offload runtime.
88+
#offload = false
89+
8790
# Indicates whether ccache is used when building LLVM. Set to `true` to use the first `ccache` in
8891
# PATH, or set an absolute path to use a specific version.
8992
#ccache = false

src/bootstrap/configure.py

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def v(*args):
7272
o("optimize-llvm", "llvm.optimize", "build optimized LLVM")
7373
o("llvm-assertions", "llvm.assertions", "build LLVM with assertions")
7474
o("llvm-enzyme", "llvm.enzyme", "build LLVM with enzyme")
75+
o("llvm-offload", "llvm.offload", "build LLVM with gpu offload support")
7576
o("llvm-plugins", "llvm.plugins", "build LLVM with plugin interface")
7677
o("debug-assertions", "rust.debug-assertions", "build with debugging assertions")
7778
o("debug-assertions-std", "rust.debug-assertions-std", "build the standard library with debugging assertions")

src/bootstrap/src/core/build_steps/llvm.rs

+15
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,21 @@ impl Step for Llvm {
459459
cfg.define("LLVM_ENABLE_PROJECTS", enabled_llvm_projects.join(";"));
460460
}
461461

462+
let mut enabled_llvm_runtimes = Vec::new();
463+
464+
if builder.config.llvm_offload {
465+
enabled_llvm_runtimes.push("offload");
466+
//FIXME(ZuseZ4): LLVM intends to drop the offload dependency on openmp.
467+
//Remove this line once they achieved it.
468+
enabled_llvm_runtimes.push("openmp");
469+
}
470+
471+
if !enabled_llvm_runtimes.is_empty() {
472+
enabled_llvm_runtimes.sort();
473+
enabled_llvm_runtimes.dedup();
474+
cfg.define("LLVM_ENABLE_RUNTIMES", enabled_llvm_runtimes.join(";"));
475+
}
476+
462477
if let Some(num_linkers) = builder.config.llvm_link_jobs {
463478
if num_linkers > 0 {
464479
cfg.define("LLVM_PARALLEL_LINK_JOBS", num_linkers.to_string());

src/bootstrap/src/core/config/config.rs

+9
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ pub struct Config {
224224
pub llvm_assertions: bool,
225225
pub llvm_tests: bool,
226226
pub llvm_enzyme: bool,
227+
pub llvm_offload: bool,
227228
pub llvm_plugins: bool,
228229
pub llvm_optimize: bool,
229230
pub llvm_thin_lto: bool,
@@ -930,6 +931,7 @@ define_config! {
930931
use_libcxx: Option<bool> = "use-libcxx",
931932
use_linker: Option<String> = "use-linker",
932933
allow_old_toolchain: Option<bool> = "allow-old-toolchain",
934+
offload: Option<bool> = "offload",
933935
polly: Option<bool> = "polly",
934936
clang: Option<bool> = "clang",
935937
enable_warnings: Option<bool> = "enable-warnings",
@@ -1636,6 +1638,7 @@ impl Config {
16361638
// we'll infer default values for them later
16371639
let mut llvm_tests = None;
16381640
let mut llvm_enzyme = None;
1641+
let mut llvm_offload = None;
16391642
let mut llvm_plugins = None;
16401643
let mut debug = None;
16411644
let mut debug_assertions = None;
@@ -1873,6 +1876,7 @@ impl Config {
18731876
use_libcxx,
18741877
use_linker,
18751878
allow_old_toolchain,
1879+
offload,
18761880
polly,
18771881
clang,
18781882
enable_warnings,
@@ -1889,6 +1893,7 @@ impl Config {
18891893
set(&mut config.ninja_in_file, ninja);
18901894
llvm_tests = tests;
18911895
llvm_enzyme = enzyme;
1896+
llvm_offload = offload;
18921897
llvm_plugins = plugins;
18931898
set(&mut config.llvm_optimize, optimize_toml);
18941899
set(&mut config.llvm_thin_lto, thin_lto);
@@ -1910,6 +1915,7 @@ impl Config {
19101915
set(&mut config.llvm_use_libcxx, use_libcxx);
19111916
config.llvm_use_linker.clone_from(&use_linker);
19121917
config.llvm_allow_old_toolchain = allow_old_toolchain.unwrap_or(false);
1918+
config.llvm_offload = offload.unwrap_or(false);
19131919
config.llvm_polly = polly.unwrap_or(false);
19141920
config.llvm_clang = clang.unwrap_or(false);
19151921
config.llvm_enable_warnings = enable_warnings.unwrap_or(false);
@@ -2086,6 +2092,7 @@ impl Config {
20862092

20872093
config.llvm_tests = llvm_tests.unwrap_or(false);
20882094
config.llvm_enzyme = llvm_enzyme.unwrap_or(false);
2095+
config.llvm_offload = llvm_offload.unwrap_or(false);
20892096
config.llvm_plugins = llvm_plugins.unwrap_or(false);
20902097
config.rust_optimize = optimize.unwrap_or(RustOptimize::Bool(true));
20912098

@@ -2970,6 +2977,7 @@ pub(crate) fn check_incompatible_options_for_ci_llvm(
29702977
use_libcxx,
29712978
use_linker,
29722979
allow_old_toolchain,
2980+
offload,
29732981
polly,
29742982
clang,
29752983
enable_warnings,
@@ -2992,6 +3000,7 @@ pub(crate) fn check_incompatible_options_for_ci_llvm(
29923000
err!(current_llvm_config.use_libcxx, use_libcxx);
29933001
err!(current_llvm_config.use_linker, use_linker);
29943002
err!(current_llvm_config.allow_old_toolchain, allow_old_toolchain);
3003+
err!(current_llvm_config.offload, offload);
29953004
err!(current_llvm_config.polly, polly);
29963005
err!(current_llvm_config.clang, clang);
29973006
err!(current_llvm_config.build_config, build_config);

0 commit comments

Comments
 (0)