[flang-commits] [flang] [mlir] [WIP] Delayed privatization. (PR #79862)

Kareem Ergawy via flang-commits flang-commits at lists.llvm.org
Wed Jan 31 03:14:18 PST 2024


================
@@ -0,0 +1,38 @@
+// RUN: fir-opt -verify-diagnostics %s | fir-opt | FileCheck %s
+
+// CHECK-LABEL: _QPprivate_clause
+func.func @_QPprivate_clause() {
+  %0 = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFprivate_clause_allocatableEx"}
+  %1 = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFprivate_clause_allocatableEy"}
+
+  // CHECK: omp.parallel private(@x.privatizer %0 -> %arg0, @y.privatizer %1 -> %arg1 : !fir.ref<i32>, !fir.ref<i32>)
+  omp.parallel private(@x.privatizer %0 -> %arg0, @y.privatizer %1 -> %arg1 : !fir.ref<i32>, !fir.ref<i32>) {
----------------
ergawy wrote:

>  The operands in `private_vars` should already be block argument AFAICT.

Not really. Value operands to an op do not translate automatically to arguments to its entry region. Please let me know if I misunderstood your comment :).

> Do you really need to add a block argument?

However, I agree with you that we probably do not need a block argument. We can simply keep references to the host region inside the OMP region and when we inline the privatizer later, we can inline and replace all references to the host value with the yielded value from the privatizer.

So the op would look like this before inlining:
```
    %0 = fir.alloca i32 {bindc_name = "var1", uniq_name = "_QFdelayed_privatizationEvar1"}
    %1 = fir.alloca i32 {bindc_name = "var2", uniq_name = "_QFdelayed_privatizationEvar2"}
    omp.parallel private(@var1.privatizer %0, @var2.privatizer %1 : !fir.ref<i32>, !fir.ref<i32>) {
      %2 = fir.load %0 : !fir.ref<i32>
      %3 = fir.load %1 : !fir.ref<i32>
      %4 = arith.addi %2, %3 : i32
      %c2_i32 = arith.constant 2 : i32
      %5 = arith.addi %4, %c2_i32 : i32
      fir.store %5 to %0 : !fir.ref<i32>
      omp.terminator
    }
```

@kiranchandramohan what do you think? Can we go with the above?

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


More information about the flang-commits mailing list