Commit Graph

211 Commits

Author SHA1 Message Date
jeanPerier
27cfe7a07f [flang] Set assumed-size last extent to -1 (#79156)
Currently lowering sets the extents of assumed-size array to "undef"
which was OK as long as the value was not expected to be read.

But when interfacing with the runtime and when passing assumed-size to
assumed-rank, this last extent may be read and must be -1 as specified
in the BIND(C) case in 18.5.3 point 5.

Set this value to -1, and update all the lowering code that was looking
for an undef defining op to identify assumed-size: much safer to
propagate and use semantic info here, the previous check actually did
not work if the array was used in an internal procedure (defining op not
visible anymore).

@clementval and @agozillon, I left assumed-size extent to zero in the
acc/omp bounds op as it was, please double check that is what you want
(I can imagine -1 may create troubles here, and 0 makes some sense as it
would lead to no data transfer).

This also allows removing special cases in UBOUND/LBOUND lowering.

Also disable allocation of cray pointee. This was never intended and
would now lead to crashes with the -1 value for assumed-size cray
pointee.
2024-01-24 13:23:55 +01:00
Krzysztof Parzyszek
af1741ed40 [Flang][OpenMP] Reword comment for clarification, NFC 2024-01-22 09:05:44 -06:00
Krzysztof Parzyszek
55cb52bbc5 [Flang][OpenMP] Restructure recursive lowering in createBodyOfOp (#77761)
This brings `createBodyOfOp` to its final intended form. First, input
privatization is performed, then the recursive lowering takes place, and
finally the output privatization (lastprivate) is done.

This enables fixing a known issue with infinite loops inside of an
OpenMP region, and the fix is included in this patch.

Fixes https://github.com/llvm/llvm-project/issues/74348.

Recursive lowering [5/5]

---------

Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
2024-01-22 08:41:07 -06:00
Kiran Chandramohan
aac1d9710b [Flang][OpenMP] Consider renames when processing reduction intrinsics (#70822)
Fixes #68654

Depends on https://github.com/llvm/llvm-project/pull/70790
2024-01-19 15:17:21 +00:00
Kiran Chandramohan
a90347ecc7 Revert "Revert "[Flang][OpenMP] NFC: Minor refactoring of Reduction lowering code" (#73139)"
This reverts commit c2b3f16fb5.
2024-01-19 10:43:53 +00:00
Sergio Afonso
0c76865da9 [Flang][OpenMP][Lower] NFC: Combine two calls to ClauseProcessor::processTODO (#78451)
Just a minimal readability improvement that we overlooked during
refactoring.
2024-01-18 14:01:08 +00:00
Krzysztof Parzyszek
e5a34f9226 [Flang][OpenMP] Push genEval closer to leaf lowering functions (#77760)
This moves the lowering of the nested evaluations all the way to the
bottom of the call stack. This PR does not attempt to change the leaf
lowering functions beyond placing the call to `genEval` in there.
Whether the nested evaluations should be lowered for any given op
depends on the context in which that op is created, hence a `genNested`
parameter was added.

Contexts in which nested evaluations should not be lowered are during
lowering of composite constructs, such as PARALLEL SECTIONS. This
particular case is considered a block construct tied to the SECTIONS
directive, and the lowering code will first create an empty parallel op,
and then recursively lower the SECTIONS code. Similar situations occur
when lowering most (if not all) compound/composite constructs.

Recursive lowering [4/5]
2024-01-18 07:47:35 -06:00
Krzysztof Parzyszek
12c7d4c4b4 [Flang][OpenMP] Remove space before :: in member function definition,… (#78205)
… NFC

The names were
```
bool DataSharingProcessor ::needBarrier()
void DataSharingProcessor ::insertBarrier()
```

It seems like clang-format treats those as references to the global
namespace instead of separators in a qualified name.
2024-01-16 07:09:06 -06:00
Krzysztof Parzyszek
22f6e97d24 [Flang][OpenMP] Handle SECTION construct from within SECTIONS (#77759)
Introduce `genSectionOp`, invoke it from the SECTIONS construct for
each nested SECTION construct. This makes it unnecessary to embed
OpenMPSectionConstruct inside of OpenMPConstruct anymore.

Recursive lowering [3/5]
2024-01-15 11:24:28 -06:00
Krzysztof Parzyszek
705d9273c5 [Flang][OpenMP] Minor cosmetic changes post-PR#77758, NFC
Rename `getCollapsedEval` to `getCollapsedLoopEval`, and move condition
check from `getCollapsedLoopEval` to `genNestedEvaluations` (the only
caller).
2024-01-15 08:22:06 -06:00
Krzysztof Parzyszek
c5a9e35437 [Flang][OpenMP] Push genEval calls to individual operations, NFC (#77758)
Introduce `genNestedEvaluations` that will lower all evaluations nested
in the given, accouting for a potential COLLAPSE directive.

Recursive lowering [2/5]
2024-01-15 08:01:41 -06:00
Krzysztof Parzyszek
e13ee61553 [Flang][OpenMP] Separate creation of work-sharing and SIMD loops, NFC (#77757)
These two constructs were both handled in `genOMP` for loop constructs.
There is some shared code between the two, but there are also enough
differences to separate these two cases into individual functions.

The shared code converting loop bounds and steps has been extracted
into a separate function.

Recursive lowering [1/5]
2024-01-12 16:46:53 -06:00
Kareem Ergawy
52b7045fbb [flang][MLIR][OpenMP] Emit UpdateDataOp from !$omp target update (#75345)
Emits MLIR op corresponding to `!$omp target update` directive. So far,
only motion types: `to` and `from` are supported. Motion modifiers:
`present`, `mapper`, and `iterator` are not supported yet.

This is a follow up to #75047 & #75159, only the last commit is relevant
to this PR.
2023-12-22 20:02:31 +01:00
Krzysztof Parzyszek
791200b3bc [flang][OpenMP] Avoid captures of references to structured bindings
Handle one more case missed in ad37c8694e.
2023-12-21 08:41:30 -06:00
Krzysztof Parzyszek
7ffad37c86 [flang][OpenMP] Avoid captures of references to structured bindings
Fixes build break caused by 400c32cbf9.
2023-12-20 15:31:49 -06:00
Krzysztof Parzyszek
400c32cbf9 [flang][OpenMP] Use llvm::enumerate in few places, NFC (#76095)
Use `llvm::enumerate` instead of iterating over a range and keeping a
separate counter.
2023-12-20 15:09:37 -06:00
Valentin Clement (バレンタイン クレメン)
22426d9ecd [flang][openacc/mp] Do not read bounds on absent box (#75252)
Make sure we only load box and read its bounds when it is present.
- Add `AddrAndBoundInfo` struct to be able to carry around the `addr`
and `isPresent` values. This is likely to grow so we can make all the
access in a single `fir.if` operation.
2023-12-15 13:02:40 -08:00
Valentin Clement (バレンタイン クレメン)
43cb8f00f0 [flang][openacc/mp][NFC] Remove unused baseAddr argument (#75537)
`baseAddr` is not used in `genBaseBoundsOps` just remove it.
2023-12-15 09:46:47 -08:00
Krzysztof Parzyszek
82e91b91ca [flang][OpenMP] Move handling of OpenMP symbol flags to OpenMP.cpp (#75523)
The function `instantiateVariable` in Bridge.cpp has the following code:
```
  if (var.getSymbol().test(
          Fortran::semantics::Symbol::Flag::OmpThreadprivate))
    Fortran::lower::genThreadprivateOp(*this, var);

  if (var.getSymbol().test(
          Fortran::semantics::Symbol::Flag::OmpDeclareTarget))
    Fortran::lower::genDeclareTargetIntGlobal(*this, var);
```

Implement `handleOpenMPSymbolProperties` in OpenMP.cpp, move the above
code there, and have `instantiateVariable` call this function instead.

This would further separate OpenMP-related details into OpenMP.cpp.
2023-12-15 09:32:57 -06:00
Krzysztof Parzyszek
aeb482106c [flang][OpenMP] Move nested eval conversion to OpenMP.cpp, NFC (#75502)
This is the first step towards exploiting `genEval` functionality from
inside of OpenMP-generating functions.

This follows discourse discussion:
https://discourse.llvm.org/t/openmp-lowering-from-pft-to-fir/75263
2023-12-15 09:01:08 -06:00
Valentin Clement (バレンタイン クレメン)
711809f37a [flang][openacc/mp][NFC] Fix order of template arguments (#75538)
Some template parameters for the bounds ops generation have been
inverted. It should be consistent to be `BoundsOp, BoundsType`.
2023-12-14 21:13:38 -08:00
Krzysztof Parzyszek
9cf9721dcf [flang][OpenMP] Avoid unnecessary init loop, use constructor instead,… (#75482)
… NFC

SmallVector has a constructor that fills it with a number of copies of a
given value. Use it instead of a loop that does the same thing.
2023-12-14 11:24:17 -06:00
Krzysztof Parzyszek
04c4566ca1 [flang] Use genOpenMPTerminator to insert terminator (#74719)
The specific terminator operation depends on what operation it is inside
of. The function `genOpenMPTerminator` performs these checks and selects
the appropriate type of terminator.

Remove partial duplication of that code, and replace it with a function
call. This makes `genOpenMPTerminator` be the sole source of OpenMP
terminators.
2023-12-07 09:41:02 -06:00
Krzysztof Parzyszek
85e865288e [flang] Use createOpWithBody for section op, NFC (#74659)
Replace explicit calls to
```
  op = builder.create<SectionOp>(...)
  createBodyOfOp<SectionOp>(op, ...)
```
with a single call to
```
  createOpWithBody<SectionOp>(...)
```

This is NFC, that's what the `createOpWithBody` function does.
2023-12-07 07:41:32 -06:00
Krzysztof Parzyszek
10f7801cff [flang] Move genCommonBlockMember from OpenMP to ConvertVariable, NFC (#74488)
The function `genCommonBlockMember` is not specific to OpenMP, and it
could very well be a common utility. Move it to ConvertVariable.cpp
where it logically belongs.
2023-12-06 09:19:31 -06:00
Mats Petersson
0ccef6a723 [flang] Make adapt.valuebyref attribute work again (#73658)
This got "lost" in the HLFIR transformation. This patch applies the old
attribute to the AssociateOp that needs it, and forwards it to the
AllocaOp that is generated when lowering to FIR.
2023-11-29 16:15:43 +00:00
Akash Banerjee
f1d773863d [Flang][OpenMP] Remove use of non reference values from MapInfoOp (#72444)
This patch removes the val field from the `MapInfoOp`.

Previously when lowering `TargetOp`, the bounds information for the
`BoxValues` were also being mapped. Instead these ops are now cloned
inside the target region to prevent mapping of non reference typed
values.
2023-11-24 11:33:19 +00:00
Shraiysh
8840eb3fb5 [flang][OpenMP] Add semantic check for declare target (#72770) 2023-11-22 16:13:14 -06:00
Kiran Chandramohan
c2b3f16fb5 Revert "[Flang][OpenMP] NFC: Minor refactoring of Reduction lowering code" (#73139)
Reverts llvm/llvm-project#70790 to fix CI failure
(https://lab.llvm.org/buildbot/#/builders/268/builds/2884)
2023-11-22 15:47:24 +00:00
Kiran Chandramohan
8c02b34e3b [Flang][OpenMP] NFC: Minor refactoring of Reduction lowering code (#70790)
Move reduction lowering code into a ReductionProcessor class. Create an
enumeration for Intrinsic Procedure reductions.
2023-11-22 15:26:36 +00:00
NimishMishra
956cf0e5de [flang][OpenMP] Fix min reduction initialization (#73102)
Initialization of reduction variable for min-reduction is set to largest
negative value. As such, in presence of non-negative operands, min
reduction gives incorrect output. This patch initialises min-reduction
to use the maximum positive value instead, so that it can produce
correct output for the entire range of real valued operands.

Fixes https://github.com/llvm/llvm-project/issues/73101
2023-11-22 03:40:18 -08:00
Kiran Chandramohan
882d4006b9 [Flang][OpenMP] NFC: Formatting change 2023-11-20 16:44:43 +00:00
Shraiysh
c06700bd75 Revert "[flang][OpenMP] Add semantic check for declare target" (#72592)
Reverts llvm/llvm-project#71861
2023-11-16 19:17:56 -06:00
Shraiysh
7ff8094a39 [flang][OpenMP] Add semantic check for declare target (#71861)
This patch adds the following check from OpenMP 5.2.

```
If the directive has a clause, it must contain at least one enter clause
or at least one link clause.
```

Also added a warning for the deprication of `TO` clause on `DECLARE
TARGET` construct.

```
The clause-name to may be used as a synonym for the clause-name enter.
This use has been deprecated.
```

Based on the tests for to clause, the tests for enter clause are added.

This patch does not add tests where both to and enter clause are used together.
2023-11-16 18:03:32 -06:00
NimishMishra
c4d7321615 [flang][OpenMP] Skip default privatization for crashing cases (#71922)
This patch skips default privatization for crashing cases like
namelists, reduction instrinsics, and structure constructor.

Fixes: https://github.com/llvm/llvm-project/issues/67332,
https://github.com/llvm/llvm-project/issues/66454, and
https://github.com/llvm/llvm-project/issues/65569

Co-Authored-By: kiranchandramohan <kiran.chandramohan@arm.com>
2023-11-10 05:24:21 -08:00
NimishMishra
91f92e6a6b [flang][OpenMP] Fix common block missing symbol crash (#67330)
Fixes #65034 by skipping copy of host-association information if the
concerned symbol is missing from the inner construct
2023-11-10 00:17:47 -08:00
Kiran Chandramohan
848ae10cd2 [Flang][OpenMP] Finalize Statement context of clauses before op creation (#71679)
Currently Statement context used during processing of clauses is
finalized after the OpenMP operation creation. This causes the
finalization to go inside the OpenMP region and this can lead to
multiple finalizations in a parallel region. This fix proposes to
finalize them before the OpenMP op creation.

Fixes #71342
2023-11-09 14:22:20 +00:00
Kiran Chandramohan
cace7159ca [Flang][OpenMP] Process reduction only once for parallel do (#70844) 2023-11-09 14:11:46 +00:00
Slava Zakharin
ecb1fbaa13 [flang][openacc] Generate data bounds for array addressing. (#71254)
In cases like `copy(array(N))` it is still useful to represent
the data operand uniformly with `copy(array(N:N))`.
This change generates data bounds even if it is not an array
section with the triplets. The lower and the upper bounds
are the same and the extent is one in this case.
2023-11-06 14:45:46 -08:00
Akash Banerjee
8b3c071b6f [Flang][OpenMP] Small fix to handle CharBoxValue types for implicit target maps
Original commit: fbaf2c6cf7
Original PR: #67164
2023-11-06 16:50:09 +00:00
Kiran Chandramohan
12756831e4 [Flang][OpenMP] Mark mergeable and untied clauses as unsupported (#71209)
These two clauses are not supported in the OpenMP Dialect to LLVM
conversion. Mark as TODO till support is added.
2023-11-06 15:01:57 +00:00
Akash Banerjee
fbaf2c6cf7 [OpenMP][Flang] Add "IsolatedFromAbove" trait to omp.target
This patch adds the PFT lowering changes required for adding the IsolatedFromAbove trait to omp.target.

Key Changes:
	- Add IsolatedFromAbove trait to target op in MLIR.
	- Main reason for this change is to prevent CSE and other similar optimisations from crossing region boundaries for target operations. The link below has the discourse discussion surrounding this issue.
	- Move implicit operand capturing to the PFT lowering stage.
	- Implicit operands are first added as implicitly captured map_operands with their map_types set accordingly to indicate this. Later, all map_operands including implicit ones are added as block arguments.
	- Remove `implicit` attribute from the `MapInfoOp`. This information is already captured by the `map_type`.
	- The custom printer and parser for the map_types have been updated to show the `implicit` and `literal` map_types.
	- Update related tests.
	- This fixes #63555.
	- This fixes #70488.
2023-11-06 13:24:02 +00:00
Kiran Chandramohan
eac11c59a3 [Flang][OpenMP] Support unstructured code in target data (#71051) 2023-11-02 13:51:01 +00:00
Valentin Clement (バレンタイン クレメン)
0f8615f4dc [flang][openacc][openmp] Set correct location on atomic operations (#70680)
The location set on atomic operations in both OpenMP and OpenACC was
completly off. The real location needs to be created from the source
CharBlock of the parse tree node of the respective atomic statement.
This patch updates locations in lowering for atomic operations.
2023-10-30 10:35:43 -07:00
Leandro Lupori
ed979323d8 [flang][OpenMP] Fix LASTPRIVATE for iteration variables (#69773)
Iteration variables behave slightly different with LASTPRIVATE,
as they must be assigned the value that the copy would have after
sequential execution of the loop. This case is now handled.

This patch also fixes LASTPRIVATE for loops where the step is
different from 1.

Fixes https://github.com/llvm/llvm-project/issues/64055
2023-10-24 09:46:01 -03:00
Kiran Chandramohan
0235cd7336 [MLIR,Flang,OpenMP] Remove usage of getElementType in OpenMPTranslation (#69772)
Remove usage of getElementType in OpenMPTranslation to pave way for
switching to opaque pointers in MLIR and Flang. The approach chosen
stores the elementType in a new field in MapInfo called varType. A
similar approach was chosen for AtomicReadOp in

81767f52f4
2023-10-23 22:25:58 +01: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
Sergio Afonso
29aa749087 [OpenMP][Flang][MLIR] Lowering of OpenMP requires directive from parse tree to MLIR
This patch implements the lowering of the OpenMP 'requires' directive
from Flang parse tree to MLIR attributes attached to the top-level
module.

Target-related 'requires' clauses are gathered and combined for each top-level
unit during semantics. Lastly, a single module-level `omp.requires` attribute
is attached to the MLIR module with that information at the end of the process.

The `atomic_default_mem_order` clause is not addressed by this patch, but
rather it will come as a separate patch and follow a different approach.

Depends on D147214, D150328, D150329 and D157983.

Differential Revision: https://reviews.llvm.org/D147218
2023-09-14 10:34:54 +01: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: 29f167abcf
2023-09-13 20:49:54 -07:00
Daniil Dudkin
8a6e54c9b3 [mlir][arith] Rename operations: maxfmaximumf, minfminimumf (#65800)
This patch is part of a larger initiative aimed at fixing floating-point `max` and `min` operations in MLIR: https://discourse.llvm.org/t/rfc-fix-floating-point-max-and-min-operations-in-mlir/72671.

This commit addresses Task 1.2 of the mentioned RFC. By renaming these operations, we align their names with LLVM intrinsics that have corresponding semantics.
2023-09-11 22:02:19 -07:00