212 Commits

Author SHA1 Message Date
Slava Zakharin
d0e8f3321e
[flang][openacc] Fixed private/reduction for combined constructs. (#69417)
According to OpenACC 3.2 2.11, private or reduction clause
on the combined construct is treated as if it appeared
on the loop construct.
2023-10-18 08:10:50 -07:00
Valentin Clement (バレンタイン クレメン)
d9568bd4aa
[flang][openacc] Support array with dynamic extents in firstprivate recipe (#69026)
Add lowering support for array with dynamic extents in the firstprivate
recipe. Generalize the lowering so static shaped arrays and array with
dynamic extents use the same path.

Some cleaning code is taken from #68836 that is not landed yet.
2023-10-16 12:51:01 -07:00
Valentin Clement (バレンタイン クレメン)
f74b85c678
[flang][openacc] Support array with dynamic extents in reduction recipe (#68829)
Add support for array with dynamic extents in lowering of the reduction
recipe.
2023-10-16 12:50:39 -07:00
Valentin Clement (バレンタイン クレメン)
468d3b1b78
[flang][openacc][NFC] Simplify lowering of recipe (#68836)
Refactor some of the lowering in the reduction and firstprivate recipe
to avoid duplicated code.
2023-10-16 09:35:50 -07:00
Valentin Clement
acbb260a48
[flang][openacc][NFC] Fix TODO messages 2023-10-10 10:10:15 -07:00
Valentin Clement (バレンタイン クレメン)
e2f493bed3
[flang][openacc] Support assumed shape array in firstprivate recipe (#68640)
Add support for assumed shape arrays in lowering of the copy region of
the firstprivate recipe. Information is passed in block arguments as it
is done for the reduction recipe.
2023-10-10 09:55:55 -07:00
Valentin Clement (バレンタイン クレメン)
c8b5f4c07e
[flang][openacc] Support array with dynamic extent in private recipe (#68624)
Add lowering support for array with dynamic extents for private recipe.
The extents are passed as block arguments and used in the alloca
operation. The shape also used this information for the hlfir.declare
operation.
2023-10-09 17:43:03 -07:00
Valentin Clement
470b65270b
[flang][openacc] Support allocatable and pointer array in private recipe
Add support for pointer and allocatable arrays in private clause.
2023-10-09 10:20:58 -07:00
Valentin Clement
2615de5867
Revert "[flang][openacc] Support allocatable and pointer array in private recipe (#68422)"
This reverts commit e85cdb94cc1f1cf3f61de65ae9f72348d0d52b80.

This fails some buildbots
2023-10-09 09:33:26 -07:00
Valentin Clement (バレンタイン クレメン)
e85cdb94cc
[flang][openacc] Support allocatable and pointer array in private recipe (#68422)
Add support for pointer and allocatable arrays in private clause.
2023-10-09 09:22:43 -07:00
Valentin Clement (バレンタイン クレメン)
1556ddf255
[flang][openacc] Do not generate duplicate routine op (#68348)
This patch updates the lowering of OpenACC routine directive to avoid
creating duplicate acc.routine operations when all the clauses are
identical. If clauses differ an error is raised.
2023-10-06 08:10:12 -07:00
Valentin Clement (バレンタイン クレメン)
964a252202
[flang][openacc] Add support for allocatable and pointer arrays in reduction (#68261)
This patch adds support for allocatable and pointer arrays in the
reduction recipe lowering.
2023-10-05 13:05:43 -07:00
Valentin Clement (バレンタイン クレメン)
4f98fb2e93
[mlir][openacc][NFC] Remove useless OptionalAttr with UnitAttr (#68337)
`UnitAttr` exits or not so adding `OptionalAttr` around it is not
necessary. This patch cleanup this for the `RoutineOp`
2023-10-05 10:45:04 -07:00
Valentin Clement (バレンタイン クレメン)
438a6ef277
[flang][openacc] Use the array section for assumed shape array reduction (#68147)
Use the bounds information in the reduction recipe for assumed shape
arrays.
2023-10-03 13:38:02 -07:00
Valentin Clement (バレンタイン クレメン)
e0cd781f3b
[flang][openacc] Fix getBoundsString for reduction recipe name (#68146)
`getBoundsString` is used to generate the reduction recipe names when an
array section is provided. The lowerbound and upperbound were swapped.
This patch fixes it.
2023-10-03 13:08:00 -07:00
Jie Fu
57c639deb4 [flang][openacc] Fix -Wunused-variable in OpenACC.cpp (NFC)
/llvm-project/flang/lib/Lower/OpenACC.cpp:940:16: error: unused variable 'nbRangeArgs' [-Werror,-Wunused-variable]
      unsigned nbRangeArgs =
               ^
1 error generated.
2023-10-03 09:14:32 +08:00
Valentin Clement (バレンタイン クレメン)
185eab1974
[flang][openacc] Keep constant bounds in reduction recipe when it is all constants (#67827)
Following #67719, propagate the constant bounds in the combiner region
when all bounds are constant. Otherwise, bounds information are
propagated as block arguments as defined in #67719.
2023-10-02 17:59:41 -07:00
Kazu Hirata
aa5a1b267a [flang] Fix a typo 2023-09-28 14:28:19 -07:00
Kazu Hirata
33f5087e1b [flang] Fix an unused variable warning
This patch fixes:

  flang/lib/Lower/OpenACC.cpp:876:14: error: unused variable
  'nbRangeArgs' [-Werror,-Wunused-variable]
2023-09-28 14:25:54 -07:00
Valentin Clement (バレンタイン クレメン)
d28a782542
[flang][openacc] Use bounds information in reduction recipe combiner (#67719)
This patch makes use of the bounds in the combiner region for known
shape arrays. Until know the combiner region was iterating over the
whole array.
Lowerbound, upperbound and step are passed as block arguments after the
two values.

A follow up patch will make use of this information for the assumed
shape arrays as well.
2023-09-28 13:11:06 -07:00
Valentin Clement (バレンタイン クレメン)
49f1232ea1
[flang][openacc] Support assumed shape arrays in private recipe (#67701)
This patch adds correct support for the assumed shape arrays in the
privatization recipes.
This follows the same IR generation than in #67610.
2023-09-28 12:40:51 -07:00
Valentin Clement (バレンタイン クレメン)
ef1eb502e0
[flang][openacc] Support assumed shape arrays in reduction (#67610)
Assumed shape array are using descriptor and must be handled differently
than known shape arrays. This patch adds support to generate the `init`
and `combiner` region for the reduction recipe operation with assumed
shape array by using the descriptor and the HLFIR lowering path.

`createTempFromMold` function is moved from
`flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp` to
`flang/include/flang/Optimizer/Builder/HLFIRTools.h` to be reused to
create the private copy.
2023-09-28 08:36:19 -07:00
Valentin Clement (バレンタイン クレメン)
b163e52b78
[flang][openacc][hlfir] Add declare op in reduction recipe (#67484)
Same change than #67368 but for the reduction recipe.
2023-09-26 13:36:57 -07:00
Valentin Clement (バレンタイン クレメン)
4da01a636b
[flang][openacc][hlfir] Add declare op in private recipe (#67368)
Following #66099, the generation of private (and firstprivate) recipe
needs to add a declare op. This patch adds the declare op for the case
currently supported.

This will fix issue #66105.
2023-09-26 10:32:47 -07:00
Andrew Gozillon
8fde6f41a0 [Flang][OpenMP] Add lowering from PFT to new MapEntry and Bounds operations and tie them to relevant Target operations
This patch builds on top of a prior patch in review which adds a new map
and bounds operation by modifying the OpenMP PFT lowering to support
these operations and generate them from the PFT.

A significant amount of the support for the Bounds operation is borrowed
from OpenACC's own current implementation and lowering, just ported
over to OpenMP.

The patch also adds very preliminary/initial support for lowering to
a new Capture attribute, which is stored on the new Map Operation,
which helps the later lowering from OpenMP -> LLVM IR by indicating
how a map argument should be handled. This capture type will
influence how a map argument is accessed on device and passed by
the host (different load/store handling etc.). It is reflective of a
similar piece of information stored in the Clang AST which performs a
similar role.

As well as some minor adjustments to how the map type (map bitshift
which dictates to the runtime how it should handle an argument) is
generated to further support more use-cases for future patches that
build on this work.

Finally it adds the map entry operation creation and tying it to the relevant
target operations as well as the addition of some new tests and alteration
of previous tests to support the new changes.

Depends on D158732

reviewers: kiranchandramohan, TIFitis, clementval, razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158734
2023-09-19 08:26:46 -05:00
Valentin Clement (バレンタイン クレメン)
b171849afe
[flang][openacc] Use OpenACC terminator instead of fir.unreachable after Stop stmt (#66325)
This follow an update made on OpenMP https://reviews.llvm.org/D129969
and was not possible on OpenACC until the unstructured construct was
supported.
2023-09-13 22:28:02 -07:00
Valentin Clement (バレンタイン クレメン)
b1341e2863
[flang][openacc] Fix unstructured code in OpenACC region ops (#66284)
For unstructured construct, the blocks are created in advance inside the
function body. This causes issues when the unstructured construct is
inside an OpenACC region operations. This patch adds the same fix than
OpenMP lowering and re-create the blocks inside the op region.

Initial OpenMP fix: 29f167abcf7d871d17dd3f38f361916de1a12470
2023-09-13 20:49:54 -07:00
Razvan Lupusoru
e070ea47a9
[flang][openacc] Enable lowering support for OpenACC atomic operations (#65776)
Since the OpenACC atomics specification is a subset of OpenMP atomics,
the same lowering implementation can be used. This change extracts out
the necessary pieces from the OpenMP lowering and puts them in a shared
spot. The shared spot is a header file so that each implementation can
template specialize directly.

After putting the OpenMP implementation in a common spot, the following
changes were needed to make it work for OpenACC:
* Ensure parsing works correctly by avoiding hardcoded offsets.
* Templatize based on atomic type.
* The checking whether it is OpenMP or OpenACC is done by checking for
OmpAtomicClauseList (OpenACC does not implement this so we just
templatize with void). It was preferable to check this instead of atomic
type because in some cases, like atomic capture, the read/write/update
implementations are called - and we want compile time evaluation of
these conditional parts.
* The memory order and hint are used only for OpenMP.
* Generate acc dialect operations instead of omp dialect operations.
2023-09-11 13:58:10 -07:00
Valentin Clement (バレンタイン クレメン)
8bc676c2ec
[flang][openacc] Lower acc cache directive (#65673)
The cache directive is attached directly to the acc.loop operation when
the directive appears in the loop. When it appears before a loop, the
OpenACCCacheConstruct is saved and attached when the acc.loop is
created.

Directive that cannot be attached to a loop are silently discarded. 

Depends on #65521
2023-09-11 13:38:21 -07:00
Valentin Clement (バレンタイン クレメン)
996171a412
[mlir][openacc] Model acc cache directive as data entry operands on acc.loop (#65521)
The `cache` directive may appear at the top of (inside of) a loop. It
specifies array elements or subarrays that should be fetched into the
highest level of the cache for the body of the loop.

The `cache` directive is modeled as a data entry operands attached to
the acc.loop operation.
2023-09-11 13:38:03 -07:00
Valentin Clement (バレンタイン クレメン)
20f4a5a313
[flang][openacc][NFC] Clean up lowering api (#65678)
Remove unused argument `pft::Evaluation` from higher level lowering API.
2023-09-07 14:54:38 -07:00
Valentin Clement
e8824e05e3
[flang][openacc] Relax required clauses on acc data as portability warning
Some compilers accept `!$acc data` without any clauses. For portability
reason, this patch relaxes the strict error to a simple portability warning.

Reviewed By: razvanlupusoru, vzakhari

Differential Revision: https://reviews.llvm.org/D159019
2023-08-29 14:57:50 -07:00
Valentin Clement
d77ae428e0
Revert "[compiler-rt] Use just built libatomic if available"
This reverts commit 02fa9fc018db5b757a4ce129d85d64efefc8645c.

Commit message and content does not match. Revert to commit with
a proper commit message.
2023-08-29 14:54:33 -07:00
Alex Brachet
02fa9fc018
[compiler-rt] Use just built libatomic if available
Use libclang_rt.atomic.so instead of the libatomic installed
on the system if it is available.

Differential Revision: https://reviews.llvm.org/D151680
2023-08-29 14:53:01 -07:00
Valentin Clement
52683899fc
[flang][openacc] Fix crash with array section in acc declare in function
getSymbolFromAccObject was hitting the fatal error when
trying to retrieve the symbol on array section

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158881
2023-08-28 08:59:04 -07:00
Valentin Clement
2db0acb279
[flang][NFC] Use the constexpr instead of hardcoded -1 2023-08-24 09:40:38 -07:00
Valentin Clement
9d7c7f6983
[flang][openacc] Lower acc set directive
Lower the acc set directive to the acc.set op.

Depends on D158554

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158555
2023-08-23 14:08:39 -07:00
Valentin Clement
22209a673e
[flang][openacc] Keep routine information in the module file
This patch propagates the acc routine information
to the module file so they can be used by the caller.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158541
2023-08-23 08:56:55 -07:00
Valentin Clement
4d04baeca5
[flang][openacc] Lower acc declare to the new acc.declare function
Lower the acc delcare directive in function/subroutine
to the newly introduced acc.declare operation. Only a single
acc.declare operation is procduced in a function or subroutine
so they don't end up nested.

Depends on D158314

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158315
2023-08-21 12:39:02 -07:00
Valentin Clement
69a6bd5f05
[flang][openacc] Lower acc routine with function name
The routine directive can appear in the specification part of
a subroutine, function or module and therefore appear before the
function or subroutine is lowered. We keep track of the created
routine info attribute and attach them to the function at the end
of the lowering if the directive appeared before the function was
lowered.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158204
2023-08-17 14:25:26 -07:00
Slava Zakharin
de2be3e469 [flang][hlfir] Use the HLFIR base of hlfir.declare if possible.
This patch makes use of the HLFIR box produced for hlfir.declare
in place of the FIR box (the memref of hlfir.declare) when possible.

This makes the representation a little bit more clear, because
all accesses are made via a single box.
This reduces the life range of the original box, because the new
temporary box produced by embox/rebox is used from now.
Apparently, this works around some issues in the current HLFIR codegen,
for example, look at the LIT tests changes around fir.array_coor
produced by hlfir.designate codegen - using the FIR box for fir.array_coor
might result in using incorrect lbounds.
Apparently, this change enables more intrinsics simplifications
because the SimplifyIntrinsicsPass looks for explicit embox/rebox
in findBoxDef() to decide whether to apply the optimization.
This change also provides better association of the base addresses
referenced by OpenACC clauses with the corresponding boxes
that might be used explicitly in OpenACC regions (e.g. for reading
the lbounds).

Reviewed By: razvanlupusoru, clementval

Differential Revision: https://reviews.llvm.org/D158119
2023-08-16 17:56:23 -07:00
Valentin Clement
b1d0f5f7cd
[flang][openacc] Lower the bind clause on acc routine
Lower the bind clause to the corresponding attribute

Depends on D158120

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158121
2023-08-16 15:20:32 -07:00
Valentin Clement
939bdaec18
[flang][openacc] Attach attribute only when there is an exit operation
Not all declare clause have an exit operation attach to them and
therefore no dealloc function generated. Attach
the pre/post deallocation attribute only for the clauses that have
an exit operation.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158106
2023-08-16 13:10:43 -07:00
Valentin Clement
9a96b0a0dc
[flang][openacc] Generate pre/post alloc/dealloc function for in subroutine declare
Lowering was missing to generate the pre/post alloc/dealloc
functions for the acc declare variables. This patch adds the generation.
These functions have the descriptor as their unique argument.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158103
2023-08-16 13:04:33 -07:00
Valentin Clement
1640b80d6f
[flang][openacc] Lower gang, vector, worker, seq and nohost for acc routine
Lower clauses to the routine info op.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158007
2023-08-16 11:22:40 -07:00
Valentin Clement
0e7649698a
[flang][openacc] Fix post deallocate suffix
The wrong suffix was applied

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158098
2023-08-16 11:09:42 -07:00
Valentin Clement
e18672ad3a
[flang][openacc] Add routine info attribute to the function
Attch the routine info attribute to the func operation.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D157998
2023-08-15 22:19:03 -07:00
Valentin Clement
9334671aa7
[flang][openacc] Lower simple acc routine directive
This patch lower simple acc routine directive
with no clauses and no name inside function/subroutine.

Patch to handle name and clauses will follow up.
Patch to add attribute to the original routine will follow as well.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D157919
2023-08-15 09:45:57 -07:00
Valentin Clement
2e1982f31d
[flang][openacc] Add acc.declare_action attributes on operation
This patches adds the acc.declare_action attrbites on
post allocate operation and pre/post deallocate operations.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D157915
2023-08-15 09:44:42 -07:00
Valentin Clement
69a337e2c7
[flang][openacc][NFC] Rename createRegisterFunc and refactor
Depends on D157530

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D157555
2023-08-10 10:57:25 -07:00