[flang-commits] [flang] c2d8974 - [Flang] Fix parsing error on loop count compiler directive
via flang-commits
flang-commits at lists.llvm.org
Tue Jan 17 19:16:27 PST 2023
Author: Nadeem, Usman
Date: 2023-01-17T19:15:47-08:00
New Revision: c2d8974a89767678898f7f8a5e7caa3d527e5d56
URL: https://github.com/llvm/llvm-project/commit/c2d8974a89767678898f7f8a5e7caa3d527e5d56
DIFF: https://github.com/llvm/llvm-project/commit/c2d8974a89767678898f7f8a5e7caa3d527e5d56.diff
LOG: [Flang] Fix parsing error on loop count compiler directive
Fixes: https://github.com/llvm/llvm-project/issues/58731
Fixes: https://github.com/llvm/llvm-project/issues/56678
Only handles this form which was reported: `!DIR$ LOOP COUNT (n1[, n2]...)`
Differential Revision: https://reviews.llvm.org/D141976
Change-Id: I768c8cb9f289c5fc4adee1ef8262c6d827574f27
Added:
Modified:
flang/include/flang/Parser/dump-parse-tree.h
flang/include/flang/Parser/parse-tree.h
flang/lib/Parser/Fortran-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/test/Parser/compiler-directives.f90
Removed:
################################################################################
diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h
index f96632f3064b6..f0716c7da7f79 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -190,6 +190,7 @@ class ParseTreeDumper {
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
index 8d7a878bf86d0..9792e995fc39a 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3231,6 +3231,7 @@ struct StmtFunctionStmt {
// Compiler directives
// !DIR$ IGNORE_TKR [ [(tkr...)] name ]...
+// !DIR$ LOOP COUNT (n1[, n2]...)
// !DIR$ name...
struct CompilerDirective {
UNION_CLASS_BOILERPLATE(CompilerDirective);
@@ -3238,12 +3239,15 @@ struct CompilerDirective {
TUPLE_CLASS_BOILERPLATE(IgnoreTKR);
std::tuple<std::list<const char *>, Name> t;
};
+ struct LoopCount {
+ WRAPPER_CLASS_BOILERPLATE(LoopCount, std::list<std::uint64_t>);
+ };
struct NameValue {
TUPLE_CLASS_BOILERPLATE(NameValue);
std::tuple<Name, std::optional<std::uint64_t>> t;
};
CharBlock source;
- std::variant<std::list<IgnoreTKR>, std::list<NameValue>> u;
+ std::variant<std::list<IgnoreTKR>, LoopCount, std::list<NameValue>> u;
};
// Legacy extensions
diff --git a/flang/lib/Parser/Fortran-parsers.cpp b/flang/lib/Parser/Fortran-parsers.cpp
index 5f64d3346d7e4..a6bec93517ce7 100644
--- a/flang/lib/Parser/Fortran-parsers.cpp
+++ b/flang/lib/Parser/Fortran-parsers.cpp
@@ -1209,14 +1209,20 @@ TYPE_PARSER(construct<StatOrErrmsg>("STAT =" >> statVariable) ||
// 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<CompilerDirective::IgnoreTKR>(
defaulted(parenthesized(some("tkr"_ch))), name))};
+constexpr auto loopCount{
+ "DIR$ LOOP COUNT" >> construct<CompilerDirective::LoopCount>(
+ parenthesized(nonemptyList(digitString64)))};
+
TYPE_PARSER(beginDirective >>
sourced(construct<CompilerDirective>(ignore_tkr) ||
+ construct<CompilerDirective>(loopCount) ||
construct<CompilerDirective>(
"DIR$" >> many(construct<CompilerDirective::NameValue>(name,
maybe(("="_tok || ":"_tok) >> digitString64))))) /
diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index 3c31a0fcad72e..e0f763ca03a88 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -1783,6 +1783,9 @@ class UnparseVisitor {
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<CompilerDirective::NameValue> &names) {
Walk("!DIR$ ", names, " ");
},
diff --git a/flang/test/Parser/compiler-directives.f90 b/flang/test/Parser/compiler-directives.f90
index 95250338ec752..1e6c67dff3c1c 100644
--- a/flang/test/Parser/compiler-directives.f90
+++ b/flang/test/Parser/compiler-directives.f90
@@ -13,4 +13,6 @@ module m
!dir$ integer = 64
!dir$ optimize:1
!dir$ optimize : 1
+ !dir$ loop count (10000)
+ !dir$ loop count (1, 500, 5000, 10000)
end
More information about the flang-commits
mailing list