Commit Graph

164 Commits

Author SHA1 Message Date
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
Sergio Afonso
65e80d6dfd [Flang][OpenMP] Improve support for if clause on combined constructs
This patch adds support for matching multiple OpenMP `if` clauses to their
specified directive in a combined construct. It also enables this clause to be
attached by name to `simd` and `teams` directives, in addition to the others
that were already supported.

This patch on its own cannot yet be tested because there is currently no
lowering to MLIR support for any combined construct containing two or more
OpenMP directives that can have an `if` clause attached.

Depends on D155981.

Differential Revision: https://reviews.llvm.org/D156313
2023-08-04 10:43:12 +01:00
Kiran Chandramohan
93b0d0f6b5 [Flang][OpenMP] Add TODO message for copyprivate clause
The copyprivate clause is not yet implemented. Provide a TODO
error message when this clause is seen.

Reviewed By: NimishMishra

Differential Revision: https://reviews.llvm.org/D155596
2023-08-03 18:51:27 +00:00
Peter Klausler
45760be33b [flang] Attempt to silence new GCC warnings
Restructure three code sites that are now eliciting new warnings
from the latest GCC compiler.  One of these looks like a
legitimate problem with a reference to an expression temporary.

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

Differential Revision: https://reviews.llvm.org/D156750
2023-08-02 07:58:00 -07:00
Leandro Lupori
5bbfbd9a1c [flang][OpenMP] Fix parallel do with integer*1 var
Temporaries created to store worksharing loop index values were
using different types than that of the original index variables.
This caused invalid IR to be produced when an index variable was
used in binary operations which expected its original type.

Fix this by creating temporaries with the types of their original
variables and converting the loop values, that continue to use
the types that OpenMP runtime expects, to them.

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

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D156803
2023-08-02 10:16:16 -03:00
Kiran Chandramohan
980808dc5b [Flang][OpenMP] Fix loop index privatisation with HLFIR
Loop index variables are privatised for a worksharing loop.
The alloca ops of the privatised index are hoisted to the
entry block of the outlineable region or parent function.
With HLFIR, the hlfir.declare should be created in the same
place as the alloca op. To achieve this the alloc and the
hflir.declare should be created in the same place. A new
function is created in OpenMP.cpp for this purpose.

Reviewed By: tblah

Differential Revision: https://reviews.llvm.org/D156719
2023-08-01 14:45:52 +00:00
Nimish Mishra
da1f1b2292 Prevent extraneous copy in f752265231
Commit f752265231 uses
extraneous copy to the loop variable. Fixing the same
2023-07-31 17:31:19 +05:30
Nimish Mishra
f752265231 [flang][OpenMP] Support for privatization in common block
This patch provides support for usage of common block
in private/firstprivate and lastprivate clauses.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D156120
2023-07-31 16:46:18 +05:30
Peixin Qiao
b4c54b2027 [flang][OpenMP] Support common block in OpenMP private clause
This supports the common block in OpenMP privat clause by making
each common block member host-associated privatization and
adds the test case.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D127215
2023-07-31 16:24:12 +05:30
Sergio Afonso
fcb6a9c07c [Flang][OpenMP][Lower] Refactor implementation of PFT to MLIR lowering
This patch makes the following non-functional changes:
  - Extract OpenMP clause processing into a new internal `ClauseProcessor`
    class. Atomic and reduction-related clauses processing is kept unchanged,
    since atomic clauses are stored in `OmpAtomicClauseList` rather than
    `OmpClauseList` and there are many TODO comments related to the current
    implementation of reduction lowering. This has been left unchanged to avoid
    merge conflicts and work duplication.
  - Reorganize functions into sections in the file to improve readability.
  - Explicitly use mlir:: namespace everywhere, rather than just most places.
  - Spell out uses of `auto` in which the type wasn't explicitly stated as part
    of the initialization expression.
  - Normalize a few function names to match the rest and renamed variables in
    'snake_case' to 'camelCase'.

The main purpose is to reduce code duplication and simplify the implementation
of upcoming work to support loop-attached target constructs and teams/
distribute lowering to MLIR.

Differential Revision: https://reviews.llvm.org/D155981
2023-07-31 10:51:39 +01:00
Kiran Chandramohan
305ad9a6b2 [Flang][OpenMP] Use typed assignment in Atomic Write lowering
Use typed assignment in Atomic Write lowering to better handle
type conversions of allowed types.

Note: We should make similar changes for other constructs in
later patches.

Reviewed By: NimishMishra

Differential Revision: https://reviews.llvm.org/D154163
2023-07-14 09:21:34 +00:00
Andrew Gozillon
e909a2c1ca [Flang][OpenMP][Lower] Program level implicit SAVE variable handling for declare target
This is an attempt at mimicing the method in which
threadprivate handles the following type of variables:

program main
  integer :: i
  !$omp declare target to(i)
end

Which essentially generates a GlobalOp for the variable (which
would normally only be an alloca) when it's instantiated. The
main difference is there is no operation generated within the
function, instead the declare target attribute is appended
later within handleDeclareTarget.

