Skip to content

[flang][Semantics] Threadprivate symbols are ignored in presence of default clause #78282

Closed
@NimishMishra

Description

@NimishMishra

Current default clause lowering proceeds in two steps: (1) in the semantics phase, the symbols are modified to contain relevant flag associated with the default data sharing attribute on the region, and (2) in the lowering phase, the corresponding symbols are collected and lowering.

Step (1) of this process currently allows incorrect modification of the symbol that is threadprivate. Consider the example:

PROGRAM main
 COMMON /PLATQ_COMMON/      &
&  Px(8),Py(8),Pz(8)
!$OMP THREADPRIVATE (/PLATQ_COMMON/)

!$OMP PARALLEL DO DEFAULT(PRIVATE)
   DO I=1, 4
     PX(I) = 4
     CALL SUB1()
   ENDDO
!$OMP END PARALLEL DO
 CONTAINS
   SUBROUTINE SUB1()
     COMMON /PLATQ_COMMON/      &
    &  Px(8),Py(8),Pz(8)
    !$OMP THREADPRIVATE (/PLATQ_COMMON/)

      print *, PX
    END SUBROUTINE
END PROGRAM

Currently, LLVM flang does not treat PX as threadprivate when default clause is present:

omp.parallel {
      %24 = fir.alloca i32 {adapt.valuebyref, pinned}
      %25 = fir.declare %24 {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> !fir.ref<i32>
      omp.wsloop for  (%arg0) : i32 = (%c1_i32) to (%c4_i32) inclusive step (%c1_i32) {
        fir.store %arg0 to %25 : !fir.ref<i32>
        %26 = fir.load %25 : !fir.ref<i32>
        %27 = fir.convert %26 : (i32) -> i64
        %28 = fir.array_coor %13(%12) %27 : (!fir.ref<!fir.array<8xf32>>, !fir.shape<1>, i64) -> !fir.ref<f32>
        fir.store %cst to %28 : !fir.ref<f32>
        fir.call @_QFPsub1() fastmath<contract> : () -> ()
        omp.yield
      }
      omp.terminator
    }

However, should default clause be removed, then correct privatization follows:

omp.parallel {
      %24 = fir.alloca i32 {adapt.valuebyref, pinned}
      %25 = fir.declare %24 {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> !fir.ref<i32>
      %26 = omp.threadprivate %2 : !fir.ref<!fir.array<96xi8>> -> !fir.ref<!fir.array<96xi8>>
      %27 = fir.convert %26 : (!fir.ref<!fir.array<96xi8>>) -> !fir.ref<!fir.array<?xi8>>
      %28 = fir.coordinate_of %27, %c0 : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
      %29 = fir.convert %28 : (!fir.ref<i8>) -> !fir.ref<!fir.array<8xf32>>
      %30 = fir.shape %c8 : (index) -> !fir.shape<1>
      %31 = fir.declare %29(%30) {uniq_name = "_QFEpx"} : (!fir.ref<!fir.array<8xf32>>, !fir.shape<1>) -> !fir.ref<!fir.array<8xf32>>
      omp.wsloop for  (%arg0) : i32 = (%c1_i32) to (%c4_i32) inclusive step (%c1_i32) {
        fir.store %arg0 to %25 : !fir.ref<i32>
        %32 = fir.load %25 : !fir.ref<i32>
        %33 = fir.convert %32 : (i32) -> i64
        %34 = fir.array_coor %31(%30) %33 : (!fir.ref<!fir.array<8xf32>>, !fir.shape<1>, i64) -> !fir.ref<f32>
        fir.store %cst to %34 : !fir.ref<f32>
        fir.call @_QFPsub1() fastmath<contract> : () -> ()
        omp.yield
      }
      omp.terminator
    }

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviorflang:frontend

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions