390 Commits

Author SHA1 Message Date
Krzysztof Parzyszek
04bc0af103
[flang][OpenMP] Expand GetOmpObjectList to all subclasses of OmpClause (#170351)
Use GetOmpObjectList instead of extracting the object list by hand.
2025-12-04 07:37:13 -06:00
Krzysztof Parzyszek
7c33b8247d
[flang][OpenMP] Move two functions to check-omp-loop.cpp, NFC (#170526)
These are checks for clauses that apply to loop constructs.
2025-12-03 12:30:53 -06: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
Pranav Bhandarkar
28fde68501
[Flang] - Enhance testing for strictly-nested teams in target regions. (#168437)
This patch enhances the semantics test for checking that teams
directives are strictly nested inside target directives.

Fixes https://github.com/llvm/llvm-project/issues/153173
2025-11-24 23:36:41 -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
Ferran Toda
f4ebee0ca9
[Flang][OpenMP] Add semantic support for Loop Sequences and OpenMP loop fuse (#161213)
This patch adds semantics for the `omp fuse` directive in flang, as
specified in OpenMP 6.0. This patch also enables semantic support for
loop sequences which are needed for the fuse directive along with
semantics for the `looprange` clause. These changes are only semantic.
Relevant tests have been added , and previous behavior is retained with
no changes.

---------

Co-authored-by: Ferran Toda <ferran.todacasaban@bsc.es>
Co-authored-by: Krzysztof Parzyszek <Krzysztof.Parzyszek@amd.com>
2025-11-21 08:16:30 -06:00
Krzysztof Parzyszek
17e67b0d9a
[flang][OpenMP] Semantic checks for DYN_GROUPPRIVATE (#166214) 2025-11-11 08:02:30 -06:00
Jack Styles
91e6deeef4
[Flang][OpenMP] Improve Semantics for Derived Type Array Elements (#167296)
Flang does not allow the use of Structure Component types inside of
certain OpenMP clauses. While this has been introduced, it seemed that
Structure Component Array Elements were not being captured as they got
embedded in the parse tree. To ensure all structure component types are
identified, a new `HasStructureComponent` evaluate function has been
introduced to walk a Semantics expression, identified where Components
are used within.

This replaces the previous implementation of `CheckStructureComponent`
which just looked for the StructureComponent inside of a DataRef.

Fixes #150830
2025-11-11 13:31:22 +00:00
Krzysztof Parzyszek
3c81587f6a
[OpenMP] Add definitions for DECLARE_INDUCTION and related clauses (#166235)
Add definitions for DECLARE_INDUCTION, COLLECTOR, and INDUCTOR to
OMP.td.
2025-11-07 06:13:55 -06:00
Krzysztof Parzyszek
24c22b7de6
[flang][OpenMP] Sort and move macro-based clause checks to the end, NFC (#166175) 2025-11-03 09:27:45 -06: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
Ritanya-B-Bharadwaj
25ece5ba92
[clang][OpenMP] New OpenMP 6.0 threadset clause (#135807)
Initial parsing/sema/codegen support for threadset clause in task and
taskloop directives [Section 14.8 in in OpenMP 6.0 spec]

---------
2025-10-30 15:48:13 +05:30
Krzysztof Parzyszek
48cc443a72
[flang][OpenMP] Anonymous BLOCK DATA may not have Symbol at all (#165250)
This fixes https://linaro.atlassian.net/browse/LLVM-2106 and
https://github.com/llvm/llvm-project/issues/164815.
2025-10-27 09:49:58 -05:00
Krzysztof Parzyszek
322dd63004
[flang][OpenMP] Refactor/update semantic checks for ALLOCATE directive (#164420)
OpenMP 5.0 and 5.1 allowed the ALLOCATE directive to appear in two
forms, declarative and executable. The syntax of an individual directive
was the same in both cases, but the semantic restrictions were slightly
different.

- Update the semantic checks to reflect the different restrictions,
gather them in a single function.
- Improve test for the presence of a TARGET region, add a check for
REQUIRES directive.
- Update tests.
2025-10-22 11:46:48 -05:00
Krzysztof Parzyszek
e6af0a40ac
[flang][OpenMP] Keep track of scoping units in OmpStructureChecker (#164419)
Introduce a stack of scopes to OmpStructureChecker for scoping units,
plus function/subroutine entries in interfaces.

This will help with applying and locating properties introduced by
declarative or informational directives (e.g. DECLARE_TARGET, REQUIRES),
which are stored as flags on the corresponding symbols.
2025-10-22 11:46:11 -05:00
Krzysztof Parzyszek
a585448903
[flang][OpenMP] Move check of ALIGN clause to visitor function (#164261)
This replaces CheckAlignValue with an Enter function, and adds a check
that the alignment is a power of 2.
2025-10-21 08:02:46 -05:00
Peter Klausler
5cd9f0f655
[flang] Move parse tree tool to Parser/tools.h (#163998)
Move the parse tree utility function
semantics::getDesignatorNameIfDataRef to Parser/tools.h and rename it to
comply with the local style.
2025-10-20 13:20:33 -07:00
Krzysztof Parzyszek
3590a912da
[flang][OpenMP] Frontend support for DEVICE_SAFESYNC (#163560)
Add parsing and semantic checks for DEVICE_SAFESYNC clause. No lowering.
2025-10-20 08:11:55 -05:00
Peter Klausler
e0bffe1ff9
[flang][NFC] Use parser::Unwrap(Ref) more (#162918)
Replace more parse tree references to "thing" and "value()" with usage
of the parser::Unwrap<> template function.
Add parser::UnwrapRef<> as an alias for DEREF(Unwrap<>()).
2025-10-16 12:20:27 -07:00
Krzysztof Parzyszek
467487f2a1
[flang][OpenMP] Reuse semantic check for "constantness" of alignment (#163624)
Use ScalarIntConstantExpr in the parse tree instead of ScalarIntExpr.
This will still parse a general expression, but the semantic checker for
expressions will automatically perfom a test for whether the value is
constant or not.

Use that instead of manual checks, it will make diagnostics more
uniform. There is no functional change other than that.
2025-10-16 12:00:22 -05:00
Krzysztof Parzyszek
0ca14470fc
[flang][OpenMP] Add optional argument to requirement clauses (#163557)
OpenMP 6.0 added an optional logical parameter to the requirement
clauses (except ATOMIC_DEFAULT_MEM_ORDER) to indicate whether the clause
should take effect or not. The parameter defaults to true if not
specified.

The parameter value is a compile-time constant expression, but it may
require folding to get the final value. Since name resolution happens
before folding, the argument expression needs to be analyzed by hand.
The determination of the value needs to happen during name resolution
because the requirement directives need to be available through module
files (and the module reader doesn't to semantic checks beyond name
resolution).
2025-10-16 11:59: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
Krzysztof Parzyszek
c8b8fa26a2
[flang][OpenMP] Format check-omp-structure.cpp, NFC (#163750)
Only a couple of changes, including adding two empty comments to resolve
differences between different versions of clang-format.
2025-10-16 06:37:18 -05:00
Peter Klausler
e2ee91ed34
[flang] Clean up some optional<bool> usage (#161925)
Audit the use of std::optional<bool> as a tri-state logical value in
flang, correct a couple cases that need ".value_or()", add some explicit
".has_value()" calls, and document the possible pitfalls.
2025-10-10 10:09:02 -07:00
Michael Kruse
375f48942b
[Flang] Add standalone tile support (#160298)
Add support for the standalone OpenMP tile construct:
```f90
!$omp tile sizes(...)
DO i = 1, 100
  ...
```

This is complementary to #143715 which added support for the tile
construct as part of another loop-associated construct such as
worksharing-loop, distribute, etc.
2025-10-03 15:52:48 +02:00
Krzysztof Parzyszek
ba5141d27c
[flang][OpenMP] Check contatining scoping unit in DECLARE_SIMD (#161556)
Check if the name on DECLARE_SIMD is the name of the containing scoping
unit.

Fixes https://github.com/llvm/llvm-project/issues/161516
2025-10-01 16:12:30 -05:00
Krzysztof Parzyszek
6f1f00c243
[flang][OpenMP] Move semantic checks for ALLOCATE to check-omp-structure (#161249)
The checks were previously in resolve-directives, which is mostly
intended for determining symbol properties, not performing semantic
checks.
2025-09-30 08:23:54 -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
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
89d79b65f7
[flang][OpenMP] Semantic checks for TASKGRAPH (#160115)
This verifies the "structural" restrictions on constructs encountered in
a TASKGRAPH construct.

There are also restrictions that apply to list items, specifically in
the following contexts:
- a list item on a clause on a replayable construct,
- data-sharing attributes for a variable on a replayable construct.
These restrictions are not verified, because that would require knowing
which clauses (on a potential compound directive) apply to the task-
generating construct of interest. This information is not available
during semantic checks.
2025-09-22 14:21:12 -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
e2467cbfa8
[flang][OpenMP] Remove no longer used OmpLoopDirective, NFC (#159576) 2025-09-19 09:27:50 -05:00
Ritanya-B-Bharadwaj
af66368ff6
[clang] [OpenMP] New OpenMP 6.0 - Parsing and Sema support for groupprivate (#158134) 2025-09-18 15:31:56 +05:30
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
cdd54ff927
[flang][OpenMP] Frontend support for REPLAYABLE and TRANSPARENT clauses (#158149)
Parsing and semantic checks.
2025-09-12 08:40:00 -05:00
Krzysztof Parzyszek
13547a9a77
[flang][OpenMP] Turn IsStrictlyStructuredBlock into utility function,… (#158111)
… NFC
2025-09-12 08:39:16 -05:00
Krzysztof Parzyszek
00483379fb
[OpenMP] Add definitions of TASKGRAPH, GRAPH_ID and GRAPH_RESET (#157502)
This only adds the definitions of the TASKGRAPH directive and the
associated clauses, plus the minimal additional changes to make
everything compile without errors.
2025-09-10 11:09:32 -05:00
Krzysztof Parzyszek
5520e16d2a
[flang][OpenMP] Parse ORDERED as standalone when DEPEND/DOACROSS is p… (#156693)
…resent

The OpenMP spec 4.5-5.1 defines ORDERED as standalone when a DEPEND
clause is present (with either SOURCE or SINK as argument). The OpenMP
spec 5.2+ defines ORDERED as standalone when a DOACROSS clause is
present.
2025-09-04 08:30:23 -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