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
commit a56e2d3037
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 0 deletions

View file

@ -55,6 +55,10 @@ impl<'ll> OffloadGlobals<'ll> {
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,

View file

@ -104,3 +104,5 @@ pub fn _kernel_1(x: &mut [f32; 256]) {
// CHECK-NEXT: call void @__tgt_unregister_lib(ptr nonnull %EmptyDesc)
// CHECK-NEXT: ret void
// CHECK-NEXT: }
// CHECK: !{i32 7, !"openmp", i32 51}