Skip to content

Commit c171ed4

Browse files
committed
[OpenMP] Fix the linkage for kernel environment global variable
This patch fixes the issue that multiple definition of kernel environment global variables can occur because of wrong linkage. Fixes llvm#64284. Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D156955
1 parent 68ea002 commit c171ed4

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4040,7 +4040,7 @@ OpenMPIRBuilder::createTargetInit(const LocationDescription &Loc, bool IsSPMD) {
40404040
ConstantStruct::get(DynamicEnvironment, {DebugIndentionLevelVal});
40414041
Constant *DynamicEnvironmentGV = new GlobalVariable(
40424042
M, DynamicEnvironment, /* IsConstant */ false,
4043-
GlobalValue::InternalLinkage, DynamicEnvironmentInitializer,
4043+
GlobalValue::WeakODRLinkage, DynamicEnvironmentInitializer,
40444044
DynamicEnvironmentName,
40454045
/* InsertBefore */ nullptr, llvm::GlobalValue::NotThreadLocal,
40464046
DL.getDefaultGlobalsAddressSpace());
@@ -4062,7 +4062,7 @@ OpenMPIRBuilder::createTargetInit(const LocationDescription &Loc, bool IsSPMD) {
40624062
});
40634063
Twine KernelEnvironmentName = KernelName + "_kernel_environment";
40644064
Constant *KernelEnvironmentGV = new GlobalVariable(
4065-
M, KernelEnvironment, /* IsConstant */ true, GlobalValue::ExternalLinkage,
4065+
M, KernelEnvironment, /* IsConstant */ true, GlobalValue::WeakODRLinkage,
40664066
KernelEnvironmentInitializer, KernelEnvironmentName,
40674067
/* InsertBefore */ nullptr, llvm::GlobalValue::NotThreadLocal,
40684068
DL.getDefaultGlobalsAddressSpace());

mlir/test/Target/LLVMIR/omptarget-region-device-llvm.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ module attributes {omp.is_target_device = true} {
2525

2626
// CHECK: @[[SRC_LOC:.*]] = private unnamed_addr constant [23 x i8] c"{{[^"]*}}", align 1
2727
// CHECK: @[[IDENT:.*]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @[[SRC_LOC]] }, align 8
28-
// CHECK: @[[DYNA_ENV:.*]] = internal global %struct.DynamicEnvironmentTy zeroinitializer
29-
// CHECK: @[[KERNEL_ENV:.*]] = constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 1, i8 1, i8 1 }, ptr @[[IDENT]], ptr @[[DYNA_ENV]] }
28+
// CHECK: @[[DYNA_ENV:.*]] = weak_odr global %struct.DynamicEnvironmentTy zeroinitializer
29+
// CHECK: @[[KERNEL_ENV:.*]] = weak_odr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 1, i8 1, i8 1 }, ptr @[[IDENT]], ptr @[[DYNA_ENV]] }
3030
// CHECK: define weak_odr protected void @__omp_offloading_{{[^_]+}}_{{[^_]+}}_omp_target_region__l{{[0-9]+}}(ptr %[[ADDR_A:.*]], ptr %[[ADDR_B:.*]], ptr %[[ADDR_C:.*]])
3131
// CHECK: %[[INIT:.*]] = call i32 @__kmpc_target_init(ptr @[[KERNEL_ENV]])
3232
// CHECK-NEXT: %[[CMP:.*]] = icmp eq i32 %3, -1

0 commit comments

Comments
 (0)