[llvm] c171ed4 - [OpenMP] Fix the linkage for kernel environment global variable
Shilei Tian via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 3 18:33:36 PDT 2023
Author: Shilei Tian
Date: 2023-08-03T21:33:31-04:00
New Revision: c171ed4693fb4fb9b5987e83ed2e5b200b7913ae
URL: https://github.com/llvm/llvm-project/commit/c171ed4693fb4fb9b5987e83ed2e5b200b7913ae
DIFF: https://github.com/llvm/llvm-project/commit/c171ed4693fb4fb9b5987e83ed2e5b200b7913ae.diff
LOG: [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 #64284.
Reviewed By: jhuber6
Differential Revision: https://reviews.llvm.org/D156955
Added:
Modified:
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
mlir/test/Target/LLVMIR/omptarget-region-device-llvm.mlir
Removed:
################################################################################
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index c242870f32ca84..988b0df9eaf1cc 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4040,7 +4040,7 @@ OpenMPIRBuilder::createTargetInit(const LocationDescription &Loc, bool IsSPMD) {
ConstantStruct::get(DynamicEnvironment, {DebugIndentionLevelVal});
Constant *DynamicEnvironmentGV = new GlobalVariable(
M, DynamicEnvironment, /* IsConstant */ false,
- GlobalValue::InternalLinkage, DynamicEnvironmentInitializer,
+ GlobalValue::WeakODRLinkage, DynamicEnvironmentInitializer,
DynamicEnvironmentName,
/* InsertBefore */ nullptr, llvm::GlobalValue::NotThreadLocal,
DL.getDefaultGlobalsAddressSpace());
@@ -4062,7 +4062,7 @@ OpenMPIRBuilder::createTargetInit(const LocationDescription &Loc, bool IsSPMD) {
});
Twine KernelEnvironmentName = KernelName + "_kernel_environment";
Constant *KernelEnvironmentGV = new GlobalVariable(
- M, KernelEnvironment, /* IsConstant */ true, GlobalValue::ExternalLinkage,
+ M, KernelEnvironment, /* IsConstant */ true, GlobalValue::WeakODRLinkage,
KernelEnvironmentInitializer, KernelEnvironmentName,
/* InsertBefore */ nullptr, llvm::GlobalValue::NotThreadLocal,
DL.getDefaultGlobalsAddressSpace());
diff --git a/mlir/test/Target/LLVMIR/omptarget-region-device-llvm.mlir b/mlir/test/Target/LLVMIR/omptarget-region-device-llvm.mlir
index b91106c7d4f925..2ab09f715b2c8d 100644
--- a/mlir/test/Target/LLVMIR/omptarget-region-device-llvm.mlir
+++ b/mlir/test/Target/LLVMIR/omptarget-region-device-llvm.mlir
@@ -25,8 +25,8 @@ module attributes {omp.is_target_device = true} {
// CHECK: @[[SRC_LOC:.*]] = private unnamed_addr constant [23 x i8] c"{{[^"]*}}", align 1
// CHECK: @[[IDENT:.*]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @[[SRC_LOC]] }, align 8
-// CHECK: @[[DYNA_ENV:.*]] = internal global %struct.DynamicEnvironmentTy zeroinitializer
-// CHECK: @[[KERNEL_ENV:.*]] = constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 1, i8 1, i8 1 }, ptr @[[IDENT]], ptr @[[DYNA_ENV]] }
+// CHECK: @[[DYNA_ENV:.*]] = weak_odr global %struct.DynamicEnvironmentTy zeroinitializer
+// CHECK: @[[KERNEL_ENV:.*]] = weak_odr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 1, i8 1, i8 1 }, ptr @[[IDENT]], ptr @[[DYNA_ENV]] }
// CHECK: define weak_odr protected void @__omp_offloading_{{[^_]+}}_{{[^_]+}}_omp_target_region__l{{[0-9]+}}(ptr %[[ADDR_A:.*]], ptr %[[ADDR_B:.*]], ptr %[[ADDR_C:.*]])
// CHECK: %[[INIT:.*]] = call i32 @__kmpc_target_init(ptr @[[KERNEL_ENV]])
// CHECK-NEXT: %[[CMP:.*]] = icmp eq i32 %3, -1
More information about the llvm-commits
mailing list