Commit Graph

140 Commits

Author SHA1 Message Date
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
Kiran Chandramohan
f51bdae4e3 [Flang][OpenMP] Add support for OpenMP max reduction
This patch adds support for reduction of max-intrinsic for scalar
types. Max 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.

Reviewed By: do

Differential Revision: https://reviews.llvm.org/D145083
2023-03-14 21:38:08 +00:00
Kiran Chandramohan
62fbb4c34e Revert "[Flang][OpenMP] Add support for OpenMP max reduction"
Reverting to fix a buildbot failure.

This reverts commit a7d80f43cb.
2023-03-14 16:27:18 +00:00
Kiran Chandramohan
a7d80f43cb [Flang][OpenMP] Add support for OpenMP max reduction
This patch adds support for reduction of max-intrinsic for scalar
types. Max 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.

Reviewed By: do

Differential Revision: https://reviews.llvm.org/D145083
2023-03-14 16:01:58 +00:00
Kiran Chandramohan
890e6c871d [Flang][OpenMP] NFC: Fix a few format issues
Change a few variable/class names to be in line with guidelines.
2023-03-11 10:55:27 +00:00
Dylan Fleming
56164c3eb4 [Flang][MLIR][OpenMP] Add support for logical eqv in worksharing-loop
The patch adds the lowering from Flang parse-tree to FIR+OpenMP. The
conversion code is also added in MLIR.

Reviewed By: kiranchandramohan

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

Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
2023-03-09 13:58:23 +00:00
Kiran Chandramohan
fa5714387f [Flang][OpenMP] Fix unused variable warning/error 2023-03-03 16:03:32 +00:00
Kiran Chandramohan
b512580cff [Flang][OpenMP] NFC: Refactor privatization code in Lowering 1/n
The code for handing privatization code has grown in complexity.
This patch begins an effort to refactor and simplify the code.
The refactoring will hopefully will make it modular and
enable privatization to be invoked in different places. This
patch moves the privatization related code into a class called
dataSharingProcessor.

Reviewed By: DavidTruby

Differential Revision: https://reviews.llvm.org/D144766
2023-03-03 15:45:51 +00:00
Akash Banerjee
7d9be4368a [MLIR][OpenMP] Add Lowering support for OpenMP Target Data with region
This patch adds Fortran Lowering support for the OpenMP Target Data Op with associated region.

Differential Revision: https://reviews.llvm.org/D144013
2023-03-03 13:04:39 +00:00
Kiran Chandramohan
0ca86a42f0 [Flang][OpenMP] Improved reduction clause TODO message
Provide the name of the construct and the clause info (reduction)
in the TODO mesage.

Reviewed By: DavidTruby

Differential Revision: https://reviews.llvm.org/D145061
2023-03-02 17:46:36 +00:00
Nimish Mishra
f49b6afc23 [flang][OpenMP] Handle lastprivate on sections construct
This patch adds support for lastprivate on sections construct.
One omp.sections operation can have several omp.section operation. As such, the privatization happens in the lexically last omp.section operation.

Reviewed By: kiranchandramohan, peixin

Differential Revision: https://reviews.llvm.org/D133686
2023-02-27 17:29:39 +05:30
Kiran Chandramohan
9adef1048a [Flang][OpenMP] Add convert to match the argument and result of update Op
Fixes #60873

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D144432
2023-02-21 12:34:16 +00:00
Prabhdeep Singh Soni
179db7efe5 [MLIR][OpenMP] Add support for depend clause
This patch adds support for the OpenMP 4.0 depend clause (in, out,
inout) of the task construct to the definition of the OpenMP MLIR
dialect and translation from MLIR to LLVM IR using OMPIRBuilder.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D142730
2023-02-14 14:18:16 -05:00
Kiran Chandramohan
af03616f46 [Flang][OpenMP][NFC] Remove usage of else after return 2023-02-12 22:09:26 +00:00
Kiran Chandramohan
10d8b3054a [Flang][OpenMP][NFC] Correct a few instances of variable naming
In lowering code Flang follows the MLIR coding guideline of using
camelBack for variables names. Correct a few instances that were
not following this guideline.
2023-02-12 17:12:40 +00:00
Markus Böck
81767f52f4 [mlir][OpenMP] Add support for using Opaque Pointers in the OpenMP Dialect
The current OpenMP implementation assumes the use of typed pointers (or rather typed pointer like types). Given the support for typed pointers in LLVM is now pending removal, the OpenMP Dialect should be able to support opaque pointers as well, given that any users of it must lower OpenMP through the LLVM Dialect.