Reviewers: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D152037
2023-07-13 12:07:21 -05:00
Valentin Clement
a25edba7b5 [flang][NFC] Remove duplicate of getDesignatorNameIfDataRef function
Remove duplicate of the getDesignatorNameIfDataRef() function.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D155105
2023-07-13 08:53:19 -07:00
Kiran Chandramohan
7505f2c92d [Flang][OpenMP] Only access the MapType if it is specified
Fixes #63638

Reviewed By: TIFitis

Differential Revision: https://reviews.llvm.org/D154442
2023-07-05 12:56:09 +00:00
Dmitriy Smirnov
bc4586da6e [Flang][OpenMP] Lower allocatable or pointer in private clause
This patch lowers allocatables and pointers named in "private" OpenMP clause.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D148570
2023-07-03 16:46:02 +00:00
Ethan Luis McDonough
9bf5093623 [flang][openmp] Parallel reduction FIR lowering
This patch extends the logic for lowering loop construct reductions to parallel block reductions.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D154182
2023-06-30 15:36:27 -05:00
Kiran Chandramohan
f58498399b [Flang][OpenMP] Correct location information 1/n
This patch fixes location information of a few OpenMP constructs
and clauses. More fixes will come in follow-up patches.

This patch follows the same fixes for OpenACC (D131659).

Addresses some of the issues in https://github.com/llvm/llvm-project/issues/57215

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D153887
2023-06-27 20:34:19 +00:00
Akash Banerjee
d21580c306 [MLIR][OpenMP]Add Flang lowering support for device_ptr and device_addr clauses
Add lowering support for the use_device_ptr and use_Device_addr clauses for the Target Data directive.

Depends on D152822

Differential Revision: https://reviews.llvm.org/D152824
2023-06-22 15:52:33 +01:00
Peixin Qiao
ed27d28f9a [flang][OpenMP][OpenACC] Support stop statement in OpenMP/OpenACC region
[flang][OpenMP][OpenACC] Support stop statement in OpenMP/OpenACC region

This supports lowering of stop statement in OpenMP/OpenACC region.
* OpenMP/OpenACC: Emit `fir.unreachable` only if the block is not
  terminated by any terminator. This avoids knocking off an existing
  OpenMP/OpenACC terminator.
* OpenMP: Emit the OpenMP terminator instead of `fir.unreachable` since
  OpenMP regions can only be terminated by OpenMP terminators. This is
  currently skipped for OpenACC since unstructured code is not yet
  handled specially in OpenACC lowering.

Fixes #60737
Fixes #61877

Co-authored-by: Kiran Chandramohan <kiranchandramohan@gmail.com>
Co-authored-by: Val Donaldson <vdonaldson@nvidia.com>

Reviewed By: vdonaldson, peixin

Differential Revision: https://reviews.llvm.org/D129969
2023-06-15 10:29:42 +00:00
Prabhdeep Singh Soni
e0fed04366 [Flang][OpenMP] Fix unused variable warning for task depend
This patch fixes an unused variable warning that was caused by the task
depend patch.

Original Commit: 3373c8405c

Original Differential Revision: https://reviews.llvm.org/D146766
2023-06-06 12:29:42 -04:00
Prabhdeep Singh Soni
3373c8405c [Flang][OpenMP] Support depend clause for task construct, excluding array sections
This patch adds support for the OpenMP 4.0 depend clause for the task
construct, excluding array sections, to Flang lowering from parse-tree
to MLIR.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D146766
2023-06-06 10:21:05 -04:00
Kiran Chandramohan
ca81808cc3 [Flang][OpenMP] Refactor to properly fix privatisation of loop bounds
The OpenMP loop Operations have the bounds attached to them. If the
loop bounds are privatised then the privatisation has to happen
before the loop operation is created. To do this the privatisation
is split into two steps. The first step performs cloning and
firstprivate handling, the second step performs lastprivate handling.

This also reverts the changes in the temporary fix (D127137).

Fixes https://github.com/flang-compiler/f18-llvm-project/issues/1171#issuecomment-1143880545
Fixes https://github.com/flang-compiler/f18-llvm-project/issues/1171#issuecomment-1119997442

Fixes #60872

Reviewed By: NimishMishra

Differential Revision: https://reviews.llvm.org/D151504
2023-06-05 16:04:24 +00:00
Andrew Gozillon
e39866c75d [Flang][OpenMP][MLIR] Add lowering from PFT to MLIR (FIR) for OpenMP declare target directive in Flang
This patch adds PFT lowering for the OpenMP declare target directive
in Flang to the omp dialects declare target attribute, which currently
applies to function or global operations.

Reviewers: kiranchandramohan, skatrak, jsjodin

Differential Revision: https://reviews.llvm.org/D150329
2023-06-05 07:07:56 -05:00
Kiran Chandramohan
218841af7c [Flang][OpenMP] Add Todo for doconcurrent with worksharing loop
This is a valid usage. We do not handle it as of now. Gfortran/Ifx produces an error, possibly because `do concurrent` was not allowed in previous versions of the OpenMP standard.

