77 Commits

Author SHA1 Message Date
swatheesh-mcw
fe30cf18ab
Revert "Revert "[flang][openmp] Adds Parser and Semantic Support for Interop Construct, and Init and Use Clauses."" (#132343)
Reverts llvm/llvm-project#132005
2025-03-28 15:21:52 +00:00
Michael Kruse
27539c3f90 Revert "[Flang] Remove FLANG_INCLUDE_RUNTIME (#124126)"
The production buildbot master apparently has not yet been restarted
since https://github.com/llvm/llvm-zorg/pull/393 landed.

This reverts commit 96d1baedefc3581b53bc4389bb171760bec6f191.
2025-03-26 19:02:13 +01:00
Michael Kruse
96d1baedef
[Flang] Remove FLANG_INCLUDE_RUNTIME (#124126)
Remove the FLANG_INCLUDE_RUNTIME option which was replaced by
LLVM_ENABLE_RUNTIMES=flang-rt.

The FLANG_INCLUDE_RUNTIME option was added in #122336 which disables the
non-runtimes build instructions for the Flang runtime so they do not
conflict with the LLVM_ENABLE_RUNTIMES=flang-rt option added in #110217.
In order to not maintain multiple build instructions for the same thing,
this PR completely removes the old build instructions (effectively
forcing FLANG_INCLUDE_RUNTIME=OFF).

As per discussion in
https://discourse.llvm.org/t/buildbot-changes-with-llvm-enable-runtimes-flang-rt/83571/2
we now implicitly add LLVM_ENABLE_RUNTIMES=flang-rt whenever Flang is
compiled in a bootstrapping (non-standalone) build. Because it is
possible to build Flang-RT separately, this behavior can be disabled
using `-DFLANG_ENABLE_FLANG_RT=OFF`. Also see the discussion an
implicitly adding runtimes/projects in #123964.
2025-03-26 18:50:41 +01:00
Krzysztof Parzyszek
68180d8d16
[flang][OpenMP] Use OmpDirectiveSpecification in standalone directives (#131163)
This uses OmpDirectiveSpecification in the rest of the standalone
directives.
2025-03-20 06:50:43 -05:00
Krzysztof Parzyszek
cd26dd5595
[flang][OpenMP] Use OmpDirectiveSpecification in simple directives (#131162)
The `OmpDirectiveSpecification` contains directive name, the list of
arguments, and the list of clauses. It was introduced to store the
directive specification in METADIRECTIVE, and could be reused everywhere
a directive representation is needed.
In the long term this would unify the handling of common directive
properties, as well as creating actual constructs from METADIRECTIVE by
linking the contained directive specification with any associated user
code.
2025-03-19 11:34:40 -05:00
Kiran Chandramohan
96b112fb61
Revert "[flang][openmp] Adds Parser and Semantic Support for Interop Construct, and Init and Use Clauses." (#132005)
Reverts llvm/llvm-project#120584

Reverting due to CI failure
https://lab.llvm.org/buildbot/#/builders/157/builds/22946
2025-03-19 11:13:52 +00:00
swatheesh-mcw
ee8a759bfb
[flang][openmp] Adds Parser and Semantic Support for Interop Construct, and Init and Use Clauses. (#120584)
Adds Parser and Semantic Support for the below construct and clauses:
- Interop Construct
- Init Clause
- Use Clause

Note:
The other clauses supported by Interop Construct such as Destroy, Use,
Depend and Device are added already.
2025-03-19 10:49:17 +00:00
Krzysztof Parzyszek
5ba7a3bd4c
[flang][OpenMP] Parse cancel-directive-name as clause (#130146)
The cancellable construct names on CANCEL or CANCELLATION POINT
directives are actually clauses (with the same names as the
corresponding constructs).

Instead of parsing them into a custom structure, parse them as a clause,
which will make CANCEL/CANCELLATION POINT follow the same uniform scheme
as other constructs (<directive> [(<arguments>)] [clauses]).
2025-03-10 11:58:02 -05:00
Mats Petersson
9925359fee
[flang][llvm][openmp]Add Initializer clause to OMP.td (#129540)
Then use this in the Flang compiler for parsing the OpenMP declare
reduction.

This has no real functional change to the existing code, it's only
moving the declaration itself around.

A few tests has been updated, to reflect the new type names.
2025-03-05 15:41:24 +00:00
Mats Petersson
24b7759a9d
[FLANG][OpenMP]Add frontend support for ASSUME and ASSUMES (#120770)
Enough suport to parse correctly formed directives of !$OMP ASSUME and
!$OMP ASSUMES with teh related clauses that go with them: ABSENT,
CONTAINS, NO_OPENPP, NO_OPENMP_ROUTINES, NO_PARALLELISM and HOLDS.

Tests added for unparsing and dump parse-tree.

Semantics support is very minimal and no specific tests added.

The lowering will hit a TODO, and there are tests in Lower/OpenMP/Todo
to make it clear that this is currently expected behaviour.

---------

Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
Co-authored-by: Krzysztof Parzyszek <Krzysztof.Parzyszek@amd.com>
2025-02-25 17:36:25 +00:00
Michael Kruse
54f37133b7
[Flang][NFC] Move runtime library files to flang-rt (#110298)
Mostly mechanical changes in preparation of extracting the Flang-RT
"subproject" in #110217. This PR intends to only move pre-existing files
to the new folder structure, with no behavioral change. Common files
(headers, testing, cmake) shared by Flang-RT and Flang remain in
`flang/`.

Some cosmetic changes and files paths were necessary:
* Relative paths to the new path for the source files and
`add_subdirectory`.
 * Add the new location's include directory to `include_directories`
* The unittest/Evaluate directory has unitests for flang-rt and Flang. A
new `CMakeLists.txt` was introduced for the flang-rt tests.
 * Change the `#include` paths relative to the include directive
 * clang-format on the `#include` directives
* Since the paths are part if the copyright header and include guards, a
script was used to canonicalize those
* `test/Runtime` and runtime tests in `test/Driver` are moved, but the
lit.cfg.py mechanism to execute the will only be added in #110217.
2025-02-16 13:25:31 +01:00
Michael Kruse
5c8c2b3db5
[Flang] Rename libFortranRuntime.a to libflang_rt.runtime.a (#122341)
Following the conclusion of the
[RFC](https://discourse.llvm.org/t/rfc-names-for-flang-rt-libraries/84321),
rename Flang's runtime libraries as follows:

 * libFortranRuntime.(a|so) to libflang_rt.runtime.(a|so)
 * libFortranFloat128Math.a to libflang_rt.quadmath.a
* libCufRuntime_cuda_${CUDAToolkit_VERSION_MAJOR}.(a|so) to
libflang_rt.cuda_${CUDAToolkit_VERSION_MAJOR}.(a|so)

This follows the same naming scheme as Compiler-RT libraries
(`libclang_rt.${component}.(a|so)`). It provides some consistency
between Flang's runtime libraries for current and potential future
library components.
2025-02-08 18:02:54 +01:00
Michael Kruse
e6e8ac59ba
[Flang] Optionally do not compile the runtime in-tree (#122336)
Introduce the CMake switch FLANG_INCLUDE_RUNTIME. When set to off, do
not add build instructions for the runtime.

This is required for Flang-RT (#110217) and the current runtime CMake
code to co-exist. When using `LLVM_ENABLE_RUNTIME=flang-rt`, the in-tree
build instructions are in conflict and must be disabled.
2025-02-08 01:06:27 +01:00
Krzysztof Parzyszek
e8100c399b
[flang][OpenMP] Handle directive arguments in OmpDirectiveSpecifier (#124278)
Implement parsing and symbol resolution for directives that take
arguments. There are a few, and most of them take objects. Special
handling is needed for two that take more specialized arguments: DECLARE
MAPPER and DECLARE REDUCTION.

This only affects directives in METADIRECTIVE's WHEN and OTHERWISE
clauses. Parsing and semantic checks of other cases is unaffected.
2025-02-03 12:58:42 -06:00
Krzysztof Parzyszek
6dfe20dbbd
[flang][OpenMP] Parse METADIRECTIVE in specification part (#123397)
Add METADIRECTIVE to the OpenMP declarative constructs as well. Emit a
TODO error for both declarative and executable cases.
2025-02-03 11:13:44 -06:00
Krzysztof Parzyszek
adeff9f63a
[flang][OpenMP] Allow utility constructs in specification part (#121509)
Allow utility constructs (error and nothing) to appear in the
specification part as well as the execution part. The exception is
"ERROR AT(EXECUTION)" which should only be in the execution part.
In case of ambiguity (the boundary between the specification and the
execution part), utility constructs will be parsed as belonging to the
specification part. In such cases move them to the execution part in the
OpenMP canonicalization code.
2025-01-03 09:21:36 -06:00
Krzysztof Parzyszek
df859f90aa
[flang][OpenMP] Frontend support for NOTHING directive (#120606)
Create OpenMPUtilityConstruct and put the two utility directives in it
(error and nothing). Rename OpenMPErrorConstruct to OmpErrorDirective.
2025-01-03 08:36:34 -06:00
Mats Petersson
75e6d0eb4d
[flang][OpenMP]Add support for OpenMP ERROR directive (#119582)
Lowering leads to a TODO, with a test to confirm.

Also testing unparse.

---------

Co-authored-by: Krzysztof Parzyszek <Krzysztof.Parzyszek@amd.com>
2024-12-13 14:05:48 +00:00
Krzysztof Parzyszek
03cbe42627
[flang][OpenMP] Rework LINEAR clause (#119278)
The OmpLinearClause class was a variant of two classes, one for when the
linear modifier was present, and one for when it was absent. These two
classes did not follow the conventions for parse tree nodes, (i.e.
tuple/wrapper/union formats), which necessitated specialization of the
parse tree visitor.

The new form of OmpLinearClause is the standard tuple with a list of
modifiers and an object list. The specialization of parse tree visitor
for it has been removed.
Parsing and unparsing of the new form bears additional complexity due to
syntactical differences between OpenMP 5.2 and prior versions: in OpenMP
5.2 the argument list is post-modified, while in the prior versions, the
step modifier was a post-modifier while the linear modifier had an
unusual syntax of `modifier(list)`.

With this change the LINEAR clause is no different from any other
clauses in terms of its structure and use of modifiers. Modifier
validation and all other checks work the same as with other clauses.
2024-12-12 12:19:35 -06:00
Krzysztof Parzyszek
33faa8285f
[flang][OpenMP] Use new modifiers in IF/LASTPRIVATE (#118128)
The usual changes, added more references to OpenMP specs.
2024-12-02 16:36:31 -06:00
Krzysztof Parzyszek
bde79c0e27
[flang][OpenMP] Use new modifiers in DEPEND/GRAINSIZE/NUM_TASKS (#117917)
The usual changes, added more references to OpenMP specs.
2024-12-02 15:22:05 -06:00
Krzysztof Parzyszek
05096590e0
[flang][OpenMP] Use new modifiers with AFFINITY/ALIGNED/DEVICE (#117786)
This is a mostly mechanical change from specific modifiers embedded
directly in a clause to the Modifier variant.

Additional comments and references to the OpenMP specs were added.
2024-12-02 10:46:06 -06:00
Krzysztof Parzyszek
608f4ae113
[flang][OpenMP] Rename some Type members in OpenMP clauses (#117784)
The intent is to keep names in sync with the terminology from the OpenMP
spec:
```
  OmpBindClause::Type       -> Binding
  OmpDefaultClause::Type    -> DataSharingAttribute
  OmpDeviceTypeClause::Type -> DeviceTypeDescription
  OmpProcBindClause::Type   -> AffinityPolicy
```
Add more comments with references to the OpenMP specs.
2024-12-02 09:22:30 -06:00
Krzysztof Parzyszek
cdbd22876b
[flang][OpenMP] Use new modifiers in ALLOCATE clause (#117627)
Again, this simplifies the semantic checks and lowering quite a bit.
Update the check for positive alignment to use a more informative
message, and to highlight the modifier itsef, not the whole clause.
Remove the checks for the allocator expression itself being positive:
there is nothing in the spec that says that it should be positive.

Remove the "simple" modifier from the AllocateT template, since both
simple and complex modifiers are the same thing, only differing in
syntax.
2024-12-02 08:11:49 -06:00
Krzysztof Parzyszek
52755ac253
[flang][OpenMP] Use new modifier infrastructure for MAP/FROM/TO clauses (#117447)
This removes the specialized parsers and helper classes for these
clauses, namely ConcatSeparated, MapModifiers, and MotionModifiers. Map
and the motion clauses are now handled in the same way as all other
clauses with modifiers, with one exception: the commas separating their
modifiers are optional. This syntax is deprecated in OpenMP 5.2.

Implement version checks for modifiers: for a given modifier on a given
clause, check if that modifier is allowed on this clause in the
specified OpenMP version. This replaced several individual checks.

Add a testcase for handling map modifiers in a different order, and for
diagnosing an ultimate modifier out of position.
2024-11-25 07:38:12 -06:00
Krzysztof Parzyszek
e79cd24676
[flang][OpenMP] Use new modifier code in ORDER and SCHEDULE clauses (#117081)
This actually simplifies the AST node for the schedule clause: the two
allowed modifiers can be easily classified as the ordering-modifier and
the chunk-modifier during parsing without the need to create additional
classes.
2024-11-21 17:50:37 -06:00
Krzysztof Parzyszek
4fc1141e76
[flang][OpenMP] Apply modifier representation to semantic checks (#116658)
Also, define helper macros in parse-tree.h.

Apply the new modifier representation to the DEFAULTMAP and REDUCTION
clauses, with testcases utilizing the new modifier validation.

OpenMP modifier overhaul: #3/3
2024-11-21 13:18:01 -06:00
Krzysztof Parzyszek
cfd67c2149
[flang][OpenMP] Normalize clause modifiers that exist on their own (#116655)
This is the first part of the effort to make parsing of clause modifiers
more uniform and robust. Currently, when multiple modifiers are allowed,
the parser will expect them to appear in a hard-coded order.
Additionally, modifier properties (such as "ultimate") are checked
separately for each case.

The overall plan is
1. Extract all modifiers into their own top-level classes, and then
equip them with sets of common properties that will allow performing the
property checks generically, without refering to the specific kind of
the modifier.
2. Define a parser (as a separate class) for each modifier.
3. For each clause define a union (std::variant) of all allowable
modifiers, and parse the modifiers as a list of these unions.

The intent is also to isolate parts of the code that could eventually be
auto-generated.

OpenMP modifier overhaul: #1/3
2024-11-20 08:33:17 -06:00
Krzysztof Parzyszek
f87737f3fd
[flang][OpenMP] Parse DOACROSS clause (#115396)
Extract the SINK/SOURCE parse tree elements into a separate class
`OmpDoacross`, share them between DEPEND and DOACROSS clauses. Most of
the changes in Semantics are to accommodate the new contents of
OmpDependClause, and a mere introduction of OmpDoacrossClause.

There are no semantic checks specifically for DOACROSS.
2024-11-11 08:48:51 -06:00
Krzysztof Parzyszek
09a4bcf1a5
[flang][OpenMP] Update handling of DEPEND clause (#113620)
Parse the locator list in OmpDependClause as an OmpObjectList (instead
of a list of Designators). When a common block appears in the locator
list, show an informative message.
Implement resolving symbols in DependSinkVec in a dedicated visitor
instead of having a visitor for OmpDependClause.
Resolve unresolved names common blocks in OmpObjectList.

Minor changes to the code organization:
- rename OmpDependenceType to OmpTaskDependenceType (to follow 5.2
terminology),
- rename Depend::WithLocators to Depend::DepType,
- add comments with more detailed spec references to parse-tree.h.

---------

Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
2024-10-28 16:06:22 -05:00
Kiran Chandramohan
5621929f7f
[Flang][OpenMP] Add parser support for grainsize and num_tasks clause (#113136)
These clauses are applicable only for the taskloop directive. Since the
directive has a TODO error, skipping the addition of TODOs for these
clauses.
2024-10-27 20:16:24 +00:00
Krzysztof Parzyszek
697d65ded6
[flang][OpenMP] Parsing support for map type modifiers (#111860)
This commit adds parsing of type modifiers for the MAP clause: CLOSE,
OMPX_HOLD, and PRESENT. The support for ALWAYS has already existed.

The new modifiers are not yet handled in lowering: when present, a TODO
message is emitted and compilation stops.
2024-10-11 11:38:32 -05:00
Brad Richardson
06eb10dadf
[flang][driver] rename flang-new to flang (#110023)
This does a global rename from `flang-new` to `flang`. I also
removed/changed any TODOs that I found related to making this change.

---------

Co-authored-by: H. Vetinari <h.vetinari@gmx.com>
Co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com>
2024-10-10 09:26:04 +01:00
Jay Foad
d4a0154902
[llvm-project] Fix typo "seperate" (#95373) 2024-06-13 20:20:27 +01:00
khaki3
3af717d661
[flang] Add parsing of DO CONCURRENT REDUCE clause (#92518)
Derived from #92480. This PR supports parsing of the DO CONCURRENT
REDUCE clause in Fortran 2023. Following the style of the OpenMP parser
in MLIR, the front end accepts both arbitrary operations and procedures
for the REDUCE clause. But later Semantics can notify type errors and
resolve procedure names.
2024-05-30 11:34:19 -07:00
Peter Klausler
f2e808932c
[flang] Intermix messages from parser and semantic analysis (#90654)
When there are one or more fatal error messages produced by the parser,
semantic analysis is not performed. But when there are messages produced
by the parser and none of them are fatal, those messages are emitted to
the user before compilation continues with semantic analysis, and any
messages produced by semantics are emitted after the messages from
parsing.

This can be confusing for the user, as the messages may no longer all be
in source file location order. It also makes it difficult to write tests
that check for both non-fatal messages from parsing as well as messages
from semantics using inline CHECK: or other expected messages in test
source code.

This patch ensures that if semantic analysis is performed, and non-fatal
messages were produced by the parser, that all the messages will be
combined and emitted in source file order.
2024-05-01 13:49:33 -07:00
Katherine Rasmussen
a2d7af757b
[flang] Add notify-type and notify-wait-stmt (#76594)
Add `notify-type` to `iso_fortran_env` module. Add `notify-wait-stmt` to
the parser and add checks for constraints on the statement, `C1177` and
`C1178`, from the Fortran 2023 standard. Add three semantics tests for
`notify-wait-stmt`.
2024-01-02 10:40:47 -08:00
Sergio Afonso
edc2fb0733
[Flang][OpenMP][Sema] Support propagation of REQUIRES information across program units
Re-land commit 3787fd942f3927345320cc97a479f13e44355805

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 3787fd942f3927345320cc97a479f13e44355805.
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
Josh Mottley
165f7f06a1 [flang] Bump python dependencies in flang/examples/FlangOmpReport
ruamel.yaml had a potential security issues (may also be a false
positive in scanner).

Related to #64417 https://github.com/llvm/llvm-project/issues/64417

Reviewed By: avogelsgesang

Differential Revision: https://reviews.llvm.org/D157284
2023-08-07 18:00:07 +01:00
Peter Klausler
e12ffe6a93
[flang] Honor #line and related preprocessing directives
Extend the SourceFile class to take account of #line directives
when computing source file positions for error messages.
Adjust the output of #line directives to -E output so that they
reflect any #line directives that were in the input.

Differential Revision: https://reviews.llvm.org/D153910
2023-06-29 08:27:37 -07:00
Valentin Clement
5923e46fce
[flang][openacc] Add parsing support for dim in gang clause
Add parsing supprot for dim in gang clause

Depends on D151971

Reviewed By: razvanlupusoru, jeanPerier

Differential Revision: https://reviews.llvm.org/D151972
2023-06-13 20:33:36 -07:00
Tobias Hieta
f98ee40f4b
[NFC][Py Reformat] Reformat python files in the rest of the dirs
This is an ongoing series of commits that are reformatting our
Python code. This catches the last of the python files to
reformat. Since they where so few I bunched them together.

Reformatting is done with `black`.

If you end up having problems merging this commit because you
have made changes to a python file, the best way to handle that
is to run git checkout --ours <yourfile> and then reformat it
with black.

If you run into any problems, post to discourse about it and
we will try to help.

RFC Thread below:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Reviewed By: jhenderson, #libc, Mordante, sivachandra

Differential Revision: https://reviews.llvm.org/D150784
2023-05-25 11:17:05 +02: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
Ethan Luis McDonough
00d0749f92
[flang] Feature list plugin
Plugin that counts the number of times each tree node occurs in a given program.  Used for test coverage.

Updated to fix build issues.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D143704
2023-04-24 23:41:32 -05:00
Ethan Luis McDonough
22293a3d85
Revert "[flang] Feature list plugin" due to failing build
This reverts commit 823ddba1b325f30fc3fb2e9d695c211b856a4d5d.
2023-03-22 15:49:50 -05:00
Ethan Luis McDonough
823ddba1b3
[flang] Feature list plugin
Plugin that counts the number of times each tree node occurs in a given program.  Used for test coverage.

Updated to fix build issues.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D143704
2023-03-22 01:27:55 -05:00
Valentin Clement
9be446588e
Revert "[flang] Feature list plugin"
This reverts commit bde91fd03f72a25151caa9f8ee2d4572ff14619b.

Failing buildbot: https://lab.llvm.org/buildbot/#/builders/181/builds/15552
2023-03-17 17:59:22 +01:00
Ethan Luis McDonough
bde91fd03f
[flang] Feature list plugin
Plugin that counts the number of times each tree node occurs in a given program.  Used for test coverage.

> One thing we need...is a way to determine what features a code uses. Preferably we would also be able to determine if they are implemented or not. Just the former could be done with a visitor for the parse tree. For the latter we would continue compilation and somehow ignore todo errors but collect them - @jdoerfert

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D143704
2023-03-17 02:28:59 -05:00