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

Leandro Lupori llvmlistbot at llvm.org
Mon Feb 5 09:38:47 PST 2024


================
@@ -0,0 +1,43 @@
+subroutine delayed_privatization()
+  integer :: var1
+  integer :: var2
+
+!$OMP PARALLEL FIRSTPRIVATE(var1, var2)
+  var1 = var1 + var2 + 2
+!$OMP END PARALLEL
+
+end subroutine
+
+! This is what flang emits with the PoC:
+! --------------------------------------
+!
+!func.func @_QPdelayed_privatization() {
+!  %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
+!  }
+!  return
+!}
+!
+!"omp.private"() <{function_type = (!fir.ref<i32>) -> !fir.ref<i32>, sym_name = "var1.privatizer"}> ({
----------------
luporl wrote:

I think the idea would be to look for the privatizer in the module, using the name that can be obtained from the type of the variable. Then a new privatizer would be created only when none exists for the given type.
Can this be done with `omp.private`?

It is done for the copy functions, used with copyprivate:
https://github.com/llvm/llvm-project/pull/80485/files#diff-63581fb5be230c4918a0d8196a02ff696759f3010a419339c56a21777fb8c634R1221

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


More information about the Mlir-commits mailing list