Fixes #62649

Reviewed By: Leporacanthicus

Differential Revision: https://reviews.llvm.org/D150869
2023-05-19 12:03:03 +00:00
Ethan Luis McDonough
6311ab2147 [Flang] Syntax support for OMP Allocators Construct
OpenMP 5.2 introduces a Fortran specific construct that aims to replace the executable allocate directive.  This patch seeks to add parser support for the directive as well as the allocator clause with the [[ https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5-2.pdf#section.6.6 | extended align/complex ]] modifier.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D149727
2023-05-10 14:57:20 -05:00
Nimish Mishra
b2eceea392 [flang][OpenMP] Lowering support for atomic capture
This patch adds lowering support for atomic capture operation. First is
created a region (without any operand) for the atomic capture operation.
Then based on one of the following configurations...

	1. [update-stmt, capture-stmt]
	2. [capture-stmt, update-stmt]
	3. [capture-stmt, write-stmt]
... the lowering proceeds by creating these individual operations inside
the atomic capture's region.

Differential Revision: https://reviews.llvm.org/D127272

Reviewed By: kiranchandramohan
2023-05-04 10:18:08 +05:30
Nimish Mishra
b50f733c20 [flang][OpenMP] Lowering support for lastprivate on unstructured sections
construct

This patch adds lowering support for lastprivate privatization on
unstructured construct. Generic lastprivate lowering on sections
involves creating a if operation on the lexically last section block
and updating the lastprivate variable inside it. However, this control
flow is not needed if the section construct is lowered as an
unstructured construct. Hence, this patch modifies the lowering control
flow to not emit an unnecessary scf.if if the section block is lowered
as an unstructured construct.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D143077
2023-05-04 09:27:36 +05:30
Kiran Chandramohan
39e8e59950 [Flang][OpenMP] Use fir.if instead of scf.if in lastprivate lowering
For finding the last iteration of a loop, or the last section an
if condition is generated. Using scf::if can cause some lowering
issues since the code contained inside it can have branches. Using
fir::if instead ensures that the fir::if is lowered into branches
along with any code contained inside that can generate branches.

Fixes #62458.

Reviewed By: NimishMishra

Differential Revision: https://reviews.llvm.org/D149547
2023-05-02 12:02:04 +00:00
do
740c0b3a50 {Flang][OpenMP] Add support for ior, ieor, and iand reduction in worksharing-loop
Adds support for .ior., .ieor., and .iand. reductions.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D148994
2023-04-26 14:40:15 -04:00
Kavitha Natarajan
38bb79beac [Flang][OpenMP] Add support for OpenMP MIN reduction
This patch adds support for reduction of min-intrinsic for scalar
types. Min is lowered as a compare-select in the default lowering
flow for Flang. This pattern is matched and replaced with the
OpenMP dialect reduction operation.

Note: This is a temporary flow. The plan is to move to a flow
where the OpenMP reduction operation is inserted during lowering.
2023-04-20 12:13:58 +05:30
do
9f4051b79d [Flang][OpenMP] Add support for logical neqv reduction in worksharing-loop
Adds support for .neqv. reductions with logical types.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D147677
2023-04-13 18:04:08 -04:00
Akash Banerjee
2cfbbfc06f [Flang][OpenMP] Add Fortran lowering support for Target directive
This patch adds Fortran lowering support for OMP Target directive along with tests.

Differential Revision: https://reviews.llvm.org/D147339
2023-04-11 16:35:43 +01:00
dossai.o@yahoo.com
3b11e4097f [Flang][OpenMP] Add support for logical or reduction in worksharing-loop
Adds support for .or. reductions with logical types.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D145410
2023-03-30 17:59:57 -04:00
Kavitha Natarajan
da9f890d09 [Flang][OpenMP] Fix crash in MAX intrinsic reduction
This patch fixes a crash that appear in an OpenMP MAX intrinsic
reduction when the reduction is not expressed using MAX intrinsic
function. Updated flang/test/Lower/OpenMP/wsloop-reduction-max.f90
test case with additional way of expressing MAX reduction.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D146967
2023-03-29 23:41:21 +05:30
Akash Banerjee
a1717a3e75 [Flang][OpenMP] Added TODO checks for unsupported map types
This patch adds TODO checks for unspported types in the map clause for OpenMP Target directives.

Example of unsupported code:

implicit none
character(len=10) :: str1, str2(5,5)

type t
  character(len=10) :: str1, str2(5,5)
end type t
type(t) :: v

!$omp target enter data map(to: str2(2,5))
!$omp target enter data map(to: v%str1)
!$omp target enter data map(to: v%str2)
!$omp target enter data map(to: v%str2(1,2))

end

Differential Revision: https://reviews.llvm.org/D146292
2023-03-27 12:37:53 +01:00
Kiran Chandramohan
90d9c1ca74 [Flang][OpenMP] Add TODO message for common block privatisation
This is a temporary message until the feature is implemented and
merged.

Note: There is a proposed patch (https://reviews.llvm.org/D127215)

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D146768
2023-03-24 11:20:03 +00:00