[flang] [llvm] [flang][OpenMP] Overhaul implementation of ATOMIC construct (PR #137852)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 30 22:53:17 PDT 2025
================
@@ -1223,6 +1233,155 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
TYPE_PARSER(sourced(construct<OmpBeginLoopDirective>(
sourced(Parser<OmpLoopDirective>{}), Parser<OmpClauseList>{})))
+struct OmpEndDirectiveParser {
+ using resultType = OmpDirectiveSpecification;
+
+ constexpr OmpEndDirectiveParser(llvm::omp::Directive dir) : dir_(dir) {}
+
+ std::optional<resultType> Parse(ParseState &state) const {
+ if ((startOmpLine >> "END"_id).Parse(state)) {
+ auto &&dirSpec{Parser<OmpDirectiveSpecification>{}.Parse(state)};
+ if (dirSpec && dirSpec->DirId() == dir_) {
+ return std::move(dirSpec);
+ }
+ }
+ return std::nullopt;
+ }
+
+private:
+ llvm::omp::Directive dir_;
+};
+
+// Parser for an arbitrary OpenMP ATOMIC construct.
+//
+// Depending on circumstances, an ATOMIC construct applies to one or more
+// following statements. In certain cases when a single statement is
+// expected, the end-directive is optional. The specifics depend on both
+// the clauses used, and the form of the executable statement. To emit
+// more meaningful messages in case of errors, the exact analysis of the
+// structure of the construct will be delayed until semantic checks.
+//
+// The parser will first try the case when the end-directive is present,
+// and will parse at most "BodyLimit" (and potentially zero) constructs
+// while looking for the end-directive before it gives up.
+// Then it will assume that no end-directive is present, and will try to
+// parse a single executable construct as the body of the construct.
+//
+// The limit on the number of constructs is there to reduce the amount of
+// unnecessary parsing when the end-directive is absent. It's higher than
+// the maximum number of statements in any valid construct to accept cases
+// when extra statements are present by mistake.
----------------
NimishMishra wrote:
Is there a specific reason to allow a `BodyLimit` up to 5? Atomic structured blocks still have at most two statements (in case of capture construct). If we are speculating, wouldn't the end atomic construct (if it exists) occur at most 3 constructs later?
https://github.com/llvm/llvm-project/pull/137852
More information about the llvm-commits
mailing list