[all-commits] [llvm/llvm-project] aeaafc: [mlir][OpenMP][flang] make private variable alloca...

Tom Eccles via All-commits all-commits at lists.llvm.org
Fri Jan 31 01:35:48 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: aeaafce4644788963d9823067e46b50266af4f05
      https://github.com/llvm/llvm-project/commit/aeaafce4644788963d9823067e46b50266af4f05
  Author: Tom Eccles <tom.eccles at arm.com>
  Date:   2025-01-31 (Fri, 31 Jan 2025)

  Changed paths:
    M flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
    M flang/lib/Lower/OpenMP/DataSharingProcessor.h
    M flang/lib/Lower/OpenMP/PrivateReductionUtils.cpp
    M flang/lib/Lower/OpenMP/PrivateReductionUtils.h
    M flang/lib/Lower/OpenMP/ReductionProcessor.cpp
    M flang/lib/Lower/OpenMP/ReductionProcessor.h
    M flang/lib/Optimizer/CodeGen/CodeGenOpenMP.cpp
    M flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp
    M flang/test/Analysis/AliasAnalysis/alias-analysis-omp-private-allocatable.mlir
    M flang/test/Analysis/AliasAnalysis/alias-analysis-omp-teams-distribute-private-ptr.mlir
    M flang/test/Analysis/AliasAnalysis/alias-analysis-omp-teams-distribute-private.mlir
    M flang/test/Fir/boxproc-openmp.fir
    M flang/test/HLFIR/opt-variable-assign-omp.fir
    M flang/test/Integration/OpenMP/copyprivate.f90
    M flang/test/Integration/OpenMP/parallel-private-reduction-worstcase.f90
    M flang/test/Integration/OpenMP/private-global.f90
    M flang/test/Lower/OpenMP/DelayedPrivatization/distribute-standalone-private.f90
    M flang/test/Lower/OpenMP/DelayedPrivatization/equivalence.f90
    M flang/test/Lower/OpenMP/DelayedPrivatization/target-private-allocatable.f90
    M flang/test/Lower/OpenMP/DelayedPrivatization/target-private-multiple-variables.f90
    M flang/test/Lower/OpenMP/DelayedPrivatization/target-private-simple.f90
    M flang/test/Lower/OpenMP/DelayedPrivatization/wsloop.f90
    M flang/test/Lower/OpenMP/cfg-conversion-omp.private.f90
    M flang/test/Lower/OpenMP/copyprivate.f90
    M flang/test/Lower/OpenMP/default-clause-byref.f90
    M flang/test/Lower/OpenMP/delayed-privatization-allocatable-array.f90
    M flang/test/Lower/OpenMP/delayed-privatization-allocatable-firstprivate.f90
    M flang/test/Lower/OpenMP/delayed-privatization-allocatable-private.f90
    M flang/test/Lower/OpenMP/delayed-privatization-array.f90
    M flang/test/Lower/OpenMP/delayed-privatization-character-array.f90
    M flang/test/Lower/OpenMP/delayed-privatization-character.f90
    M flang/test/Lower/OpenMP/delayed-privatization-default-init.f90
    M flang/test/Lower/OpenMP/delayed-privatization-firstprivate.f90
    A flang/test/Lower/OpenMP/delayed-privatization-lastprivate-of-private.f90
    M flang/test/Lower/OpenMP/delayed-privatization-pointer.f90
    M flang/test/Lower/OpenMP/delayed-privatization-private-firstprivate.f90
    M flang/test/Lower/OpenMP/delayed-privatization-private.f90
    M flang/test/Lower/OpenMP/delayed-privatization-reduction-byref.f90
    M flang/test/Lower/OpenMP/delayed-privatization-reduction.f90
    M flang/test/Lower/OpenMP/derived-type-allocatable.f90
    M flang/test/Lower/OpenMP/firstprivate-alloc-comp.f90
    M flang/test/Lower/OpenMP/implicit-dsa.f90
    M flang/test/Lower/OpenMP/loop-directive.f90
    M flang/test/Lower/OpenMP/parallel-firstprivate-clause-scalar.f90
    M flang/test/Lower/OpenMP/parallel-private-clause-fixes.f90
    M flang/test/Lower/OpenMP/parallel-private-clause-str.f90
    M flang/test/Lower/OpenMP/parallel-private-clause.f90
    M flang/test/Lower/OpenMP/parallel-reduction-allocatable-array.f90
    M flang/test/Lower/OpenMP/parallel-reduction-pointer-array.f90
    A flang/test/Lower/OpenMP/pointer-to-array.f90
    M flang/test/Lower/OpenMP/private-commonblock.f90
    M flang/test/Lower/OpenMP/private-derived-type.f90
    M flang/test/Lower/OpenMP/same_var_first_lastprivate.f90
    M flang/test/Lower/OpenMP/simd.f90
    M flang/test/Lower/OpenMP/task2.f90
    M flang/test/Lower/OpenMP/wsloop-reduction-allocatable-array-minmax.f90
    M flang/test/Transforms/generic-loop-rewriting.mlir
    M flang/test/Transforms/omp-maps-for-privatized-symbols.fir
    M mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
    M mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp
    M mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
    M mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
    M mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
    M mlir/test/Dialect/OpenMP/invalid.mlir
    M mlir/test/Dialect/OpenMP/ops.mlir
    M mlir/test/Target/LLVMIR/openmp-firstprivate.mlir
    M mlir/test/Target/LLVMIR/openmp-llvm.mlir
    M mlir/test/Target/LLVMIR/openmp-omp.private-dealloc.mlir
    M mlir/test/Target/LLVMIR/openmp-private.mlir
    M mlir/test/Target/LLVMIR/openmp-simd-private.mlir
    M mlir/test/Target/LLVMIR/openmp-target-multiple-private.mlir
    M mlir/test/Target/LLVMIR/openmp-target-private-allocatable.mlir
    M mlir/test/Target/LLVMIR/openmp-target-private.mlir
    M mlir/test/Target/LLVMIR/openmp-target-simd-on_device.mlir
    M mlir/test/Target/LLVMIR/openmp-todo.mlir
    M mlir/test/Target/LLVMIR/openmp-wsloop-private-cond_br.mlir
    M mlir/test/Target/LLVMIR/openmp-wsloop-private.mlir

  Log Message:
  -----------
  [mlir][OpenMP][flang] make private variable allocation implicit in omp.private (#124019)

The intention of this work is to give MLIR->LLVMIR conversion freedom to
control how the private variable is allocated so that it can be
allocated on the stack in ordinary cases or as part of a structure used
to give closure context for tasks which might outlive the current stack
frame. See RFC:

https://discourse.llvm.org/t/rfc-openmp-supporting-delayed-task-execution-with-firstprivate-variables/83084

For example, a privatizer for an integer used to look like
```mlir
  omp.private {type = private} @x.privatizer : !fir.ref<i32> alloc {
  ^bb0(%arg0: !fir.ref<i32>):
    %0 = ... allocate proper memory for the private clone ...
    omp.yield(%0 : !fir.ref<i32>)
  }
```

After this change, allocation become implicit in the operation:
```mlir
  omp.private {type = private} @x.privatizer : i32
```

For more complex types that require initialization after allocation, an
init region can be used:
``` mlir
  omp.private {type = private} @x.privatizer : !some.type init {
  ^bb0(%arg0: !some.pointer<!some.type>, %arg1: !some.pointer<!some.type>):
    // initialize %arg1, using %arg0 as a mold for allocations
    omp.yield(%arg1 : !some.pointer<!some.type>)
  } dealloc {
    ^bb0(%arg0: !some.pointer<!some.type>):
    ... deallocate memory allocated by the init region ...
    omp.yield
  }
```

This patch lays the groundwork for delayed task execution but is not
enough on its own.

After this patch all gfortran tests which previously passed still pass.
There
are the following changes to the Fujitsu test suite:
- 0380_0009 and 0435_0009 are fixed
- 0688_0041 now fails at runtime. This patch is testing firstprivate
variables with tasks. Previously we got lucky with the undefined
behavior and won the race. After these changes we no longer get lucky.
This patch lays the groundwork for a proper fix for this issue.

In flang the lowering re-uses the existing lowering used for reduction
init and dealloc regions.

In flang, before this patch we hit a TODO with the same wording when
generating the copy region for firstprivate polymorphic variables. After
this patch the box-like fir.class is passed by reference into the copy
region, leading to a different path that didn't hit that old TODO but
the generated code still didn't work so I added a new TODO in
DataSharingProcessor.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list