diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h --- a/flang/include/flang/Parser/dump-parse-tree.h +++ b/flang/include/flang/Parser/dump-parse-tree.h @@ -190,6 +190,7 @@ NODE(CommonStmt, Block) NODE(parser, CompilerDirective) NODE(CompilerDirective, IgnoreTKR) + NODE(CompilerDirective, LoopCount) NODE(CompilerDirective, NameValue) NODE(parser, ComplexLiteralConstant) NODE(parser, ComplexPart) diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -3231,6 +3231,7 @@ // Compiler directives // !DIR$ IGNORE_TKR [ [(tkr...)] name ]... +// !DIR$ LOOP COUNT (n1[, n2]...) // !DIR$ name... struct CompilerDirective { UNION_CLASS_BOILERPLATE(CompilerDirective); @@ -3238,12 +3239,15 @@ TUPLE_CLASS_BOILERPLATE(IgnoreTKR); std::tuple, Name> t; }; + struct LoopCount { + WRAPPER_CLASS_BOILERPLATE(LoopCount, std::list); + }; struct NameValue { TUPLE_CLASS_BOILERPLATE(NameValue); std::tuple> t; }; CharBlock source; - std::variant, std::list> u; + std::variant, LoopCount, std::list> u; }; // Legacy extensions diff --git a/flang/lib/Parser/Fortran-parsers.cpp b/flang/lib/Parser/Fortran-parsers.cpp --- a/flang/lib/Parser/Fortran-parsers.cpp +++ b/flang/lib/Parser/Fortran-parsers.cpp @@ -1209,14 +1209,20 @@ // Directives, extensions, and deprecated statements // !DIR$ IGNORE_TKR [ [(tkr...)] name ]... +// !DIR$ LOOP COUNT (n1[, n2]...) // !DIR$ name... constexpr auto beginDirective{skipStuffBeforeStatement >> "!"_ch}; constexpr auto endDirective{space >> endOfLine}; constexpr auto ignore_tkr{ "DIR$ IGNORE_TKR" >> optionalList(construct( defaulted(parenthesized(some("tkr"_ch))), name))}; +constexpr auto loopCount{ + "DIR$ LOOP COUNT" >> construct( + parenthesized(nonemptyList(digitString64)))}; + TYPE_PARSER(beginDirective >> sourced(construct(ignore_tkr) || + construct(loopCount) || construct( "DIR$" >> many(construct(name, maybe(("="_tok || ":"_tok) >> digitString64))))) / diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp --- a/flang/lib/Parser/unparse.cpp +++ b/flang/lib/Parser/unparse.cpp @@ -1783,6 +1783,9 @@ Word("!DIR$ IGNORE_TKR"); // emitted even if tkr list is empty Walk(" ", tkr, ", "); }, + [&](const CompilerDirective::LoopCount &lcount) { + Walk("!DIR$ LOOP COUNT (", lcount.v, ", ", ")"); + }, [&](const std::list &names) { Walk("!DIR$ ", names, " "); }, diff --git a/flang/test/Parser/compiler-directives.f90 b/flang/test/Parser/compiler-directives.f90 --- a/flang/test/Parser/compiler-directives.f90 +++ b/flang/test/Parser/compiler-directives.f90 @@ -13,4 +13,6 @@ !dir$ integer = 64 !dir$ optimize:1 !dir$ optimize : 1 + !dir$ loop count (10000) + !dir$ loop count (1, 500, 5000, 10000) end