9 Commits

Author SHA1 Message Date
Leandro Lupori
ef56f4b5a0
[flang][OpenMP] Fix reduction of arrays with non-default lower bounds (#132228)
Using LoopNest's indices with ShapeShifts that have non-default
lower bounds results in accesses to incorrect array elements.
To avoid having to adjust each index, a ShapeShift with default
lower bounds can be used instead.

Fixes #131751
2025-03-24 09:48:41 -03:00
Tom Eccles
747588dc64
[flang][Lower][OpenMP] Don't read moldarg for static sized array (#127838)
This should further reduce the number of spurious barriers
2025-02-20 10:31:34 +00:00
Tom Eccles
22ef210100
Revert "[flang][Lower][OpenMP] Don't read moldarg for static sized array" (#127596)
Reverts llvm/llvm-project#125901

Revert until I have fixed bot failures
2025-02-18 09:12:36 +00:00
Tom Eccles
88dd372d67
[flang][Lower][OpenMP] Don't read moldarg for static sized array (#125901)
This should further reduce the number of spurious barriers
2025-02-18 09:02:29 +00:00
Kareem Ergawy
32faf43878
[flang][OpenMP] Handle fixed length charaters in delayed privatization (#126704)
We currently handle sequences of fixed-length arrays properly by **not**
emitting length parameters for `embox` ops inside the `omp.private` op.
However, we do not handle the scalar case. This PR extends
`getLengthParameters` defined in `PrivateReductionUtils.cpp` to handle
such cases.

Fixes issue reported in #125732.
2025-02-12 11:04:26 +01:00
Tom Eccles
d5c60724be
[flang][Lower][OpenMP] try to avoid using init mold argument (#125900)
Unfortunately we still have a lot of cases like
!fir.box<!fir.array<10xi32>> where we read dimensions from the mold in
case there are non-default lower bounds stored inside the box. I will
address this in the next patch.
2025-02-06 14:27:41 +00:00
Tom Eccles
4daf307099
[flang][Lower][OpenMP][NFC] tidy up PrivateReductionUtils (#125867)
First part of a series of patches to improve private/reduction init and
cleanup region generation.

This commit is NFC. I factored out processing for each datatype into its
own method so that it is easier to keep track of what is being handled
where (I found the old gigantic init region generation function
difficult to navigate). The methods all share context in a helper class
to avoid having to pass a very large number of arguments.

I also removed the conflation between the mold argument and the mold
argument after loading. This should make it easier to avoid generating
dead uses of the mold argument in a later non-nfc patch.
2025-02-06 10:25:15 +00:00
Tom Eccles
aeaafce464
[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.
2025-01-31 09:35:26 +00:00
Tom Eccles
8557a57c4b
[flang][OpenMP][NFC] Move reduction init and cleanup region gen to helper (#120761)
This will allow code sharing between reduction and privatization after
my (still WIP) changes to `omp.private` to use an `alloc` region similar
to the one used for reduction declarations.
2025-01-07 16:37:18 +00:00