[flang-commits] [flang] [OpenMP] Add PointerAssociateScalar to Cray Pointer used in the DSA (PR #133232)

Michael Klemm via flang-commits flang-commits at lists.llvm.org
Fri Mar 28 22:58:29 PDT 2025


================
@@ -0,0 +1,180 @@
+! Test lowering of Cray pointee references.
+! RUN: flang -fc1 -emit-hlfir -fopenmp %s -o - 2>&1 | FileCheck %s
+
+! CHECK-LABEL: func.func @_QQmain() attributes {fir.bindc_name = "test_cray_pointers_02"}
+program test_cray_pointers_02
+    implicit none
+
+    ! CHECK:   fir.call @_QPnone_shared() fastmath<contract> : () -> ()
+    ! CHECK:   fir.call @_QPnone_private() fastmath<contract> : () -> ()
+    ! CHECK:   fir.call @_QPnone_firstprivate() fastmath<contract> : () -> ()
+    ! CHECK:   fir.call @_QPprivate_shared() fastmath<contract> : () -> ()
+    ! CHECK:   fir.call @_QPprivate_firstprivate() fastmath<contract> : () -> ()
+    ! CHECK:   fir.call @_QPfirstprivate_shared() fastmath<contract> : () -> ()
+    ! CHECK:   fir.call @_QPfirstprivate_private() fastmath<contract> : () -> ()
+    call none_shared()
+    call none_private()
+    call none_firstprivate()
+    call private_shared()
+    call private_firstprivate()
+    call firstprivate_shared()
+    call firstprivate_private()
+    ! CHECK:   return
+    ! CHECK: }
+end program test_cray_pointers_02
+
+! CHECK-LABEL: func.func @_QPnone_shared()
+subroutine none_shared()
+    implicit none
+    integer var(*)
+    pointer(ivar,var)
+    integer pointee(8)
+
+    pointee(1) = 42
+    ivar = loc(pointee)
+
+    !$omp parallel num_threads(1) default(none) shared(ivar)
+        ! CHECK: omp.parallel
+        ! CHECK:   fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
+        ! CHECK:   {{.*}} = arith.divsi
+        ! CHECK:   fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
+        ! CHECK:   fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
+        var(1) = var(1) / 2
+        print '(A24,I6)', 'none_shared', var(1)
+    !$omp end parallel
+    ! CHECK: return
+end subroutine
+
+! CHECK-LABEL: func.func @_QPnone_private()
+subroutine none_private()
+    implicit none
+    integer var(*)
+    pointer(ivar,var)
+    integer pointee(8)
+
+    pointee(1) = 42
+    ivar = loc(pointee)
+
+    !$omp parallel num_threads(1) default(none) private(ivar) shared(pointee)
+        ! CHECK: omp.parallel
+        ivar = loc(pointee)
+        ! CHECK:   fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
+        ! CHECK:   {{.*}} = arith.addi
+        ! CHECK:   fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
+        ! CHECK:   fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
+        var(1) = var(1) + 2
+    print '(A24,I6)', 'none_private', var(1)
----------------
mjklemm wrote:

```suggestion
        print '(A24,I6)', 'none_private', var(1)
```

https://github.com/llvm/llvm-project/pull/133232


More information about the flang-commits mailing list