[flang-commits] [flang] [flang][OpenMP] Fix construct privatization in default clause (PR #72510)

via flang-commits flang-commits at lists.llvm.org
Sun Feb 4 10:46:30 PST 2024


================
@@ -426,14 +425,10 @@ void DataSharingProcessor::collectSymbols(
                              /*collectSymbols=*/true,
                              /*collectHostAssociatedSymbols=*/true);
   for (Fortran::lower::pft::Evaluation &e : eval.getNestedEvaluations()) {
-    if (e.hasNestedEvaluations())
+    if (e.hasNestedEvaluations() && !e.isConstruct())
----------------
NimishMishra wrote:

@kiranchandramohan I checked for the use-cases mentioned. The lowering seems to be okay. Should I add these combinations in the tests for default clause?

**outer(default=private), inner(default=private)**

Consider the following example:

```
integer :: j
!$omp parallel default(private)
      j = 10
      !$omp parallel default(firstprivate)
                 j = j + 5
      !$omp end parallel
!$omp end parallel
```

This lowers as:

```
%0 = fir.alloca i32 ......
%1:2 = hlfir.declare %0 .....
omp.parallel {
       %2 = fir.alloca i32 .....      // privatized j
        %3:2 = hlfir.declare %2
        %c = arith.constant 10 
        hlfir.assign %c to %3#0 ....
        omp.parallel {
                 %4 = fir.alloca i32 ....
                 %5:2 = hlfir.declare %4 ....
                 %6 = fir.load %3#0 .....
                 hlfir.assign %6 to %5#0 ......
        }
}
```

**outer(default=private), inner(default=shared)**

Example:

```
integer :: j
!$omp parallel default(private)
      j = 10
      !$omp parallel
                 j = j + 5
      !$omp end parallel
!$omp end parallel
```

This lowers as:

```
%0 = fir.alloca i32 ......
%1:2 = hlfir.declare %0 .....
omp.parallel {
       %2 = fir.alloca i32 .....      // privatized j
        %3:2 = hlfir.declare %2
        %c = arith.constant 10 
        hlfir.assign %c to %3#0 ....
        omp.parallel {
                 %4 = fir.load %3#0 .....
                 // add 5 to %4 and store in %5
                 hlfir.assign %5 to %3#0 ....
        }
}
```

**outer(default=shared), inner(default=private)**

Example:

```
integer :: j
!$omp parallel
      j = 10
      !$omp parallel default(private)
                 j = j + 5
      !$omp end parallel
!$omp end parallel
```

This lowers as:

```
%0 = fir.alloca i32 ......
%1:2 = hlfir.declare %0 .....
omp.parallel {
        %c = arith.constant 10 
        hlfir.assign %c to %3#0 ....
        omp.parallel {
                 %2 = fir.alloca ....
                 %3:2 = hlfir.declare %2 ....
                 %4 = fir.load %3#0 .....
                 // add 5 to %4 and store in %5
                 hlfir.assign %5 to %3#0 ....
        }
}
```

And should be consider `firstprivate` in the inner parallel:

```
%0 = fir.alloca i32 ......
%1:2 = hlfir.declare %0 .....
omp.parallel {
        %c = arith.constant 10 
        hlfir.assign %c to %3#0 ....
        omp.parallel {
                 %2 = fir.alloca ....
                 %3:2 = hlfir.declare %2 ....
                 %4 = fir.load %1#0 ....
                 hlfir.assign %4 to %3#0 .....
                 %5 = fir.load %3#0 .....
                 // add 5 to %4 and store in %6
                 hlfir.assign %6 to %3#0 ....
        }
}
```

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


More information about the flang-commits mailing list