This patch fixes the above and adds support for using LLVM opaque pointers with the OpenMP dialect. This is implemented by making all related code not make use of the element type of pointer arguments. The few (one) op requiring a pointer element type now use an explicit `TypeAttr` for representing the element type.
More concretely, the list of changes are:
* `omp.atomic.read` now has an extra `TypeAttr` (also in syntax) which is the element type of the values read and stored from the operands
* `omp.reduction` now has an type argument in the syntax for both the accmulator and operand since the operand type can no longer be inferred from the accumulator
* `OpenMPToLLVMIRTranslation.cpp` was rewritten to never query element types of pointers
* Adjusted the verifier to be able to handle pointers without element types

Differential Revision: https://reviews.llvm.org/D143582
2023-02-10 17:56:37 +01:00
Akash Banerjee
0488ecb569 [MLIR][OpenMP] Add Lowering support for OpenMP Target Data, Exit Data and Enter Data directives
This patch adds Fortran Lowering support for the OpenMP Target Data, Target Exit Data and Target Enter Data constructs.
operation.

Differential Revision: https://reviews.llvm.org/D142357
2023-01-26 10:59:55 +00:00
Dominik Adamski
e4ebe14fd1 [mlir][OpenMP] Add nontemporal clause definition to simd construct
simd nontemporal construct is represented as a list of variables
which have low locality accross simd iterations

Added verifier of nontemporal clause. MLIR tests were updated to test
correctness of MLIR definition of nontemporal clause.

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

Reviewed By: kiranchandramohan
2023-01-19 05:41:50 -06:00
Dominik Adamski
163dbfe869 [mlir][OpenMP] Add order clause definition to simd construct
Update simd construct definition and add mlir tests to prove
that order(concurrent) clause is correctly modeled for simd
construct.
2022-11-18 06:08:04 -06:00
Sergio Afonso
d5fb5960d0 [flang][OpenMP] Add parser support for Requires directive
OpenMP 5.0 adds support for the "requires" directive. This patch adds parser support for it in flang.

Differential revision: https://reviews.llvm.org/D136867
2022-11-10 05:38:31 -06:00
Dominik Adamski
25243d717d [mlir][OpenMP] Add aligned clause definition to simd construct
simd aligned construct is represented as pair of variable which needs
to be aligned and corresponding alignment value.

Added parser, printer and verifier of aligned clause. MLIR tests were
updated to test correctness of MLIR definition of aligned clause.

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

Reviewed By: kiranchandramohan
2022-11-01 11:07:53 -05:00
Peixin Qiao
240b85b1a8 [flang][OpenMP] Fix the use-associated bug in threadprivate directive lowering
The symbol may be used by use-association for multiple times such
as one in module specification part and one in module procedure.
Then in module procedure, the variable instantiation will be called
for multiple times. But we only need to threadprivatize it once and
use the threadprivatized value for the second time.

Fix #58379.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D136035
2022-10-17 19:46:18 +08:00
Slava Zakharin
606245ad54 [flang] Fixed build issue after 88f07a736b
nullptr matches both against ::mlir::UnitAttr and ::mlir::TypeRange,
so the following two candidates fit:
static void mlir::omp::OrderedRegionOp::build(::mlir::OpBuilder &odsBuilder,
    ::mlir::OperationState &odsState,
    /*optional*/::mlir::UnitAttr simd)
static void mlir::omp::OrderedRegionOp::build(::mlir::OpBuilder &odsBuilder,
    ::mlir::OperationState &odsState,
    ::mlir::TypeRange resultTypes,
    /*optional*/bool simd = false)
2022-10-05 12:59:31 -07:00
Peixin Qiao
f4accbf55f [flang][OpenMP] Support privatization for single construct
This supports the lowering of private and firstprivate clauses in single
construct. The alloca ops are emitted in the entry block according to
https://llvm.org/docs/Frontend/PerformanceTips.html#use-of-allocas, and
the load/store ops are emitted in the single region. The data race
problem is handled in OMPIRBuilder. That is, the barrier is emitted in
OMPIRBuilder.

Co-authored-by: Nimish Mishra <neelam.nimish@gmail.com>

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D128596
2022-10-05 20:22:33 +08:00
River Riddle
c692a11e69 [mlir] Flip Async/GPU/MemRef/OpenACC/OpenMP/PDL dialects to prefixed
This flips all of the remaining dialects to prefixed except for linalg, which
will be done in a followup.

Differential Revision: https://reviews.llvm.org/D134995
2022-09-30 16:55:30 -07:00