[clang] c30d773 - [OpenMP] Change debugging symbol to weak_odr linkage

Joseph Huber via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 17 18:25:54 PDT 2021


Author: Joseph Huber
Date: 2021-09-17T21:25:24-04:00
New Revision: c30d7730ebde18d61b33ae1de9ded69dac6ea6be

URL: https://github.com/llvm/llvm-project/commit/c30d7730ebde18d61b33ae1de9ded69dac6ea6be
DIFF: https://github.com/llvm/llvm-project/commit/c30d7730ebde18d61b33ae1de9ded69dac6ea6be.diff

LOG: [OpenMP] Change debugging symbol to weak_odr linkage

The new device runtime uses an internal variable to set debugging. This
variable was originally privately linked because every module will have
a copy of it. This caused problems with merging the device bitcode
library because it would get renamed and there was not a way to refer to
an external, private symbol. This changes the symbol to weak_odr so it
can be defined multiply, but will not be renamed.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D109997

Added: 
    

Modified: 
    clang/test/OpenMP/target_debug_codegen.cpp
    llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/OpenMP/target_debug_codegen.cpp b/clang/test/OpenMP/target_debug_codegen.cpp
index aa9e1a618773..5932e12a4d5d 100644
--- a/clang/test/OpenMP/target_debug_codegen.cpp
+++ b/clang/test/OpenMP/target_debug_codegen.cpp
@@ -1,4 +1,4 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals --global-value-regex "(__omp_rtl_debug_kind|llvm\.used)"
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals --global-value-regex "__omp_rtl_debug_kind"
 // Test target codegen - host bc file has to be created first.
 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-target-new-runtime -fopenmp-target-debug -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix=CHECK
@@ -10,14 +10,11 @@
 #define HEADER
 
 //.
-// CHECK: @__omp_rtl_debug_kind = private constant i32 1
-// CHECK: @llvm.used = appending global [1 x i8*] [i8* bitcast (i32* @__omp_rtl_debug_kind to i8*)], section "llvm.metadata"
+// CHECK: @__omp_rtl_debug_kind = weak_odr constant i32 1
 //.
-// CHECK-EQ: @__omp_rtl_debug_kind = private constant i32 111
-// CHECK-EQ: @llvm.used = appending global [1 x i8*] [i8* bitcast (i32* @__omp_rtl_debug_kind to i8*)], section "llvm.metadata"
+// CHECK-EQ: @__omp_rtl_debug_kind = weak_odr constant i32 111
 //.
-// CHECK-DEFAULT: @__omp_rtl_debug_kind = private constant i32 0
-// CHECK-DEFAULT: @llvm.used = appending global [1 x i8*] [i8* bitcast (i32* @__omp_rtl_debug_kind to i8*)], section "llvm.metadata"
+// CHECK-DEFAULT: @__omp_rtl_debug_kind = weak_odr constant i32 0
 //.
 void foo() {
 #pragma omp target

diff  --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index fc4580eacacd..fdedea54a897 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -249,11 +249,9 @@ GlobalValue *OpenMPIRBuilder::createDebugKind(unsigned DebugKind) {
   IntegerType *I32Ty = Type::getInt32Ty(M.getContext());
   auto *GV = new GlobalVariable(
       M, I32Ty,
-      /* isConstant = */ true, GlobalValue::PrivateLinkage,
+      /* isConstant = */ true, GlobalValue::WeakODRLinkage,
       ConstantInt::get(I32Ty, DebugKind), "__omp_rtl_debug_kind");
 
-  llvm::appendToUsed(M, {GV});
-
   return GV;
 }
 


        


More information about the cfe-commits mailing list