[flang-commits] [flang] [flang] Add parsing-support for IVDEP directive (PR #101045)
Mats Petersson via flang-commits
flang-commits at lists.llvm.org
Mon Aug 12 09:49:56 PDT 2024
https://github.com/Leporacanthicus updated https://github.com/llvm/llvm-project/pull/101045
>From 219840fb1b31e0a40ff94548fbd2178928e8ba5f Mon Sep 17 00:00:00 2001
From: Mats Petersson <mats.petersson at arm.com>
Date: Mon, 29 Jul 2024 18:02:38 +0100
Subject: [PATCH 1/4] [flang] Add parsing-support for IVDEP directive
This adds the parser-side of the IVDEP (Ignore Vector memory
DEPendencies). This still produces a warning when used at this
point.
There will be a follow-up patch to implement the lowering for this,
so that it passes attributes to LLVM to indicate that it should ignore
memory dependencies for the vectorisation of the loop following
the IVDEP directive.
---
flang/docs/Directives.md | 2 ++
flang/include/flang/Parser/dump-parse-tree.h | 1 +
flang/include/flang/Parser/parse-tree.h | 6 ++++--
flang/lib/Parser/Fortran-parsers.cpp | 6 +++++-
flang/lib/Parser/unparse.cpp | 3 +++
flang/test/Parser/compiler-directives.f90 | 7 +++++++
6 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/flang/docs/Directives.md b/flang/docs/Directives.md
index f356f762b13a2d..2d70a1c4b33be9 100644
--- a/flang/docs/Directives.md
+++ b/flang/docs/Directives.md
@@ -39,6 +39,8 @@ A list of non-standard directives supported by Flang
* `!dir$ vector always` forces vectorization on the following loop regardless
of cost model decisions. The loop must still be vectorizable.
[This directive currently only works on plain do loops without labels].
+* `!dir$ ivdev` tells vecorisation to ignore the dependency analysis of the
+ following loop.
# Directive Details
diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h
index 37c3370b48a085..2e026e6427a6bc 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -203,6 +203,7 @@ class ParseTreeDumper {
NODE(parser, CompilerDirective)
NODE(CompilerDirective, AssumeAligned)
NODE(CompilerDirective, IgnoreTKR)
+ NODE(CompilerDirective, IgnoreVectorDep)
NODE(CompilerDirective, LoopCount)
NODE(CompilerDirective, NameValue)
NODE(CompilerDirective, Unrecognized)
diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index 548fcc81984b2a..660cd492243011 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3342,10 +3342,12 @@ struct CompilerDirective {
TUPLE_CLASS_BOILERPLATE(NameValue);
std::tuple<Name, std::optional<std::uint64_t>> t;
};
+ EMPTY_CLASS(IgnoreVectorDep);
EMPTY_CLASS(Unrecognized);
CharBlock source;
- std::variant<std::list<IgnoreTKR>, LoopCount, std::list<AssumeAligned>,
- VectorAlways, std::list<NameValue>, Unrecognized>
+ std::variant<std::list<IgnoreTKR>, IgnoreVectorDep, LoopCount,
+ std::list<AssumeAligned>, VectorAlways, std::list<NameValue>,
+ Unrecognized>
u;
};
diff --git a/flang/lib/Parser/Fortran-parsers.cpp b/flang/lib/Parser/Fortran-parsers.cpp
index 0bdc4c4e033c76..7ae4ae474ac2e5 100644
--- a/flang/lib/Parser/Fortran-parsers.cpp
+++ b/flang/lib/Parser/Fortran-parsers.cpp
@@ -1266,12 +1266,15 @@ TYPE_PARSER(construct<StatOrErrmsg>("STAT =" >> statVariable) ||
// Directives, extensions, and deprecated statements
// !DIR$ IGNORE_TKR [ [(tkrdmac...)] name ]...
// !DIR$ LOOP COUNT (n1[, n2]...)
+// !DIR$ IVDEP
// !DIR$ name[=value] [, name[=value]]...
// !DIR$ <anything else>
constexpr auto ignore_tkr{
"IGNORE_TKR" >> optionalList(construct<CompilerDirective::IgnoreTKR>(
maybe(parenthesized(many(letter))), name))};
-constexpr auto loopCount{
+constexpr auto ignore_vector_dep{
+ "IVDEP" >> construct<CompilerDirective::IgnoreVectorDep>()};
+const constexpr auto loopCount{
"LOOP COUNT" >> construct<CompilerDirective::LoopCount>(
parenthesized(nonemptyList(digitString64)))};
constexpr auto assumeAligned{"ASSUME_ALIGNED" >>
@@ -1283,6 +1286,7 @@ TYPE_PARSER(beginDirective >> "DIR$ "_tok >>
sourced((construct<CompilerDirective>(ignore_tkr) ||
construct<CompilerDirective>(loopCount) ||
construct<CompilerDirective>(assumeAligned) ||
+ construct<CompilerDirective>(ignore_vector_dep) ||
construct<CompilerDirective>(vectorAlways) ||
construct<CompilerDirective>(
many(construct<CompilerDirective::NameValue>(
diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index 2511a5dda9d095..5b4b5adcd49537 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -1826,6 +1826,9 @@ class UnparseVisitor {
Word("!DIR$ IGNORE_TKR"); // emitted even if tkr list is empty
Walk(" ", tkr, ", ");
},
+ [&](const CompilerDirective::IgnoreVectorDep &ivdep) {
+ Word("!DIR$ IVDEP");
+ },
[&](const CompilerDirective::LoopCount &lcount) {
Walk("!DIR$ LOOP COUNT (", lcount.v, ", ", ")");
},
diff --git a/flang/test/Parser/compiler-directives.f90 b/flang/test/Parser/compiler-directives.f90
index 246eaf985251c6..3eac51b6df6d24 100644
--- a/flang/test/Parser/compiler-directives.f90
+++ b/flang/test/Parser/compiler-directives.f90
@@ -35,3 +35,10 @@ subroutine vector_always
do i=1,10
enddo
end subroutine
+
+subroutine ignore_vector_dep
+ !dir$ ivdep
+ ! CHECK: !DIR$ IVDEP
+ do i=1,10
+ enddo
+end subroutine
>From 896fbdfe587b5349e6e6a6221abe2f0864de355d Mon Sep 17 00:00:00 2001
From: Mats Petersson <mats.petersson at arm.com>
Date: Tue, 30 Jul 2024 12:11:39 +0100
Subject: [PATCH 2/4] Fix review comments
---
flang/docs/Directives.md | 2 +-
flang/lib/Parser/Fortran-parsers.cpp | 4 ++--
flang/lib/Parser/unparse.cpp | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/flang/docs/Directives.md b/flang/docs/Directives.md
index 2d70a1c4b33be9..68dce0e1aee298 100644
--- a/flang/docs/Directives.md
+++ b/flang/docs/Directives.md
@@ -39,7 +39,7 @@ A list of non-standard directives supported by Flang
* `!dir$ vector always` forces vectorization on the following loop regardless
of cost model decisions. The loop must still be vectorizable.
[This directive currently only works on plain do loops without labels].
-* `!dir$ ivdev` tells vecorisation to ignore the dependency analysis of the
+* `!dir$ ivdev` tells vecorization to ignore the dependency analysis of the
following loop.
# Directive Details
diff --git a/flang/lib/Parser/Fortran-parsers.cpp b/flang/lib/Parser/Fortran-parsers.cpp
index 7ae4ae474ac2e5..91f8a4c984135e 100644
--- a/flang/lib/Parser/Fortran-parsers.cpp
+++ b/flang/lib/Parser/Fortran-parsers.cpp
@@ -1272,7 +1272,7 @@ TYPE_PARSER(construct<StatOrErrmsg>("STAT =" >> statVariable) ||
constexpr auto ignore_tkr{
"IGNORE_TKR" >> optionalList(construct<CompilerDirective::IgnoreTKR>(
maybe(parenthesized(many(letter))), name))};
-constexpr auto ignore_vector_dep{
+constexpr auto ignoreVectorDep{
"IVDEP" >> construct<CompilerDirective::IgnoreVectorDep>()};
const constexpr auto loopCount{
"LOOP COUNT" >> construct<CompilerDirective::LoopCount>(
@@ -1286,7 +1286,7 @@ TYPE_PARSER(beginDirective >> "DIR$ "_tok >>
sourced((construct<CompilerDirective>(ignore_tkr) ||
construct<CompilerDirective>(loopCount) ||
construct<CompilerDirective>(assumeAligned) ||
- construct<CompilerDirective>(ignore_vector_dep) ||
+ construct<CompilerDirective>(ignoreVectorDep) ||
construct<CompilerDirective>(vectorAlways) ||
construct<CompilerDirective>(
many(construct<CompilerDirective::NameValue>(
diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index 5b4b5adcd49537..74b9101f8a1602 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -1826,7 +1826,7 @@ class UnparseVisitor {
Word("!DIR$ IGNORE_TKR"); // emitted even if tkr list is empty
Walk(" ", tkr, ", ");
},
- [&](const CompilerDirective::IgnoreVectorDep &ivdep) {
+ [&](const CompilerDirective::IgnoreVectorDep &) {
Word("!DIR$ IVDEP");
},
[&](const CompilerDirective::LoopCount &lcount) {
>From 6dfa1d15644799a6a8bc343007b0d4f380974294 Mon Sep 17 00:00:00 2001
From: Mats Petersson <mats.petersson at arm.com>
Date: Tue, 30 Jul 2024 15:35:53 +0100
Subject: [PATCH 3/4] Fix minor typo missed previously
---
flang/docs/Directives.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/docs/Directives.md b/flang/docs/Directives.md
index 68dce0e1aee298..7fdfba068b2a9e 100644
--- a/flang/docs/Directives.md
+++ b/flang/docs/Directives.md
@@ -39,7 +39,7 @@ A list of non-standard directives supported by Flang
* `!dir$ vector always` forces vectorization on the following loop regardless
of cost model decisions. The loop must still be vectorizable.
[This directive currently only works on plain do loops without labels].
-* `!dir$ ivdev` tells vecorization to ignore the dependency analysis of the
+* `!dir$ ivdep` tells vecorization to ignore the dependency analysis of the
following loop.
# Directive Details
>From 89009da270ab6bfc24de85dbae61eb19c17a37ee Mon Sep 17 00:00:00 2001
From: Mats Petersson <mats.petersson at arm.com>
Date: Mon, 12 Aug 2024 14:33:05 +0100
Subject: [PATCH 4/4] Fix simple typo
---
flang/docs/Directives.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/docs/Directives.md b/flang/docs/Directives.md
index 7fdfba068b2a9e..dc6db1a044dcd0 100644
--- a/flang/docs/Directives.md
+++ b/flang/docs/Directives.md
@@ -39,7 +39,7 @@ A list of non-standard directives supported by Flang
* `!dir$ vector always` forces vectorization on the following loop regardless
of cost model decisions. The loop must still be vectorizable.
[This directive currently only works on plain do loops without labels].
-* `!dir$ ivdep` tells vecorization to ignore the dependency analysis of the
+* `!dir$ ivdep` tells vectorization to ignore the dependency analysis of the
following loop.
# Directive Details
More information about the flang-commits
mailing list