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
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
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.
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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
This patch lowers allocatables and pointers named in "private" OpenMP clause.
Reviewed By: kiranchandramohan
Differential Revision: https://reviews.llvm.org/D148570
This patch extends the logic for lowering loop construct reductions to parallel block reductions.
Reviewed By: kiranchandramohan
Differential Revision: https://reviews.llvm.org/D154182
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
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
[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#60737Fixes#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
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
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
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
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
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
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
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
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.
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
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