summaryrefslogtreecommitdiff
path: root/flang/lib/Parser/parse-tree.cpp
AgeCommit message (Collapse)Author
2025-11-22[flang][OpenMP] Implement loop nest parser (#168884)Krzysztof Parzyszek
Previously, loop constructs were parsed in a piece-wise manner: the begin directive, the body, and the end directive were parsed separately. Later on in canonicalization they were all coalesced into a loop construct. To facilitate that end-loop directives were given a special treatment, namely they were parsed as OpenMP constructs. As a result syntax errors caused by misplaced end-loop directives were handled differently from those cause by misplaced non-loop end directives. The new loop nest parser constructs the complete loop construct, removing the need for the canonicalization step. Additionally, it is the basis for parsing loop-sequence-associated constructs in the future. It also removes the need for the special treatment of end-loop directives. While this patch temporarily degrades the error messaging for misplaced end-loop directives, it enables uniform handling of any misplaced end-directives in the future.
2025-11-17[flang][OpenMP] Store Block in OpenMPLoopConstruct, add access functions ↵Krzysztof Parzyszek
(#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-10-28[flang][OpenMP] Implement OpenMP stylized expressions (#165049)Krzysztof Parzyszek
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-16[flang][NFC] Use parser::Unwrap(Ref) more (#162918)Peter Klausler
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-08-01[flang][OpenMP] Make all block constructs share the same structure (#150956)Krzysztof Parzyszek
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.
2025-07-15[flang][OpenMP] Avoid unnecessary parsing of OpenMP constructs (#148629)Krzysztof Parzyszek
When parsing a specification part, the parser will look ahead to see if the next construct is an executable construct. In doing so it will invoke OpenMPConstruct parser, whereas the only necessary thing to check would be the directive alone.
2025-06-11[flang][OpenMP] Overhaul implementation of ATOMIC construct (#137852)Krzysztof Parzyszek
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-05-09[flang][OpenMP] Pass OpenMP version to getOpenMPDirectiveName (#139131)Krzysztof Parzyszek
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 Parzyszek
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 Parzyszek
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-03-20[flang][OpenMP] Use OmpDirectiveSpecification in standalone directives (#131163)Krzysztof Parzyszek
This uses OmpDirectiveSpecification in the rest of the standalone directives.
2025-03-07[flang][OpenMP] Remove pessimizing move introduced in 90f45a15abKrzysztof Parzyszek
This unbreaks the builders that diagnose this situation: error: moving a temporary object prevents copy elision [-Werror,-Wpess imizing-move] 341 | static OmpClauseList empty{std::move(decltype(OmpClauseList: :v){})}; | ^
2025-03-07[flang][OpenMP] Implement OmpDirectiveName, use in OmpDirectiveSpecif… ↵Krzysztof Parzyszek
(#130121) …ication The `OmpDirectiveName` class has a source in addition to wrapping the llvm::omp::Directive.
2025-02-03[flang][OpenMP] Semantic checks for context selectors (#123243)Krzysztof Parzyszek
This implements checks of the validity of context set selectors and trait selectors, plus the types of trait properties. Clause properties are also validated, but not name or extension properties. --------- Co-authored-by: Tom Eccles <tom.eccles@arm.com>
2024-12-02[flang][OpenMP] Use new modifiers in DEPEND/GRAINSIZE/NUM_TASKS (#117917)Krzysztof Parzyszek
The usual changes, added more references to OpenMP specs.
2024-11-20[flang][OpenMP] Normalize clause modifiers that exist on their own (#116655)Krzysztof Parzyszek
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-11[flang][OpenMP] Parse DOACROSS clause (#115396)Krzysztof Parzyszek
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-10-30[flang][OpenMP] Parser support for DEPOBJ plus DEPEND, DESTROY, UPDATE (#114074)Krzysztof Parzyszek
Parse the DEPOBJ construct and the associated clauses, perform basic semantic checks.
2024-10-18[flang][OpenMP] Add `Id` function to `OmpClause` to return clause id,… ↵Krzysztof Parzyszek
(#112712) … NFC This replaces the two instances of `GetClauseKindForParserClass` with a localized member function.
2023-05-31[flang] CUDA Fortran - part 1/5: parsingPeter Klausler
Begin upstreaming of CUDA Fortran support in LLVM Flang. This first patch implements parsing for CUDA Fortran syntax, including: - a new LanguageFeature enum value for CUDA Fortran - driver change to enable that feature for *.cuf and *.CUF source files - parse tree representation of CUDA Fortran syntax - dumping and unparsing of the parse tree - the actual parsers for CUDA Fortran syntax - prescanning support for !@CUF and !$CUF - basic sanity testing via unparsing and parse tree dumps ... along with any minimized changes elsewhere to make these work, mostly no-op cases in common::visitors instances in semantics and lowering to allow them to compile in the face of new types in variant<> instances in the parse tree. Because CUDA Fortran allows the kernel launch chevron syntax ("call foo<<<blocks, threads>>>()") only on CALL statements and not on function references, the parse tree nodes for CallStmt, FunctionReference, and their shared Call were rearranged a bit; this caused a fair amount of one-line changes in many files. More patches will follow that implement CUDA Fortran in the symbol table and name resolution, and then semantic checking. Differential Revision: https://reviews.llvm.org/D150159
2022-04-25[flang] Disambiguate F(X)=Y case where F is a function returning a pointerPeter Klausler
F(X)=Y may be initially parsed as a statement function definition; an existing pass will detect statement functions that should be rewritten into assignment statemets with array element references as their left-hand side variables. However, F() may also be a reference to a function that returns a data pointer, and f18 did not handle this case correctly. The right fix is to rewrite the parse tree for F(X)=Y into an assignment to a function reference result. The cases that are actually assignments to array elements -- including all of the cases previously handled -- will have their left-hand sides converted to array element references later by another existing rewriting step. Differential Revision: https://reviews.llvm.org/D124299
2022-04-16[flang] Add & use a better visit() (take 2)Peter Klausler
Adds flang/include/flang/Common/log2-visit.h, which defines a Fortran::common::visit() template function that is a drop-in replacement for std::visit(). Modifies most use sites in the front-end and runtime to use common::visit(). The C++ standard mandates that std::visit() have O(1) execution time, which forces implementations to build dispatch tables. This new common::visit() is O(log2 N) in the number of alternatives in a variant<>, but that N tends to be small and so this change produces a fairly significant improvement in compiler build memory requirements, a 5-10% improvement in compiler build time, and a small improvement in compiler execution time. Building with -DFLANG_USE_STD_VISIT causes common::visit() to be an alias for std::visit(). Calls to common::visit() with multiple variant arguments are referred to std::visit(), pending further work. This change is enabled only for GCC builds with GCC >= 9; an earlier attempt (D122441) ran into bugs in some versions of clang and was reverted rather than simply disabled; and it is not well tested with MSVC. In non-GCC and older GCC builds, common::visit() is simply an alias for std::visit().
2022-03-28Revert "[flang] Add & use a better visit()"Andrzej Warzynski
This reverts commit 2ab9990c9eb79682a4d4b183dfbc7612d3e55328. It has caused multiple build failures: * https://lab.llvm.org/buildbot/#/builders/177/builds/4346 * https://lab.llvm.org/buildbot/#/builders/180/builds/3803 * https://lab.llvm.org/buildbot/#/builders/175/builds/10419 * https://lab.llvm.org/buildbot/#/builders/191/builds/4318 * https://lab.llvm.org/buildbot/#/builders/173/builds/4274 * https://lab.llvm.org/buildbot/#/builders/181/builds/4297 All these bots failed with a time-out: ``` command timed out: 1200 seconds without output running [b'ninja', b'-j', b'32'], attempting to kill ``` I'm guessing that that's due to template instantiations failing at some point (https://reviews.llvm.org/D122441 introduced a custom implementation of std::visit). Everything seems fine when either: * building on X86 with GCC or Clang (tested with GCC 9.3 and Clang 12) * building on AArch64 with GCC (tested with GCC 11)
2022-03-25[flang] Add & use a better visit()Peter Klausler
Adds flang/include/flang/Common/visit.h, which defines a Fortran::common::visit() template function that is a drop-in replacement for std::visit(). Modifies most use sites in the front-end and runtime to use common::visit(). The C++ standard mandates that std::visit() have O(1) execution time, which forces implementations to build dispatch tables. This new common::visit() is O(log2 N) in the number of alternatives in a variant<>, but that N tends to be small and so this change produces a fairly significant improvement in compiler build memory requirements, a 5-10% improvement in compiler build time, and a small improvement in compiler execution time. Building with -DFLANG_USE_STD_VISIT causes common::visit() to be an alias for std::visit(). Calls to common::visit() with multiple variant arguments are referred to std::visit(), pending further work. Differential Revision: https://reviews.llvm.org/D122441
2020-12-07[flang] Improve initializer semantics, esp. for component default valuespeter klausler
This patch plugs many holes in static initializer semantics, improves error messages for default initial values and other component properties in parameterized derived type instantiations, and cleans up several small issues noticed during development. We now do proper scalar expansion, folding, and type, rank, and shape conformance checking for component default initializers in derived types and PDT instantiations. The initial values of named constants are now guaranteed to have been folded when installed in the symbol table, and are no longer folded or scalar-expanded at each use in expression folding. Semantics documentation was extended with information about the various kinds of initializations in Fortran and when each of them are processed in the compiler. Some necessary concomitant changes have bulked this patch out a bit: * contextual messages attachments, which are now produced for parameterized derived type instantiations so that the user can figure out which instance caused a problem with a component, have been added as part of ContextualMessages, and their implementation was debugged * several APIs in evaluate::characteristics was changed so that a FoldingContext is passed as an argument rather than just its intrinsic procedure table; this affected client call sites in many files * new tools in Evaluate/check-expression.cpp to determine when an Expr actually is a single constant value and to validate a non-pointer variable initializer or object component default value * shape conformance checking has additional arguments that control whether scalar expansion is allowed * several now-unused functions and data members noticed and removed * several crashes and bogus errors exposed by testing this new code were fixed * a -fdebug-stack-trace option to enable LLVM's stack tracing on a crash, which might be useful in the future TL;DR: Initialization processing does more and takes place at the right times for all of the various kinds of things that can be initialized. Differential Review: https://reviews.llvm.org/D92783
2020-07-09[flang] Fix frontend build with -DBUILD_SHARED_LIBS=Onpeter klausler
Fix fronted shared library builds by eliminating dependences of the parser on other component libraries, moving some code around that wasn't in the right library, and making some dependences explicit in the CMakeLists.txt files. The lowering library does not yet build as a shared library due to some undefined names. Reviewed By: tskeith Differential Revision: https://reviews.llvm.org/D83515
2020-03-28[flang] Reformat with latest clang-format and .clang-formatTim Keith
Original-commit: flang-compiler/f18@9fe84f45d7fd685051004678d6b5775dcc4c6f8f Reviewed-on: https://github.com/flang-compiler/f18/pull/1094
2020-03-19[flang] [LLVMify F18] Replace the use std::ostream with LLVM streams ↵Caroline Concatto
llvm::ostream This patch replaces the occurrence of std::ostream by llvm::raw_ostream. In LLVM Coding Standards[1] "All new code should use raw_ostream instead of ostream".[1] As a consequence, this patch also replaces the use of: std::stringstream by llvm::raw_string_ostream or llvm::raw_ostream* std::ofstream by llvm::raw_fd_ostream std::endl by '\n' and flush()[2] std::cout by llvm::outs() and std::cerr by llvm::errs() It also replaces std::strerro by llvm::sys::StrError** , but NOT in Fortran runtime libraries *std::stringstream were replaced by llvm::raw_ostream in all methods that used std::stringstream as a parameter. Moreover, it removes the pointers to these streams. [1]https://llvm.org/docs/CodingStandards.html [2]https://releases.llvm.org/2.5/docs/CodingStandards.html#ll_avoidendl Signed-off-by: Caroline Concatto <caroline.concatto@arm.com> Running clang-format-7 Signed-off-by: Caroline Concatto <caroline.concatto@arm.com> Removing residue of ostream library Signed-off-by: Caroline Concatto <caroline.concatto@arm.com> Original-commit: flang-compiler/f18@a3507d44b8911e6024033aa583c1dc54e0eb89fd Reviewed-on: https://github.com/flang-compiler/f18/pull/1047
2020-02-25[flang] Fix misparsed structure constructor in data stmtTim Keith
In a data statement like `data x / a(1) /`, `a(1)` may be an array element or a structure constructor. It is parsed as an array element so if it turns out `a` is a derived type it must be rewritten as a strucutre constructor. Original-commit: flang-compiler/f18@a2b2a330e7dbb8d719fdab9bb28921cf84f503ca Reviewed-on: https://github.com/flang-compiler/f18/pull/1024
2020-02-25[flang] [LLVMify F18] Compiler module folders should have capitalised names ↵CarolineConcatto
(flang-compiler/f18#980) This patch renames the modules in f18 to use a capital letter in the module name Signed-off-by: Caroline Concatto <caroline.concatto@arm.com> Original-commit: flang-compiler/f18@d2eb7a1c443d1539ef12b6f027074a0eb15b1ea0 Reviewed-on: https://github.com/flang-compiler/f18/pull/980