224 Commits

Author SHA1 Message Date
kwyatt-ext
79f5bc4927
[flang] Implemented the RANK clause of an attr-spec, per the Fortran 2023 Standard (#176979)
This implements the RANK clause per the Fortran 2023 Standard. This
includes both the parsing/semantics and un-parsing functionality. It is
a fairly straight-forward change.

An executable test was added that tests the examples from the Fortran
2023 What's New document.

check-flang, check-flang-rt, and llvm-lit tests have been executed
against this change.

---------

Co-authored-by: Kevin Wyatt <kwyatt@hpe.com>
2026-01-27 11:16:17 -05:00
Krzysztof Parzyszek
d542fac6b1
[flang] Add traits to more AST nodes (#175578)
Follow-up to PR175211.

There are still a few AST nodes that don't have any of the standard
traits (Wrapper/Tuple/etc). Because of that they require special
handling in the parse tree visitor.

Convert a subset of these nodes to the typical format, and remove the
special cases from the parse tree visitor.

The members of these nodes were frequently used, so instead of
extracting them by hand each time use helper member functions to access
them.
2026-01-20 09:57:35 -06:00
Krzysztof Parzyszek
b8fec8ebc6
[flang] Add traits to more AST nodes (#175566)
Follow-up to PR175211.

There are still a few AST nodes that don't have any of the standard
traits (Wrapper/Tuple/etc). Because of that they require special
handling in the parse tree visitor.

Convert a subset of these nodes to the typical format, and remove the
special cases from the parse tree visitor.
2026-01-20 08:00:00 -06:00
Krzysztof Parzyszek
568b8e4873
[flang] Add traits to several AST nodes (#175065)
There are quite a few AST nodes that don't have any of the standard
traits (Wrapper/Tuple/etc). Because of that they require special
handling in the parse tree visitor.

Convert a subset of these nodes to the typical format, and remove the
special cases from the parse tree visitor.
2026-01-08 18:26:48 -06:00
Peter Klausler
16ecf40aea
[flang] Improve parser error recovery (#173803)
A bad I/O control specification ("NML=123" in this case) triggers an
assertion when parsing fails but emits no error message. The message was
lost when combining failed alternative parse states. Make
CombineFailedParses() take more care to not discard messages; then also
strengthen I/O control specification error recovery so that the original
test case doesn't just elicit a confusing complaint about a missing
expected "*" at the site of the "NML" keyword.

Fixes https://github.com/llvm/llvm-project/issues/173522.
2025-12-31 12:43:28 -08:00
Krzysztof Parzyszek
d49c75234c
[flang][OpenMP] Allow INIT clause on DEPOBJ, add depinfo-modifier (#173056)
Co-authored-by: Kareem Ergawy <kareem.ergawy@amd.com>
2025-12-29 08:02:10 -06:00
Krzysztof Parzyszek
1298b3b444
[flang][OpenMP] Order Unparse functions for OpenMP classes, NFC (#173391) 2025-12-23 10:13:36 -06:00
Krzysztof Parzyszek
603904fa19
[flang][OpenMP] Make OmpDependenceKind be a common enum, NFC (#172871)
In OpenMP 6.0 a subset of the dependence types is also used in the
`depinfo-modifier` on INIT clause. Make the enum be a common type to
avoid defining separate enum types with mostly identical members.

Use the name `OmpDependenceKind` because the other obvious candidate,
OmpDependenceType, used to be a modifier name in older OpenMP specs.
2025-12-18 10:23:57 -06:00
Krzysztof Parzyszek
0096bda38a
[flang][OpenMP] Rename few types to spec names, NFC (#171845)
Change Severity to SevLevel and TargetSync to Targetsync.
2025-12-11 10:52:03 -06:00
Krzysztof Parzyszek
dd63dff83a
[flang][OpenMP] Parse OpenMP 6.0 syntax of INIT clause (#171702)
This includes `FR(...)` for foreign runtime identifiers and `ATTR(...)`
for extensions. Do not store string runtime ids as character literals in
the AST. Use parser::Expr instead, since lowering would require
evaluate::Expr for these ids, and we get evaluate::Expr from
parser::Expr automatically.

Use OpenMP 6.0 naming for AST nodes (since it's the "current" one).
2025-12-11 08:08:14 -06:00
Krzysztof Parzyszek
126748840d
[flang][OpenMP] Frontend support for DIMS modifier (#171454)
Add parsing and semantic checks for DIMS modifier on NUM_TEAMS,
NUM_THREADS, and THREAD_LIMIT.
2025-12-10 11:32:20 -06:00
Anchu Rajendran S
b08c72b26c
[Flang][OpenMP] Enables parsing of threadset clause (#169856) 2025-12-08 07:47:05 -08:00
Krzysztof Parzyszek
cb5362a433
[flang][OpenMP] Rename OmpLoopRangeClause to OmpLooprangeClause, NFC (#170370)
The convention is to change spelling from snake_case to UpperCamel, and
use the result as a stem in derived names, e.g.
- spelling is "some_clause" -> stem is SomeClause
- spelling is "someclause" -> stem is Someclause

Member of the OmpClause variant is <stem> itself, e.g. Looprange as in
parser::OmpClause::Looprange.

Specific clause class name is Omp<stem>Clause, e.g. OmpLooprangeClause.
2025-12-03 07:35:33 -06:00
Tom Eccles
5ccf8c90d1
[flang] implement VECTOR VECTORLENGTH directive (#170114)
This should match exactly the llvm attributes generated by classic
flang.
2025-12-03 09:36:22 +00:00
Krzysztof Parzyszek
a3d7724908
[flang][OpenMP] Make OmpDirectiveSpecification::Flags an EnumSet (#169713)
The idea is that there can be multiple flags on a given directive. When
"Flags" was a simple enum, only one flag could have been set at a time.
2025-11-28 08:41:40 -06:00
Krzysztof Parzyszek
06fc87bcd3
[flang][OpenMP] Better diagnostics for invalid or misplaced directives (#168885)
Add two more AST nodes, one for a misplaced end-directive, and one for
an invalid string following the OpenMP sentinel (e.g. "!$OMP XYZ").

Emit error messages when either node is encountered in semantic
analysis.
2025-11-23 07:55:10 -06:00
Krzysztof Parzyszek
e70e9ec3b8
[flang][OpenMP] Store Block in OpenMPLoopConstruct, add access functions (#168078)
Instead of storing a variant with specific types, store parser::Block as
the body. Add two access functions to make the traversal of the nest
simpler.

This will allow storing loop-nest sequences in the future.
2025-11-17 08:02:36 -06:00
Jean-Didier PAILLEUX
3b83e7fa4e
[flang] Implement !DIR$ IVDEP directive (#133728)
This directive tells the compiler to ignore vector dependencies in the
following loop and it must be placed before a `do loop`.

Sometimes the compiler may not have sufficient information to decide
whether a particular loop is vectorizable due to potential dependencies
between iterations and the directive is here to tell to the compiler
that vectorization is safe with `parallelAccesses` metadata.

This directive is also equivalent to `#pragma clang loop assume(safety)`
in C++
2025-11-14 14:06:46 +01:00
Krzysztof Parzyszek
5d062bf0cc
[flang][OpenMP] Replace modifiers in DYN_GROUPPRIVATE clause (#166199)
The "prescriptiveness" modifier has been replaced with
"fallback-modifier". The "fallback" value has been removed from the
"prescriptiveness" modifier.
2025-11-11 08:01:52 -06:00
Thirumalai Shaktivel
cf1f871023
[Flang] Add parser support for prefetch directive (#139702)
Implementation details:
* Recognize prefetch directive in the parser as `!dir$ prefetch ...`
* Unparse the prefetch directive
* Add required tests

Details on the prefetch directive:
`!dir$ prefetch designator[, designator]...`, where the designator list
can be a variable or an array reference. This directive is used to
insert a hint to the code generator to prefetch instructions for
memory references.
2025-11-10 09:44:22 +05:30
Jean-Didier PAILLEUX
87fb7b002d
[flang] Adding NOTIFY specifier in image selector and add notify type checks (#148810)
This PR adds support for the NOTIFY specifier in the image selector as
described in the 2023 standard, and add checks for the NOTIFY_TYPE type.
2025-11-05 16:35:25 +01:00
Krzysztof Parzyszek
3d3fab17f5
[flang][OpenMP] Use OmpDirectiveSpecification in ALLOCATE (#165865)
The ALLOCATE directive has two forms:
- A declarative form with a standalone directive:
  ```
  !$OMP ALLOCATE (variable-list-item...)
  ```
- An executable form that consists of several directives followed by an
ALLOCATE statement:
  ```
  !$OMP ALLOCATE (variable-list-item...)
  !$OMP ALLOCATE (variable-list-item...)
  ...
  ALLOCATE (...)
  ```

The second form was deprecated in OpenMP 5.2 in favor of the ALLOCATORS
construct.

Since in the parse tree every type corresponding to a directive only
corresponds to a single directive, the executable form is represented by
a sequence of nested OmpAllocateDirectives, e.g.
```
   !$OMP ALLOCATE(x)
   !$OMP ALLOCATE(y)
   ALLOCATE(x, y)
```
will become
```
   OmpAllocateDirective
   |- ALLOCATE(x)            // begin directive
   `- OmpAllocateDirective   // block
      |- ALLOCATE(y)            // begin directive
      `- ALLOCATE(x, y)         // block
```
With this change all AST nodes for directives use
OmpDirectiveSpecification as the directive representation.
2025-11-03 07:37:13 -06:00
Krzysztof Parzyszek
ab049891cd
[flang][OpenMP] Reorganize ALLOCATE-related semantic checks (#165719)
For ALLOCATORS and executable ALLOCATE first perform list item checks in
the context of an individual ALLOCATE clause or directive respectively,
then perform "global" checks, e.g. whether all list items are present on
the ALLOCATE statement.

These changes allowed to simplify the checks for presence on ALLOCATE
statement and the use of a predefined allocator.

Additionally, allow variable list item lists to be empty, add a test for
the related spec restriction.

This is a first step towards unifying OpenMPDeclarativeAllocate and
OpenMPExecutableAllocate into a single directive.
2025-11-03 06:58:59 -06:00
Krzysztof Parzyszek
cd40bc487a
[flang][OpenMP] Implement OpenMP stylized expressions (#165049)
Consider OpenMP stylized expression to be a template to be instantiated
with a series of types listed on the containing directive (currently
DECLARE_REDUCTION). Create a series of instantiations in the parser,
allowing OpenMP special variables to be declared separately for each
type.

---------

Co-authored-by: Tom Eccles <tom.eccles@arm.com>
2025-10-28 12:45:04 -05:00
Jean-Didier PAILLEUX
c1779f33bd
[flang] Implement !DIR$ [NO]INLINE and FORCEINLINE directives (#134350)
This patch adds the support of these two directives : `!dir$ inline` and
`!dir$ noinline`.
- `!dir$ noinline` tells to the compiler to not perform inlining on
specific function calls by adding the `noinline` metadata on the call.
- `!dir$ inline` tells to the compiler to attempt inlining on specific
function calls by adding the `inlinehint` metadata on the call.
- `!dir$ forceinline` tells to the compiler to always perfom inlining on
specific function calls by adding the `alwaysinline` metadata on the
call.

Currently, these directives can be placed before a `DO LOOP`, call
functions or assignments. Maybe other statements can be added in the
future if needed.

For the `inline` directive the correct name might be `forceinline` but
I'm not sure ?
2025-10-28 08:02:15 +01:00
Krzysztof Parzyszek
b2c8b07f79
[flang][OpenMP] Rename some AST classes to follow spec naming, NFC (#164870)
Rename OmpTypeSpecifier to OmpTypeName, since it represents a type-name
list item. Also, OpenMP 6.0 introduced type-specifier with a different
meaning.

Rename OmpReductionCombiner to OmpCombinerExpression.
2025-10-23 14:00:40 -05:00
Krzysztof Parzyszek
9d0c211b14
[flang][OpenMP] Frontend support for ATTACH modifier (#163608)
Add parsing, semantic checks, but no lowering.
2025-10-16 06:51:34 -05:00
Walter J.T.V
cd4c5280c7
[Clang][OpenMP][LoopTransformations] Implement "#pragma omp fuse" loop transformation directive and "looprange" clause (#139293)
This change implements the fuse directive, `#pragma omp fuse`, as specified in the OpenMP 6.0, along with the `looprange` clause in clang.

This change also adds minimal stubs so flang keeps compiling (a full implementation in flang of this directive is still pending).

---------

Co-authored-by: Roger Ferrer Ibanez <roger.ferrer@bsc.es>
2025-09-29 07:48:18 +02:00
Krzysztof Parzyszek
80beefa539
[flang][OpenMP] Use OmpDirectiveSpecification in REQUIRES (#160595) 2025-09-27 08:10:55 -05:00
Krzysztof Parzyszek
17bfec5629
[flang][OpenMP] Use OmpDirectiveSpecification in ASSUMES (#160591) 2025-09-27 07:33:50 -05:00
Krzysztof Parzyszek
727aad15f0
[flang][OpenMP] Use OmpDirectiveSpecification in DECLARE_TARGET (#160573) 2025-09-26 15:47:31 -05:00
Krzysztof Parzyszek
e2585583ae
[flang][OpenMP] Use OmpDirectiveSpecification in DECLARE_SIMD (#160390) 2025-09-25 10:42:32 -05:00
Krzysztof Parzyszek
3bfcbfc327
[flang][OpenMP] Use OmpDirectiveSpecification in DECLARE_VARIANT (#160371) 2025-09-25 09:38:29 -05:00
Krzysztof Parzyszek
d73ffe57f9
[flang][OpenMP] Introduce variant argument, customize OmpArgument par… (#160372)
…sing

The DECLARE_VARIANT directive takes two names separated by a colon as an
argument: base-name:variant-name. Define OmpBaseVariantNames to
represent this, since no existing argument alternative matches it.

However, there is an issue. The syntax "name1:name2" can be the argument
to DECLARE_VARIANT (if both names are OmpObjects), but it can also be a
reduction-specifier if "name2" is a type. This conflict can only be
resolved once we know what the names are, which is after name resolution
has visited them. The problem is that name resolution has side-effects
that may be (practically) impossible to undo (e.g. creating new symbols,
emitting diagnostic messages).

To avoid this problem this PR makes the parsing of OmpArgument
directive- sensitive: when the directive is DECLARE_VARIANT, don't
attempt to parse a reduction-specifier, consider OmpBaseVariantNames
instead. Otherwise ignore OmpBaseVariantNames in favor of
reduction-specifier.
2025-09-25 07:58:57 -05:00
Krzysztof Parzyszek
31941d6476
[flang][OpenMP] Avoid extra newline when unparsing OmpReductionCombiner (#160200)
When the combiner contains an AssignmentStmt, the unparser for that will
emit a newline after the assignment. Don't let it do that, unparse the
assignment ourselves.
2025-09-23 13:01:38 -05:00
Krzysztof Parzyszek
a4168a6859
[flang][OpenMP] Use OmpDirectiveSpecification in DECLARE_REDUCTION (#160192) 2025-09-23 12:06:16 -05:00
Krzysztof Parzyszek
3ca59104cf
[flang][OpenMP] Use OmpDirectiveSpecification in DECLARE_MAPPER (#160169) 2025-09-23 08:50:15 -05:00
Krzysztof Parzyszek
72f3b1c1af
[flang][OpenMP] Simplify handling of UserReductionDetails a bit (#159944)
Instead of having a variant with specific AST nodes that can contain a
reduction specifier, simply store the OpenMPDeclarativeConstruct. It is
used to emit the source code directive when generating a module file,
and unparsing the top-level AST node will work just fine.
2025-09-22 13:18:18 -05:00
Krzysztof Parzyszek
c075feef37
[flang][OpenMP] Use OmpDirectiveSpecification in utility directives (#159585) 2025-09-22 13:01:05 -05:00
Krzysztof Parzyszek
dfad9837d6
[flang][OpenMP] Use OmpDirectiveSpecification in METADIRECTIVE (#159577) 2025-09-22 12:35:21 -05:00
Krzysztof Parzyszek
ad5778ff16
[flang][OpenMP] Use OmpDirectiveSpecification in THREADPRIVATE (#159632)
Since ODS doesn't store a list of OmpObjects (i.e. not as
OmpObjectList), some semantics-checking functions needed to be updated
to operate on a single object at a time.
2025-09-22 10:42:58 -05:00
Krzysztof Parzyszek
d89de09cb1
[flang][OpenMP] Reject blank common blocks more gracefully (#159626)
Parse them as "invalid" OmpObjects, then emit a diagnostic in semantic
checks.
2025-09-22 09:56:31 -05:00
Krzysztof Parzyszek
8c189327e5
[flang][OpenMP] Use OmpDirectiveSpecification in SECTIONS (#159580) 2025-09-19 10:50:23 -05:00
Krzysztof Parzyszek
e75e28ad3c
[flang][OpenMP] Use OmpDirectiveSpecification in Omp[Begin|End]LoopDi… (#159087)
…rective

This makes accessing directive components, such as directive name or the
list of clauses simpler and more uniform across different directives. It
also makes the parser simpler, since it reuses existing parsing
functionality.

The changes are scattered over a number of files, but they all share the
same nature:
- getting the begin/end directive from OpenMPLoopConstruct,
- getting the llvm::omp::Directive enum, and the source location,
- getting the clause list.
2025-09-16 11:38:03 -05:00
Krzysztof Parzyszek
88b71e2048
[flang][OpenMP] Replace OpenMPBlockConstruct with OmpBlockConstruct (#155872)
OpenMPBlockConstruct, somewhat confusingly, represents most but not all
block-associated constructs. It's derived from OmpBlockConstruct, as are
all the remaining block-associated constructs.

It does not correspond to any well-defined group of constructs. It's the
collection of constructs that don't have their own types (and those that
do have their own types do so for their own reasons).

Using the broader OmpBlockConstruct in type-based visitors won't cause
issues, because the specific overloads (for classes derived from it)
will always be preferred.
2025-08-29 07:37:48 -05:00
Krzysztof Parzyszek
870866f500
[flang][OpenMP] Fix parsing of ASSUME directive (#155257)
The ASSUME directive is block-associated and whether the end-directive
is optional or not depends on the form of the block. This is all taken
care of automatically since the AST node for ASSUME inherits from
OmpBlockConstruct.
2025-08-27 07:31:52 -05:00
Krzysztof Parzyszek
3870e5450c
[flang][OpenMP] Delete no longer used Omp[End]CriticalDirective, NFC (#155099) 2025-08-26 08:20:24 -05:00
Tom Eccles
044e1aabbd
[flang][OpenMP] move omp end sections validation to semantics (#154740)
See #90452. The old parse tree errors exploded to thousands of unhelpful
lines when there were multiple missing end directives.

Instead, allow a missing end directive in the parse tree then validate
that it is present during semantics (where the error messages are a lot
easier to control).
2025-08-26 10:45:56 +00:00
Krzysztof Parzyszek
42350f428d
[flang][OpenMP] Parse GROUPPRIVATE directive (#153807)
No semantic checks or lowering yet.
2025-08-19 08:32:43 -05:00
Krzysztof Parzyszek
8429f7faaa
[flang][OpenMP] Parsing support for DYN_GROUPPRIVATE (#153615)
This does not perform semantic checks or lowering.
2025-08-18 13:35:02 -05:00