Commit Graph

199 Commits

Author SHA1 Message Date
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
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
Kiran Chandramohan
0677a9d559 [Flang][OpenMP] Minor changes in reduction to work with HLFIR (#65775)
Changes are to work correctly in the presence of hlfir.declare, and
hlfir.assign (instead of fir.store).
2023-09-11 10:30:01 +01:00
kiranchandramohan
99789344d3 [Flang][OpenMP] Seek over an HLFIR declare to check for threadprivate (#65507)
To check whether we have already generated a threadprivate operation, we
have to seek over the HLFIR declare in the HLFIR flow.
2023-09-07 12:15:47 +01:00
Fangrui Song
fc04472aa2 [flang] Fix duplicate word typos; NFC
Those fixes were taken from https://reviews.llvm.org/D137338
2023-09-01 18:41:05 -07:00
Kiran Chandramohan
6163d66e73 [Flang][OpenMP] Fix for atomic lowering with HLFIR
Atomic update operation is modelled in OpenMP dialect as
an operation that takes a reference to the operation being
updated. It also contains a region that will perform the
update. The block argument represents the loaded value from
the update location and the Yield operation is the value
that should be stored for the update.

OpenMP FIR lowering binds the value loaded from the update
address to the SymbolAddress. HLFIR lowering does not permit
SymbolAddresses to be a value. To work around this, the
lowering is now performed in two steps. First the body of
the atomic update is lowered into an SCF execute_region
operation. Then this is copied into the omp.atomic_update
as a second step that performs the following:
-> Create an omp.atomic_update with the block argument of
the correct type.
-> Copy the operations from the SCF execute_region. Convert
the scf.yield to an omp.yield.
-> Remove the loads of the update location and replace all
uses with the block argument.

Reviewed By: tblah, razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158294
2023-08-31 17:34:45 +00:00
Peter Klausler
031b4e5e79 [flang] Support SELECT RANK on allocatables & pointers
Unlike other executable constructs with associating selectors, the
selector of a SELECT RANK construct can have the ALLOCATABLE or POINTER
attribute, and will work as an allocatable or object pointer within
each rank case, so long as there is no RANK(*) case.

Getting this right exposed a correctness risk with the popular
predicate IsAllocatableOrPointer() -- it will be true for procedure
pointers as well as object pointers, and in many contexts, a procedure
pointer should not be acceptable.  So this patch adds the new predicate
IsAllocatableOrObjectPointer(), and updates some call sites of the original
function to use the new one.

Differential Revision: https://reviews.llvm.org/D159043
2023-08-29 14:56:15 -07:00
Sergio Afonso
841c4dc7e5 [Flang][OpenMP][Lower] Fail compilation with TODO errors for unsupported clauses
This patch explicitly marks supported clauses for OpenMP directives missing an
implementation, so that compilation fails if they are specified, rather than
silently ignoring them.

Differential Revision: https://reviews.llvm.org/D158076
2023-08-22 11:35:49 +01:00
Nimish Mishra
2c3ded64bb [flang][OpenMP] Support for common block in copyin clause
This patch adds lowering support for threadprivate
variables encapsulated in a common block and
marked inside a copyin clause.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D157083
2023-08-21 10:01:57 +05:30
Sergio Afonso
211ed03bfd [Flang][OpenMP][Lower] Support lowering of teams directive to MLIR
This patch adds support for translating `teams` OpenMP directives to MLIR, when
appearing as either loop or block constructs and as part of combined constructs
or on its own.

The current Fortran parser does not allow the specification of the optional
lower bound for the "num_teams" clause, so only the `num_teams_upper` MLIR
argument is set by this patch.

Depends on D156809

Differential Revision: https://reviews.llvm.org/D156884
2023-08-15 13:38:09 +01:00
Sergio Afonso
8c177ae9dd [Flang][OpenMP][Lower] Refactor MLIR codegen for OpenMP constructs
This patch extracts MLIR codegen logic from various types of OpenMP constructs
and places it into operation-specific functions. This refactoring mainly
targets block constructs and unifying logic for directives that can appear on
their own as well as combined with others.

The processing of clauses that do not apply to the directive being processed is
avoided and code duplication for combined constructs is reduced.

Depends on D156455.

Differential Revision: https://reviews.llvm.org/D156809
2023-08-15 13:17:35 +01:00
Sergio Afonso
da5e96694d [Flang][OpenMP][Lower] Support PFT to MLIR lowering of loop-attached target constructs
This patch adds support for lowering target-related combined constructs from
PFT to MLIR. The lowering of OpenMP loop constructs is generalized in
preparation for later supporting different combinations of target, teams,
distribute, parallel and simd directives.

Currently enabled by this patch are the following combined constructs:
- do simd
- parallel do simd
- target parallel do simd
- target parallel do
- target simd

Depends on D155981 and D157090.

Differential Revision: https://reviews.llvm.org/D156455
2023-08-15 12:56:35 +01:00
Kiran Chandramohan
bd686ca4f7 [Flang][OpenMP] Fix lowering for threadprivate with HLFIR
HLFIR inserts hlfir.declare for threadprivate variables. Seek over
the hlfir.declare to find the threadprivate global symbol.

Reviewed By: tblah

Differential Revision: https://reviews.llvm.org/D157730
2023-08-11 16:25:50 +00:00