Rollup merge of #151071 - gen-openmp-metadata, r=nnethercote

Generate openmp metadata

LLVM has an openmp-opt pass, which is part of the default O3 pipeline.
The pass bails if we don't have a global called openmp, so let's generate it if people enable our experimental offload feature. openmp is a superset of the offload feature, so they share optimizations.
In follow-up PRs I'll start verifying that LLVM optimizes Rust the way we want it.

r? compiler
This commit is contained in:
Jonathan Brouwer
2026-01-19 08:31:31 +01:00
committed by GitHub
2 changed files with 6 additions and 0 deletions
@@ -55,6 +55,10 @@ pub(crate) fn declare(cx: &CodegenCx<'ll, '_>) -> Self {
let init_ty = cx.type_func(&[], cx.type_void());
let init_rtls = declare_offload_fn(cx, "__tgt_init_all_rtls", init_ty);
// We want LLVM's openmp-opt pass to pick up and optimize this module, since it covers both
// openmp and offload optimizations.
llvm::add_module_flag_u32(cx.llmod(), llvm::ModuleFlagMergeBehavior::Max, "openmp", 51);
OffloadGlobals {
launcher_fn,
launcher_ty,
@@ -104,3 +104,5 @@ fn main() {
// CHECK-NEXT: call void @__tgt_unregister_lib(ptr nonnull %EmptyDesc)
// CHECK-NEXT: ret void
// CHECK-NEXT: }
// CHECK: !{i32 7, !"openmp", i32 51}