[PATCH] D147572: [Clang][OpenMP] Fix failure with team-wide allocated variable

Gheorghe-Teodor Bercea via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 4 14:51:40 PDT 2023


doru1004 updated this revision to Diff 510934.
Herald added subscribers: llvm-commits, kosarev, foad, kerbowa, hiraditya, jvesely, arsenm.
Herald added a project: LLVM.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147572/new/

https://reviews.llvm.org/D147572

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/OpenMP/target_team_variable_codegen.cpp
  llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp


Index: llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -299,7 +299,8 @@
 
 void AMDGPUAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
   if (GV->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS) {
-    if (GV->hasInitializer() && !isa<UndefValue>(GV->getInitializer())) {
+    if (GV->hasInitializer() && !(isa<UndefValue>(GV->getInitializer()) ||
+                                  isa<PoisonValue>(GV->getInitializer()))) {
       OutContext.reportError({},
                              Twine(GV->getName()) +
                                  ": unsupported initializer for address space");
Index: clang/test/OpenMP/target_team_variable_codegen.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/target_team_variable_codegen.cpp
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals --prefix-filecheck-ir-name _ --global-value-regex "llvm.compiler.used" "_[0-9a-zA-Z]+A[0-9a-zA-Z]+pi[0-9a-zA-Z]+" "_[0-9a-zA-Z]+anotherPi" --version 2
+// REQUIRES: amdgpu-registered-target
+
+
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host-amd.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-target-debug -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host-amd.bc -o - | FileCheck %s --check-prefix=CHECK-AMD
+
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host-nvidia.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-unknown-unknown -emit-llvm %s -fopenmp-target-debug -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host-nvidia.bc -o - | FileCheck %s --check-prefix=CHECK-NVIDIA
+
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+typedef enum omp_allocator_handle_t {
+  omp_null_allocator = 0,
+  omp_default_mem_alloc = 1,
+  omp_large_cap_mem_alloc = 2,
+  omp_const_mem_alloc = 3,
+  omp_high_bw_mem_alloc = 4,
+  omp_low_lat_mem_alloc = 5,
+  omp_cgroup_mem_alloc = 6,
+  omp_pteam_mem_alloc = 7,
+  omp_thread_mem_alloc = 8,
+  KMP_ALLOCATOR_MAX_HANDLE = __UINTPTR_MAX__
+} omp_allocator_handle_t;
+
+//.
+// CHECK-AMD: @local_a = internal addrspace(3) global [10 x i32] poison, align 4
+//.
+// CHECK-NVIDIA: @local_a = internal addrspace(3) global [10 x i32] zeroinitializer, align 4
+//.
+int main()
+{
+	int N = 10000;
+	int *a = new int[N];
+#pragma omp target data map(tofrom:a[:N])
+	{
+#pragma omp target teams distribute parallel for
+    for(int i = 0; i < N; i++)
+    {
+      int local_a[10];
+#pragma omp allocate(local_a) allocator(omp_pteam_mem_alloc)
+      for(int j = 0; j < 10; j++)
+		    local_a[j] = a[(i + j) % N];
+      a[i] = local_a[0];
+    }
+	}
+  return a[17];
+}
+
+#endif
+//// NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+// CHECK-AMD: {{.*}}
+// CHECK-NVIDIA: {{.*}}
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -3351,7 +3351,9 @@
     llvm::Type *VarTy = CGF.ConvertTypeForMem(VD->getType());
     auto *GV = new llvm::GlobalVariable(
         CGM.getModule(), VarTy, /*isConstant=*/false,
-        llvm::GlobalValue::InternalLinkage, llvm::Constant::getNullValue(VarTy),
+        llvm::GlobalValue::InternalLinkage,
+        CGM.getTriple().isAMDGCN() ? llvm::PoisonValue::get(VarTy)
+                                   : llvm::Constant::getNullValue(VarTy),
         VD->getName(),
         /*InsertBefore=*/nullptr, llvm::GlobalValue::NotThreadLocal,
         CGM.getContext().getTargetAddressSpace(AS));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147572.510934.patch
Type: text/x-patch
Size: 4180 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230404/2fb574fa/attachment.bin>


More information about the cfe-commits mailing list