aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Semantics/check-omp-structure.cpp
AgeCommit message (Collapse)AuthorFilesLines
26 hours[flang][OpenMP] Make all block constructs share the same structure (#150956)Krzysztof Parzyszek1-65/+50
The structure is - OmpBeginDirective (aka OmpDirectiveSpecification) - Block - optional<OmpEndDirective> (aka optional<OmpDirectiveSpecification>) The OmpBeginDirective and OmpEndDirective are effectively different names for OmpDirectiveSpecification. They exist to allow the semantic analyses to distinguish between the beginning and the ending of a block construct without maintaining additional context. The actual changes are in the parser: parse-tree.h and openmp-parser.cpp in particular. The rest is simply changing the way the directive/clause information is accessed (typically for the simpler). All standalone and block constructs now use OmpDirectiveSpecification to store the directive/clause information.
48 hours[Flang] Add parser support for AUTOMAP modifier (#151511)Akash Banerjee1-13/+19
Add parser support for the new AUTOMAP modifier for OpenMP Declare Target Enter clause introduced in OpenMP 6.0 section 7.9.7.
2 days[flang][OpenMP] Store directive information in OpenMPSectionConstruct (#150804)Krzysztof Parzyszek1-4/+5
The OpenMPSectionConstruct corresponds to the `!$omp section` directive, but there is nothing in the AST node that stores the directive information. Even though the only possibility (at the moment) is "section" without any clauses, for improved generality it is helpful to have that information anyway.
9 days[flang][OpenMP] Parse strictly- and loosely-structured blocks (#150298)Krzysztof Parzyszek1-8/+13
Block-associated constructs have, as their body, either a strictly- or a loosely-structured block. In the former case the end-directive is optional. The existing parser required the end-directive to be present in all cases. Note: The definitions of these blocks in the OpenMP spec exclude cases where the block contains more than one construct, and the first one is BLOCK/ENDBLOCK. For example, the following is invalid: ``` !$omp target block ! This cannot be a strictly-structured block, but continue ! a loosely-structured block cannot start with endblock ! BLOCK/ENDBLOCK continue ! !$omp end target ```
9 days[flang][OpenMP] Avoid analyzing assumed-size array bases (#150324)Krzysztof Parzyszek1-16/+20
A check for character substrings masquerading as array sections was using expression analyzer on the array base. When this array happened to be an assumed-size array, the analyzer emitted a semantic error that did not correspond to any issue with the source code. To avoid that, check whether the object is an assumed-size array before using the expression analyzer on it. While at it, replace the call to GetShape with a simple check for rank, since that's the only information needed. Fixes https://github.com/llvm/llvm-project/issues/150297
11 days[flang][OpenMP] Sema checks, lowering with new format of MAP modifiers (#149137)Krzysztof Parzyszek1-36/+71
OpenMP 6.0 has changed the modifiers on the MAP clause. Previous patch has introduced parsing support for them. This patch introduces processing of the new forms in semantic checks and in lowering. This only applies to existing modifiers, which were updated in the 6.0 spec. Any of the newly introduced modifiers (SELF and REF) are ignored.
2025-07-17[flang] Main program symbol no longer conflicts with the other symbols (#149169)Eugene Epshteyn1-2/+1
The following code is now accepted: ``` module m end program m use m end ``` The PROGRAM name doesn't really have an effect on the compilation result, so it shouldn't result in symbol name conflicts. This change makes the main program symbol name all uppercase in the cooked character stream. This makes it distinct from all other symbol names that are all lowercase in cooked character stream. Modified the tests that were checking for lower case main program name.
2025-07-11[flang][OpenMP] Use OmpDirectiveSpecification in DISPATCH (#148008)Krzysztof Parzyszek1-11/+14
Dispatch is the last construct (after ATOMIC and ALLOCATORS) where the associated block requires a specific form. Using OmpDirectiveSpecification for the begin and the optional end directives will make the structure of all block directives more uniform.
2025-07-11[flang][OpenMP] Convert AST node for ALLOCATORS to use Block as body (#148005)Krzysztof Parzyszek1-11/+35
The ALLOCATORS construct is one of the few constructs that require a special form of the associated block. Convert the AST node to use OmpDirectiveSpecification for the directive and the optional end directive, and to use parser::Block as the body: the form of the block is checked in the semantic checks (with a more meaningful message).
2025-07-10[flang][OpenMP] Issue a warning when parsing future directive spelling (#147765)Krzysztof Parzyszek1-0/+183
OpenMP 6.0 introduced alternative spelling for some directives, with the previous spellings still allowed. Warn the user when a new spelling is encountered with OpenMP version set to an older value.
2025-07-01[flang] Fix a warningKazu Hirata1-1/+1
This patch fixes: flang/lib/Semantics/check-omp-structure.cpp:1747:41: error: lambda capture 'this' is not used [-Werror,-Wunused-lambda-capture]
2025-07-01[flang][OpenMP] Split check-omp-structure.cpp into smaller files, NFC (#146359)Krzysztof Parzyszek1-2737/+37
Create these new files in flang/lib/Semantics: openmp-utils.cpp/.h - Common utilities check-omp-atomic.cpp - Atomic-related checks check-omp-loop.cpp - Loop constructs/clauses check-omp-metadirective.cpp - Metadirective-related checks Update lists of included headers, std in particular. --------- Co-authored-by: Jack Styles <jack.styles@arm.com>
2025-07-01[Flang][OpenMP] Add Semantics support for Nested OpenMPLoopConstructs (#145917)Jack Styles1-44/+56
In OpenMP Version 5.1, the tile and unroll directives were added. When using these directives, it is possible to nest them within other OpenMP Loop Constructs. This patch enables the semantics to allow for this behaviour on these specific directives. Any nested loops will be stored within the initial Loop Construct until reaching the DoConstruct itself. Relevant tests have been added, and previous behaviour has been retained with no changes. See also, #110008
2025-06-19[flang][NFC] Move new code to right place (#144551)Peter Klausler1-0/+3
Some new code was added to flang/Semantics that only depends on facilities in flang/Evaluate. Move it into Evaluate and clean up some minor stylistic problems.
2025-06-19[flang][OpenMP] Handle REQUIRES ADMO in lowering (#144362)Krzysztof Parzyszek1-0/+19
The previous approach rewrote the atomic constructs in the AST based on the REQUIRES ATOMIC_DEFAULT_MEM_ORDER directives. The new approach checks for incorrect uses of REQUIRED ADMO in the semantic analysis, and applies it in lowering, eliminating the need for a separate tree-rewriting procedure.
2025-06-18[flang][OpenMP] Clarify confusing error message (#144707)Krzysztof Parzyszek1-19/+38
The message "The atomic variable x should occur exactly once among the arguments of the top-level [...] operator" was intended to convey that (1) an atomic variable should be an argument, and (2) it should be exactly one of the arguments. However, the wording turned out to be sowing confusion instead. Rework the corresponding check, and emit an individual error message for each problematic situation: - "atomic variable cannot be a proper subexpression of an argument", - "atomic variable should appear as an argument", - "atomic variable should be exactly one of the arguments". Fixes https://github.com/llvm/llvm-project/issues/144599
2025-06-17[Flang][OpenMP] Add Parsing support for Indirect Clause (#143505)Jack Styles1-0/+9
As part of OpenMP Version 5.1, support for the `indirect` clause was added for the `declare target` directive. This clause should follow an `enter` clause, and allows procedure calls to be done indirectly through OpenMP. This adds Parsing support for the clause, along with semantics checks. Currently, lowering for the clause is not supported so a TODO message will be outputted to the user. It also performs version checking as `indirect` is only support in OpenMP 5.1 or greater. See also: #110008
2025-06-13[flang][OpenMP] Support substrings and complex part refs for DEPEND (#143907)Tom Eccles1-0/+34
Fixes #142404 The parser can't tell the difference between array indexing and a substring: that has to be done in semantics once we have types. Substrings can only be in the form string([lower]:[higher]) not string(index) or string(lower:higher:step). I added semantic checks to catch this for the DEPEND clause. This patch also adds lowering for correct substrings and for complex part references.
2025-06-11[flang][OpenMP] Overhaul implementation of ATOMIC construct (#137852)Krzysztof Parzyszek1-470/+1423
The parser will accept a wide variety of illegal attempts at forming an ATOMIC construct, leaving it to the semantic analysis to diagnose any issues. This consolidates the analysis into one place and allows us to produce more informative diagnostics. The parser's outcome will be parser::OpenMPAtomicConstruct object holding the directive, parser::Body, and an optional end-directive. The prior variety of OmpAtomicXyz classes, as well as OmpAtomicClause have been removed. READ, WRITE, etc. are now proper clauses. The semantic analysis consistently operates on "evaluation" representations, mainly evaluate::Expr (as SomeExpr) and evaluate::Assignment. The results of the semantic analysis are stored in a mutable member of the OpenMPAtomicConstruct node. This follows a precedent of having `typedExpr` member in parser::Expr, for example. This allows the lowering code to avoid duplicated handling of AST nodes. Using a BLOCK construct containing multiple statements for an ATOMIC construct that requires multiple statements is now allowed. In fact, any nesting of such BLOCK constructs is allowed. This implementation will parse, and perform semantic checks for both conditional-update and conditional-update-capture, although no MLIR will be generated for those. Instead, a TODO error will be issues prior to lowering. The allowed forms of the ATOMIC construct were based on the OpenMP 6.0 spec.
2025-06-10[flang][NFC] Clean up code in two new functions (#142037)Peter Klausler1-4/+4
Two recently-added functions in Semantics/tools.h need some cleaning up to conform to the coding style of the project. One of them should actually be in Parser/tools.{h,cpp}, the other doesn't need to be defined in the header.
2025-06-09[flang][openmp]Add UserReductionDetails and use in DECLARE REDUCTION (#140066)Tom Eccles1-14/+68
This adds another puzzle piece for the support of OpenMP DECLARE REDUCTION functionality. This adds support for operators with derived types, as well as declaring multiple different types with the same name or operator. A new detail class for UserReductionDetials is introduced to hold the list of types supported for a given reduction declaration. Tests for parsing and symbol generation added. Declare reduction is still not supported to lowering, it will generate a "Not yet implemented" fatal error. Fixes #141306 Fixes #97241 Fixes #92832 Fixes #66453 --------- Co-authored-by: Mats Petersson <mats.petersson@arm.com>
2025-06-05[flang][OpenMP] Show error for task depend with no valid modifiers (#142595)Kajetan Puchalski1-0/+7
If a "TASK DEPEND" clause is not given a valid task dependece type modifier, the semantic checks for the clause will result in an ICE because they assume that such modifiers will be present. Check whether the modifiers are present and show an appropriate error instead of crashing the compiler if they are not. Fixes llvm#133678. Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
2025-05-30[flang][OpenMP] Allow structure component in `task depend` clauses (#141923)Kareem Ergawy1-6/+2
Even though the spec (version 5.2) prohibits strcuture components from being specified in `depend` clauses, this restriction is not sensible. This PR rectifies the issue by lifting that restriction and allowing structure components in `depend` clauses (which is allowed by OpenMP 6.0).
2025-05-29[flang][OpenMP] Verify that arguments to COPYPRIVATE are variables (#141823)Krzysztof Parzyszek1-12/+13
The check if the arguments are variable list items was missing, leading to a crash in lowering in some invalid situations. This fixes the first testcase reported in https://github.com/llvm/llvm-project/issues/141481
2025-05-23[Flang][OpenMP] fix crash on sematic error in atomic capture clause (#140710)Yang Zaizhou1-30/+32
Fix a crash caused by an invalid expression in the atomic capture clause, due to the `checkForSymbolMatch` function not accounting for `GetExpr` potentially returning null. Fix https://github.com/llvm/llvm-project/issues/139884
2025-05-21[flang][OpenMP] fix diagnostic for bad cancel type (#140798)Tom Eccles1-4/+4
Fixes #133685
2025-05-19[flang][OpenMP] Allow flush of common block (#139528)Tom Eccles1-1/+7
I think this was denied by accident in https://github.com/llvm/llvm-project/commit/68180d8d16f07db8200dfce7bae26a80c43ebc5e. Flush of a common block is allowed by the standard on my reading. It is not allowed by classic-flang but is supported by gfortran and ifx. This doesn't need any lowering changes. The LLVM translation ignores the flush argument list because the openmp runtime library doesn't support flushing specific data. Depends upon https://github.com/llvm/llvm-project/pull/139522. Ignore the first commit in this PR.
2025-05-14[flang][OpenMP] Verify uses of OmpCancellationConstructTypeClause (#139743)Krzysztof Parzyszek1-13/+23
Some directive names can be used as clauses, for example in "cancel". In case where a directive name is misplaced, it could be interpreted as a clause. Verify that such uses are valid, and emit a diagnostic message if not. Fixes https://github.com/llvm/llvm-project/issues/138224
2025-05-13[flang][OpenMP]Replace assert with if-condition (#139559)Mats Petersson1-2/+1
If a symbol is not declared, check-omp-structure hits an assert. It should be safe to treat undeclared symbols as "not from a block", as they would have to be declared to be in a block... Adding simple test to confirm it gives error messages, not crashing. This should fix issue #131655 (there is already a check for symbol being not null in the code identified in the ticket).
2025-05-09[flang][OpenMP] Pass OpenMP version to getOpenMPDirectiveName (#139131)Krzysztof Parzyszek1-9/+9
The OpenMP version is stored in LangOptions in SemanticsContext. Use the fallback version where SemanticsContext is unavailable (mostly in case of debug dumps). RFC: https://discourse.llvm.org/t/rfc-alternative-spellings-of-openmp-directives/85507 Reland with a fix for build break in f18-parse-demo.
2025-05-09Revert "[flang][OpenMP] Pass OpenMP version to getOpenMPDirectiveName (#139131)"Krzysztof Parzyszek1-9/+9
This reverts commit 41aa67488c3ca33334ec79fb5216145c3644277c. Breaks build: https://lab.llvm.org/buildbot/#/builders/140/builds/22826
2025-05-09[flang][OpenMP] Pass OpenMP version to getOpenMPDirectiveName (#139131)Krzysztof Parzyszek1-9/+9
The OpenMP version is stored in LangOptions in SemanticsContext. Use the fallback version where SemanticsContext is unavailable (mostly in case of debug dumps). RFC: https://discourse.llvm.org/t/rfc-alternative-spellings-of-openmp-directives/85507
2025-05-09[Flang] [OpenMP] Add semantic checks for detach clause in task (#119172)Thirumalai Shaktivel1-44/+129
Fixes: - Add semantic checks along with the tests - Move the detach clause to allowedOnceClauses list in Task construct Restrictions:\ OpenMP 5.0: Task construct - At most one detach clause can appear on the directive. - If a detach clause appears on the directive, then a mergeable clause cannot appear on the same directive. OpenMP 5.2: Detach contruct - If a detach clause appears on a directive, then the encountering task must not be a final task. - A variable that appears in a detach clause cannot appear as a list item on a data-environment attribute clause on the same construct. - A variable that is part of another variable (as an array element or a structure element) cannot appear in a detach clause. - event-handle must not have the POINTER attribute.
2025-05-07[Flang][OpenMP] Add frontend support for declare variant (#130578)Kiran Chandramohan1-0/+10
Support is added for parsing. Basic semantics support is added to forward the code to Lowering. Lowering will emit a TODO error. Detailed semantics checks and lowering is further work.
2025-05-01[flang][OpenMP] Allow UPDATE clause to not have any arguments (#137521)Krzysztof Parzyszek1-4/+12
The UPDATE clause can be specified on both ATOMIC and DEPOBJ directives. Currently, the ATOMIC directive has its own handling of it, and the definition of the UPDATE clause only supports its use in the DEPOBJ directive, where it takes a dependence-type as an argument. The UPDATE clause on the ATOMIC directive may not have any arguments. Since the implementation of the ATOMIC construct will be modified to use the standard handling of clauses, the definition of UPDATE should reflect that.
2025-04-28[Flang][OpenMP] Permit loop construct in simd regions (#137020)Kiran Chandramohan1-4/+3
Simdizable constructs are permitted in a simd region. The loop construct is a simdizable construct. Also fixes the TODO corresponding to this.
2025-04-25[Flang] [Semantics] [OpenMP] Add semantic checks for ALLOCATE directive ↵Raghu Maddhipatla1-0/+22
(#123421) Add following semantic checks for ALLOCATE directive as per OpenMP 6.0 standard. - List item in ALLOCATE directive must not be a dummy argument - List item in ALLOCATE directive must not have POINTER attribute - List item in ALLOCATE directive must not be a associate name
2025-04-23[flang][OpenMP] Use OmpMemoryOrderType enumeration in FAIL clause (#136313)Krzysztof Parzyszek1-47/+6
Make the FAIL clause contain OmpMemoryOrderType enumeration instead of OmpClause. This simplifies the semantic checks of the FAIL clause.
2025-04-22[flang][OpenMP] Introduce OmpHintClause, simplify OmpAtomicClause (#136311)Krzysztof Parzyszek1-28/+39
The OmpAtomicClause is a variant of a few specific clauses that are used on the ATOMIC construct. The HINT clause, however, was represented as a generic OmpClause, which somewhat complicated the analysis of an OmpAtomicClause. Introduce OmpHintClause to represent the contents of the HINT clause, and use it on OmpAtomicClause similarly to how OmpFailClause is used.
2025-04-17[flang][OpenMP][Semantics] Disallow NOWAIT and ORDERED with CANCEL (#135991)Tom Eccles1-1/+45
NOWAIT was a tricky one because the clause can be on either the start or the end directive. I couldn't find a convenient way to access the end directive from the CANCEL directive nested inside of the construct, but there are convenient ways to access the start directive. I have added a list to the start directive context containing the clauses from the end directive.
2025-04-07[flang][OpenMP][NFC] Don't use special chars in error messages (#134686)Leandro Lupori1-4/+4
Some error messages were using a special char for `fi`, in the word `specified`, probably due to a typo. This caused an error on Windows: #134625
2025-03-28Revert "Revert "[flang][openmp] Adds Parser and Semantic Support for Interop ↵swatheesh-mcw1-0/+82
Construct, and Init and Use Clauses."" (#132343) Reverts llvm/llvm-project#132005
2025-03-21[flang][OpenMP][Semantics] improve semantic checks for array sections (#132230)Tom Eccles1-16/+26
I'm not sure why strides were not allowed in array sections: the stride is explicitly allowed by the standard from the first version where array sections were introduced. The limitation is that the stride must not be negative. Here I have added the check for a negative stride and updated the test for a zero length section to take account of the stride.
2025-03-20[flang][OpenMP] Use OmpDirectiveSpecification in standalone directives (#131163)Krzysztof Parzyszek1-33/+92
This uses OmpDirectiveSpecification in the rest of the standalone directives.
2025-03-19[flang][OpenMP] Use OmpDirectiveSpecification in simple directives (#131162)Krzysztof Parzyszek1-21/+17
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-19Revert "[flang][openmp] Adds Parser and Semantic Support for Interop ↵Kiran Chandramohan1-82/+0
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[flang][openmp] Adds Parser and Semantic Support for Interop Construct, and ↵swatheesh-mcw1-0/+82
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-17[Flang][OpenMP] Allow zero trait score (#131473)Kiran Chandramohan1-1/+1
2025-03-17[Flang][OpenMP][taskloop] Adding missing semantic checks in Taskloop (#128431)sharang.124921-4/+31
Below semantic checks for Taskloop clause mentioned in OpenMP [5.2] specification were missing, this patch contains the semantic checks, corresponding error messages and test cases: OpenMP standard [5.2]: [12.6] Taskloop Construct [Restrictions] Restrictions to the taskloop construct are as follows: • The reduction-modifier must be default. • The conditional lastprivate-modifier must not be specified. Authored-by: shkaushi <sharang.kaushik@amd.com>
2025-03-11[clang] [OpenMP] New OpenMP 6.0 self_maps clause (#129888)Ritanya-B-Bharadwaj1-0/+4
Initial parsing/sema support for self maps in map and requirement clause [Sections 7.9.6 and 10.5.1.6 in OpenMP 6.0 spec]