Skip to content

Commit 2a50b05

Browse files
committed
update openmp/offload builds to LLVM 22
1 parent 44e34e1 commit 2a50b05

1 file changed

Lines changed: 56 additions & 40 deletions

File tree

  • src/bootstrap/src/core/build_steps

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

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,30 +1008,6 @@ impl Step for OmpOffload {
10081008
t!(fs::create_dir_all(&out_dir));
10091009

10101010
builder.config.update_submodule("src/llvm-project");
1011-
let mut cfg = cmake::Config::new(builder.src.join("src/llvm-project/runtimes/"));
1012-
1013-
// If we use an external clang as opposed to building our own llvm_clang, than that clang will
1014-
// come with it's own set of default include directories, which are based on a potentially older
1015-
// LLVM. This can cause issues, so we overwrite it to include headers based on our
1016-
// `src/llvm-project` submodule instead.
1017-
// FIXME(offload): With LLVM-22 we hopefully won't need an external clang anymore.
1018-
let mut cflags = CcFlags::default();
1019-
if !builder.config.llvm_clang {
1020-
let base = builder.llvm_out(target).join("include");
1021-
let inc_dir = base.display();
1022-
cflags.push_all(format!(" -I {inc_dir}"));
1023-
}
1024-
1025-
configure_cmake(builder, target, &mut cfg, true, LdFlags::default(), cflags, &[]);
1026-
1027-
// Re-use the same flags as llvm to control the level of debug information
1028-
// generated for offload.
1029-
let profile = match (builder.config.llvm_optimize, builder.config.llvm_release_debuginfo) {
1030-
(false, _) => "Debug",
1031-
(true, false) => "Release",
1032-
(true, true) => "RelWithDebInfo",
1033-
};
1034-
trace!(?profile);
10351011

10361012
// OpenMP/Offload builds currently (LLVM-21) still depend on Clang, although there are
10371013
// intentions to loosen this requirement for LLVM-22. If we were to
@@ -1044,23 +1020,63 @@ impl Step for OmpOffload {
10441020
None
10451021
};
10461022

1047-
// FIXME(offload): Once we move from OMP to Offload (Ol) APIs, we should drop the openmp
1048-
// runtime to simplify our build. We should also re-evaluate the LLVM_Root and try to get
1049-
// rid of the Clang_DIR, once we upgrade to LLVM-22.
1050-
cfg.out_dir(&out_dir)
1051-
.profile(profile)
1052-
.env("LLVM_CONFIG_REAL", &host_llvm_config)
1053-
.define("LLVM_ENABLE_ASSERTIONS", "ON")
1054-
.define("LLVM_ENABLE_RUNTIMES", "openmp;offload")
1055-
.define("LLVM_INCLUDE_TESTS", "OFF")
1056-
.define("OFFLOAD_INCLUDE_TESTS", "OFF")
1057-
.define("OPENMP_STANDALONE_BUILD", "ON")
1058-
.define("LLVM_ROOT", builder.llvm_out(target).join("build"))
1059-
.define("LLVM_DIR", llvm_cmake_dir);
1060-
if let Some(p) = clang_dir {
1061-
cfg.define("Clang_DIR", p);
1023+
let omp_targets = vec![target.triple.as_ref(), "amdgcn-amd-amdhsa", "nvptx64-nvidia-cuda"];
1024+
for omp_target in omp_targets {
1025+
let mut cfg = cmake::Config::new(builder.src.join("src/llvm-project/runtimes/"));
1026+
1027+
// If we use an external clang as opposed to building our own llvm_clang, than that clang will
1028+
// come with it's own set of default include directories, which are based on a potentially older
1029+
// LLVM. This can cause issues, so we overwrite it to include headers based on our
1030+
// `src/llvm-project` submodule instead.
1031+
// FIXME(offload): With LLVM-22 we hopefully won't need an external clang anymore.
1032+
let mut cflags = CcFlags::default();
1033+
if !builder.config.llvm_clang {
1034+
let base = builder.llvm_out(target).join("include");
1035+
let inc_dir = base.display();
1036+
cflags.push_all(format!(" -I {inc_dir}"));
1037+
}
1038+
1039+
configure_cmake(builder, target, &mut cfg, true, LdFlags::default(), cflags, &[]);
1040+
1041+
// Re-use the same flags as llvm to control the level of debug information
1042+
// generated for offload.
1043+
let profile =
1044+
match (builder.config.llvm_optimize, builder.config.llvm_release_debuginfo) {
1045+
(false, _) => "Debug",
1046+
(true, false) => "Release",
1047+
(true, true) => "RelWithDebInfo",
1048+
};
1049+
trace!(?profile);
1050+
1051+
// FIXME(offload): Once we move from OMP to Offload (Ol) APIs, we should drop the openmp
1052+
// runtime to simplify our build. So far, these are still under development.
1053+
cfg.out_dir(&out_dir)
1054+
.profile(profile)
1055+
.env("LLVM_CONFIG_REAL", &host_llvm_config)
1056+
.define("LLVM_ENABLE_ASSERTIONS", "ON")
1057+
.define("LLVM_INCLUDE_TESTS", "OFF")
1058+
.define("OFFLOAD_INCLUDE_TESTS", "OFF")
1059+
.define("LLVM_ROOT", builder.llvm_out(target).join("build"))
1060+
.define("LLVM_DIR", llvm_cmake_dir.clone())
1061+
.define("LLVM_DEFAULT_TARGET_TRIPLE", omp_target);
1062+
if let Some(p) = clang_dir.clone() {
1063+
cfg.define("Clang_DIR", p);
1064+
}
1065+
1066+
// We don't perform a full cross-compilation of rustc, therefore our target.triple
1067+
// will still be a CPU target.
1068+
if *omp_target == *target.triple {
1069+
// The offload library provides functionality which only makes sense on the host.
1070+
cfg.define("LLVM_ENABLE_RUNTIMES", "openmp;offload");
1071+
} else {
1072+
// OpenMP provides some device libraries, so we also compile it for all gpu targets.
1073+
cfg.define("LLVM_USE_LINKER", "lld");
1074+
cfg.define("LLVM_ENABLE_RUNTIMES", "openmp");
1075+
cfg.define("CMAKE_C_COMPILER_TARGET", omp_target);
1076+
cfg.define("CMAKE_CXX_COMPILER_TARGET", omp_target);
1077+
}
1078+
cfg.build();
10621079
}
1063-
cfg.build();
10641080

10651081
t!(stamp.write());
10661082

0 commit comments

Comments
 (0)