Commit Graph

78 Commits

Author SHA1 Message Date
Leandro Lupori
edcf65d40c [flang][OpenMP] Allow loop iteration variables in DSA clauses (#86194)
Iteration variables of non-associated loops may be listed in DSA
clauses.

Fixes https://github.com/llvm/llvm-project/issues/78938
2024-03-25 08:48:11 -03:00
Michael Klemm
fb5fd2d82f [flang][OpenMP] Compile proper omp_lib.mod from the openmp/src/include sources (#80874)
This PR changes the build system to use use the sources for the module
`omp_lib` and the `omp_lib.h` include file from the `openmp` runtime
project and not from a separate copy of these files. This will greatly
reduce potential for inconsistencies when adding features to the OpenMP
runtime implementation.

When the OpenMP subproject is not configured, this PR also disables the
corresponding LIT tests with a "REQUIRES" directive at the beginning of
the OpenMP test files.

---------

Co-authored-by: Valentin Clement (バレンタイン クレメン) <clementval@gmail.com>
2024-03-20 13:47:26 +01:00
Tom Eccles
53d8c6b1b1 [flang][Semantics][OpenMP] set intrinsic attr for reductions (#85114)
Reductions such as min are intrinsic procedures. This distinguishes them
from user defined reductions. Previously, the intrinsic attribute was
not set when visiting reduction clauses causing them to be missed.

wsloop-reduction-min.f90 (the other min reduction test) worked because
it contained "min" used as an intrinsic inside of the body of the
reduction. This allowed ResolveNamesVisitor::HandleProcedureName to set
the correct attribute on that Symbol.
2024-03-15 11:12:09 +00:00
agozillon
096ee4e16f [Flang][OpenMP] Implement "promotion" of use_device_ptr non-cptr arguments to use_device_addr (#82834)
This effectively implements some now deprecated OpenMP functionality
that some applications (most notably at the moment GenASiS)
unfortunately depend on (deprecated in specification version 5.2):

"If a list item in a use_device_ptr clause is not of type C_PTR, the
behavior is as if the list item appeared in a use_device_addr clause.
Support for such list items in a use_device_ptr clause is deprecated."

This PR downgrades the hard-error to a deprecated warning and "promotes"
the above cases by simply moving the offending operands from the
use_device_ptr value list to the back of the use_device_addr list (and
moves the related symbols, locs and types that form the BlockArgs
correspondingly) and then the generation of the target data construct
proceeds as normal.
2024-03-13 16:18:21 +01:00
Sergio Afonso
27498e9942 [Flang][OpenMP] Prevent ICE for certain constructs in unnamed programs (#73938)
This patch fixes #72748 by modifying the processing of program units to
search for a symbol to which OpenMP REQUIRES clauses can bind to. Rather
than picking up the first PFT node with a source reference and getting
its associated scope, it picks up the last one.

This avoids using the source from the first specification construct of
a nameless program, which can sometimes not be associated to any scope,
causing an ICE due to an invalid source location.
2024-02-22 14:35:05 +00:00
agozillon
cf8fc53a96 [Flang][LLVM][OpenMP] Relax target data restrictions to be more inline with the specification (#82537)
Currently we emit errors whenever a map is not provided on a target data
directive, however, I believe that's incorrect behavior, the
specification states:

"At least one map, use_device_addr or use_device_ptr clause must appear
on the directive"

So provided one is present, the directive is legal in this case.
Slightly different to its siblings (enter/exit/update) which don't have
use_device_addr/use_device_ptr.
2024-02-22 15:33:48 +01:00
Pranav Bhandarkar
58f45d909d [flang][openmp] - depend clause support in target, target enter/update/exit data constructs (#81610)
This patch adds support in flang for the depend clause in target and
target enter/update/exit constructs. Previously, the following line in a
fortran program would have resulted in the error shown below it.

    !$omp target map(to:a) depend(in:a)


"not yet implemented: Unhandled clause DEPEND in TARGET construct"
2024-02-21 11:28:25 -06:00
harishch4
40fae67a50 [Flang][OpenMP] Fix to construct-names inside OpenMP construct with default(none) (#82479)
When a do loop with a construct-name is used inside OpenMP construct
with default(none), an incorrect error will be raised as below.

```
program cn_and_default
    implicit none
    integer :: i

    !$omp parallel default(none)
        loop: do i = 1, 10
        end do loop
    !$omp end parallel
end program
```

> The DEFAULT(NONE) clause requires that 'loop' must be listed in a
data-sharing attribute clause

This patch fixes this by adding a condition to check and skip processing
construct-names.
2024-02-21 17:44:54 +05:30
Mats Petersson
b2b3a52485 Skip compiler directives between OMP PARALLEL DO and the loop (#81021)
This fixes a compilation error when code like this is presented to the
compiler:

  !$OMP PARALLEL DO
  !DIR$ VECTOR ALIGNED
  DO 20 i=1,N
     a = a + 0.5
20   CONTINUE

The directive itself is later ignored (with a warning that this is
happening), but because the compiler already errored out before that
point, it completely fails to compile this code. Other compilers accept
the code without complaints.
2024-02-09 18:05:51 +00:00
Leandro Lupori
e6866955f6 [flang][OpenMP] Accept firstprivate vars in copyprivate (#80467)
This is patch 1 of 4, to add support for COPYPRIVATE.
Original PR: https://github.com/llvm/llvm-project/pull/73128
2024-02-06 10:02:42 -03:00
Kiran Chandramohan
3ae87467a6 [Flang][OpenMP] Avoid default none errors for seq loop indices in par… (#76258)
…allel
2024-01-15 16:07:43 +00:00
Leandro Lupori
9edcf7a28e [flang][driver] Add support for -isysroot in the frontend (#77365)
If DEFAULT_SYSROOT is not specfied when building flang, then the
-isysroot flag is needed to link binaries against system libraries
on Darwin. It's also needed when linking against a non-default
sysroot.
2024-01-11 10:37:58 -03:00
Raghu Maddhipatla
decf0277a7 [Flang][OpenMP][Semantics] Modify errors to warnings for semantic checks in IS_DEVICE_PTR related to list-items being dummy arguments. (#74370)
Changed semantic check from giving error to giving a warning about
deprecation from OpenMP 5.2 and later about checks for dummy argument
list-items present on IS_DEVICE_PTR clause.

This P is blocker for
https://github.com/llvm/llvm-project/pull/71255
2023-12-08 16:06:03 -06:00
Kiran Kumar T P
666a61972f [Flang] Add semantic check for usage of COPYPRIVATE and NOWAIT clauses (#73486)
1. COPYPRIVATE clause should be specified on END SINGLE construct.
2. NOWAIT clause should be specified on END DO/DO SIMD/SINGLE/SECTIONS
construct.

Special handling for semantic checks for nowait/copyprivate clause is
needed in Fortran due to the fact that Openmp pragmas for C/C++ doesn't
have end directive (clause). nowait/copyprivate clauses are allowed in
begin directive clause lists for C/C++ and it is not allowed for
Fortran.
2023-12-04 17:27:24 +05:30
Kiran Chandramohan
63a6e51f8a [Flang][OpenMP] Fix issue with empty critical or critical without surrounding context (#71944)
Add the sourcerange for critical directive.

Fixes #65571
2023-11-27 15:56:39 +00:00
Shraiysh
8840eb3fb5 [flang][OpenMP] Add semantic check for declare target (#72770) 2023-11-22 16:13:14 -06:00
Shraiysh
525396a3ae [flang][OpenMP] Add semantic check for device clause (#72789)
This patch adds the following semantic check:

```
The ancestor device-modifier must not appear on the device clause on any
directive other than the target construct.
```
2023-11-20 19:54:22 -06: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
Peter Klausler
1c91d9bdea [flang] Ensure that portability warnings are conditional (#71857)
Before emitting a warning message, code should check that the usage in
question should be diagnosed by calling ShouldWarn(). A fair number of
sites in the code do not, and can emit portability warnings
unconditionally, which can confuse a user that hasn't asked for them
(-pedantic) and isn't terribly concerned about portability *to* other
compilers.

Add calls to ShouldWarn() or IsEnabled() around messages that need them,
and add -pedantic to tests that now require it to test their portability
messages, and add more expected message lines to those tests when
-pedantic causes other diagnostics to fire.
2023-11-13 16:13:50 -08:00
Shraiysh
6846258aa6 [flang][OpenMP] Add semantic check for declare target (#71425)
This patch adds a semantic check for the following:

```
If a list item is a procedure name, it must not be a generic name,
procedure pointer, entry name, or statement function name.
```
2023-11-06 20:42:05 -06:00
Shraiysh
ee1000573e [flang][OpenMP] Add semantic check for target update (#71305)
This patch adds the following semantic check for target update
construct.

```
A list item can only appear in a to or from clause, but not in both.
```
2023-11-06 17:16:14 -06:00
Shraiysh
d6b69a1bb9 [flang][OpenMP] Add semantic checks for is_device_ptr (#71255)
This patch adds the following semantic check for is_device_ptr

```
A list item that appears in an is_device_ptr clause must be a
dummy argument that does not have the ALLOCATABLE, POINTER or
VALUE attribute.
```
2023-11-06 12:07:31 -06:00
Kiran Chandramohan
742d8eb96d [Flang][OpenMP] Dont add PreDetermined Flag if symbol is privatized already (#70931)
If the symbol is already privatized due to a user specification then it
is not required to mark it as PreDetermined. This happens if there is a
sequential loop in a parallel region that has the private specification
for the index of the sequential loop.

Fixes #63143
2023-11-06 16:07:22 +00:00
Shraiysh
97c9c9429c [flang][OpenMP] Added semantic checks for target update (#71270)
This patch adds the following semantic check for target update

```
At least one motion-clause must be specified.
```

A motion clause is either a `to` or a `from` clause.

This patch also adds a test for the following semantic check which was
already supported.

```
At most one nowait clause can appear on the directive.
```
2023-11-04 15:20:43 -05:00
Z572
558c1f123e [Flang][OpenMP] skip CompilerDirective on ResolveOmpTopLevelParts. (#69580)
Fixes #68966
2023-10-28 08:28:55 +08:00
Sergio Afonso
b49f846fe5 [Flang][OpenMP][Sema] Add directive rewrite pass to support atomic_default_mem_order REQUIRES clause
This patch creates the `OmpRewriteMutator` pass that runs at the end of
`RewriteParseTree()`. This pass is intended to make OpenMP-specific mutations
to the PFT after name resolution.

In the case of the `atomic_default_mem_order` clause of the REQUIRES directive,
name resolution results in populating global symbols with information about the
REQUIRES clauses that apply to that scope. The new rewrite pass is then able to
use this information in order to explicitly set the memory order of ATOMIC
constructs for which that is not already specified.

Given that this rewrite happens before semantics checks, the check of the order
in which ATOMIC constructs without explicit memory order and REQUIRES
directives with `atomic_default_mem_order` appear is moved earlier into the
rewrite pass. Otherwise, these problems would not be caught by semantics
checks, since the PFT would be modified by that stage.

This is patch 4/5 of a series splitting D149337 to simplify review.

Depends on D157983.

Differential Revision: https://reviews.llvm.org/D158096
2023-10-19 10:43:37 +01:00
Leandro Lupori
499d41cef2 [flang][OpenMP] Fix threadprivate common blocks (#68739)
Using a threadprivate common block within a nested scope resulted
in compilation errors.

This happened because common block names were being first resolved
to those in the parent scope. Because of this, in a nested scope,
an inner threadprivate directive would be applied to the outter
common block. This caused a 'common_block appears in more than one
data-sharing clause' error.

Also, when a copyin clause in a parallel region tried to use the
common block, getting the inner version of it, their objects would
be missing the threadprivate attribute, causing a 'Non-THREADPRIVATE
object in COPYIN clause' error.

Fixes https://github.com/llvm/llvm-project/issues/61200
2023-10-16 09:12:53 -03:00
David Truby
f35e2d8022 [flang][openmp] Don't mark loop variables with explicit DSA as predetermined (#68723)
This patch fixes a bug where loop variables are always marked as
predetermined
even when they have an explicit data sharing attribute specified.
2023-10-12 13:04:10 +01:00
Nimish Mishra
0ff9625c0a [flang][OpenMP] Added atomic update assignment statement related semantic checks
This patch adds the following semantic checks:

- None of expr, and expr_list (as applicable) may access the same storage location as x

- Atomic update statement should be of the form x = x operator expr or
x = expr operator x or x = intrinsic_procedure(x, expr_list) or x = intrinsic_procedure(expr_list, x)

- expr_list is a comma-separated, non-empty list of scalar expressions. If intrinsic_procedure_name
refers to IAND, IOR, or IEOR, exactly one expression must appear in expr_list

Reviewed By: TIFitis

Differential Revision: https://reviews.llvm.org/D128162
2023-10-03 19:47:53 +05:30
Raghu Maddhipatla
80b571c66c [Flang] [OpenMP] [Semantics] Add semantic support for IS_DEVICE_PTR nd HAS_DEVICE_ADDR clauses on OMP TARGET directive and add more semantic checks for OMP TARGET. (#67290)
Summary of this patch

- Add semantic support for HAS_DEVICE_ADDR and IS_DEVICE_PTR clauses.
- A list item that appears in an IS_DEVICE_PTR clause must be a valid
device pointer for the device data environment.
- A list item may not be specified in both an IS_DEVICE_PTR clause and a
HAS_DEVICE_ADDR clauses on the directive.
- A list item that appears in an IS_DEVICE_PTR or a HAS_DEVICE_ADDR
clauses must not be specified in any data-sharing attribute clause on
the same target construct.
2023-09-28 11:50:26 -05:00
Sergio Afonso
edc2fb0733 [Flang][OpenMP][Sema] Support propagation of REQUIRES information across program units
Re-land commit 3787fd942f

This patch adds support for storing OpenMP REQUIRES information in the
semantics symbols for programs/subprograms and modules/submodules, and
populates them during directive resolution. A pass is added to name resolution
that makes sure this information is also propagated across top-level programs,
functions and subprograms.

Storing REQUIRES information inside of semantics symbols will also allow
supporting the propagation of this information across Fortran modules. This
will come as a separate patch.

The `bool DirectiveAttributeVisitor::Pre(const parser::SpecificationPart &x)`
method is removed since it resulted in specification parts being visited twice.

This is patch 3/5 of a series splitting D149337 to simplify review.

Differential Revision: https://reviews.llvm.org/D157983
2023-09-11 15:01:57 +01:00
Sergio Afonso
4b9259b947 Revert "[Flang][OpenMP][Sema] Support propagation of REQUIRES information across program units"
Changes in this commit make some gfortran tests crash the compiler. It is
likely trying to dereference undefined symbol pointers.

This reverts commit 3787fd942f.
2023-09-11 13:01:29 +01:00
Sergio Afonso
3787fd942f [Flang][OpenMP][Sema] Support propagation of REQUIRES information across program units
This patch adds support for storing OpenMP REQUIRES information in the
semantics symbols for programs/subprograms and modules/submodules, and
populates them during directive resolution. A pass is added to name resolution
that makes sure this information is also propagated across top-level programs,
functions and subprograms.

Storing REQUIRES information inside of semantics symbols will also allow
supporting the propagation of this information across Fortran modules. This
will come as a separate patch.

The `bool DirectiveAttributeVisitor::Pre(const parser::SpecificationPart &x)`
method is removed since it resulted in specification parts being visited twice.

This is patch 3/5 of a series splitting D149337 to simplify review.

Differential Revision: https://reviews.llvm.org/D157983
2023-09-11 11:48:07 +01:00
Ethan Luis McDonough
9ac5b1f1b2 [flang][openmp] Semantic check for OpenMPExecutableAllocate
Executable allocate directives require that list items show up in the corresponding allocate statement.  This patch is dependent on revision D150428 and applies the semantic check introduced there to allocate directives associated with allocate statements.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D150483
2023-09-08 13:03:04 -05:00
Raghu Maddhipatla
6d1c183c6f [Flang] [OpenMP] [Semantics] Add missing semantic check for MAP clause.
Added support for following semantic check for MAP clause.
  - A list item cannot appear in both a map clause and a data-sharing attribute clause on the same target construct.

Reviewed By: NimishMishra

Differential Revision: https://reviews.llvm.org/D158807
2023-09-07 15:42:25 -05:00
Nimish Mishra
1c4c9e8e70 [flang][OpenMP] Added semantic checks for atomic capture, write, and update statements
This patch adds general checks for atomic read, write, and capture statements.

-check "capture statement is of the form v = x if atomic construct is read"
-check "write statement is of the form x = expr if atomic construct is write"
-check "x must not have the ALLOCATABLE attribute."
-check for non-scalar variables
-check if x (LHS variable) is accessed on the RHS of assignment statement
-improve error reporting in atomic update statemen

Reviewed By: TIFitis, raghavendhra

Differential Revision: https://reviews.llvm.org/D127620
2023-08-27 03:44:40 +00:00
Sergio Afonso
2221b758d2 [Flang][OpenMP][Sema] Add semantics checks for REQUIRES directive
This patch adds semantics checks for REQUIRES directives appearing after other
directives that are affected by them. In particular, it adds checks for device
constructs appearing after device-related REQUIRES directives and for the
`atomic_default_mem_order` clause appearing after atomic operations where the
memory order is not explicitly specified.

This is patch 2/5 of a series splitting D149337 to simplify review.

Depends on D157710.

Differential Revision: https://reviews.llvm.org/D157722
2023-08-15 12:38:14 +01:00
Sergio Afonso
6a1be11b6c [Flang][OpenMP][Parser] Add clause list source location to REQUIRES directive
This patch fixes a problem in the representation of the clause list for the
REQUIRES directive. Location information was not present, making error messages
not very descriptive.

This is patch 1/5 of a series splitting D149337 to simplify review.

Differential Revision: https://reviews.llvm.org/D157710
2023-08-15 11:14:05 +01:00
Raghu Maddhipatla
9c2d54e96d [OpenMP] [Flang] [Semantics] Add a missing semantic check for OMP DISTRIBUTE directive.
Added semantic support for following restriction which applies to OMP DISTRIBUTE directives

  - A list item may appear in a firstprivate or lastprivate clause but not both.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D157465
2023-08-09 13:03:28 -05: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
Raghu Maddhipatla
71d763b88d [OpenMP] [Semantics] [Flang] Adding more semantic checks for USE_DEVICE_PTR and USE_DEVICE_ADDR clauses.
The following restrictions for USE_DEVICE_PTR and USE_DEVICE_ADDR clauses on OMP TARGET DATA directive are implemented in this patch.

  - A list item may not be specified more than once in use_device_ptr clauses that appear on the directive.
  - A list item may not be specified more than once in use_device_addr clauses that appear on the directive.
  - A list item may not be specified in both a use_device_addr clause and a use_device_ptr clause on the directive.
  - A list item that appears in a use_device_ptr or use_device_addr clause must not be a structure element.
  - A list item that appears in a use_device_ptr must be of type C_PTR.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D155133
2023-08-04 00:19:36 -05:00
Ethan Luis McDonough
7f0d54b429 [flang][openmp] Allocators construct semantic checks
This patch applies the semantic checks for executable allocation directives to the new allocators construct.  It also introduces a new check that ensures all items in the list appear in the corresponding Fortran allocate statement.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D150428
2023-08-02 12:59:06 -05:00
Kiran Chandramohan
8acae1a88b [Flang][OpenMP] Add source range for a few directives
The sourcerange was missing for a few directives when
they were the first directive to appear in a program
without a program statement.

Reviewed By: DavidTruby

Differential Revision: https://reviews.llvm.org/D153634
2023-07-05 13:27:52 +00:00
Raghu Maddhipatla
f36a25479b [Flang] [OpenMP] [Semantics] Change SIMD ALIGNED clause support from parsing a std::list<Name> to OmpObjectlist
This is an assisting patch which is implemented to address review comment to switch std::list<Name> to OmpObjectlist from https://reviews.llvm.org/D142722.

Also addressed a semantic check https://github.com/llvm/llvm-project/issues/61161 OpenMP 5.2 standard states that only pointer variables (C_PTR, Cray pointers, POINTER or ALLOCATABLE items) can appear in SIMD aligned clause (section 5.11). And not to allow common block names on an ALIGNED clause.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D152637
2023-06-29 17:24:54 -05:00
Andrew Gozillon
70fc081f74 [Flang][OpenMP][Parser] Resolve Declare Target Directive Symbols
Currently symbols are not resolved for declare target
after they've been modified by prior passes. This can
lead to missing or incorrect symbols in subsequent
compiler phases when declare target is used with
more complex types e.g. common block.

This patch should allow these symbols to be
resolved appropriately.

Reviewers: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D151993
2023-06-02 14:28:48 -05:00
Raghu Maddhipatla
608fe0b032 [Flang][OpenMP][Semantics] Added missing HostAssoc check for use_device_ptr test.
Missed adding this check in previous commit so adding it through separate commit.

Reviewed By: raghavendhra

Differential Revision: https://reviews.llvm.org/D150626
2023-05-16 12:42:13 -05:00
Raghu Maddhipatla
f85a8456f1 [OpenMP][Flang][Semantics] Add semantics support for USE_DEVICE_ADDR clause on OMP TARGET DATA directive.
Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D149815
2023-05-10 19:17:47 -05:00
Andrew Gozillon
39b747d0b5 [Flang][OpenMP][Sema] More gracefully handle undefined symbol in a no implicit module for declare target
Prior to this change, if you define a module as such with a declare target in it:

module test_0
    implicit none
!$omp declare target(no_implicit_materialization_1)
end module test_0

The compiler will crash rather than give some form of reasonable
diagnostic. This patch attempts to fix that.

Reviewers: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D149913
2023-05-05 06:29:51 -05:00
Raghu Maddhipatla
d6ef90f64c [OpenMP][Flang][Semantics] Add semantics support for USE_DEVICE_PTR clause on OMP TARGET DATA directive.
Initial support for USE_DEVICE_PTR clause on OMP TARGET DATA directive.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D148254
2023-04-26 20:17:12 -05:00