Skip to content

[flang] Add parsing-support for IVDEP directive #101045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Leporacanthicus
Copy link
Contributor

@Leporacanthicus Leporacanthicus commented Jul 29, 2024

This adds the parser-side of the IVDEP (Ignore Vector memory DEPendencies) directive. 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.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:parser labels Jul 29, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 29, 2024

@llvm/pr-subscribers-flang-parser

Author: Mats Petersson (Leporacanthicus)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/101045.diff

6 Files Affected:

  • (modified) flang/docs/Directives.md (+2)
  • (modified) flang/include/flang/Parser/dump-parse-tree.h (+1)
  • (modified) flang/include/flang/Parser/parse-tree.h (+4-2)
  • (modified) flang/lib/Parser/Fortran-parsers.cpp (+5-1)
  • (modified) flang/lib/Parser/unparse.cpp (+3)
  • (modified) flang/test/Parser/compiler-directives.f90 (+7)
diff --git a/flang/docs/Directives.md b/flang/docs/Directives.md
index f356f762b13a2..2d70a1c4b33be 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 37c3370b48a08..2e026e6427a6b 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 548fcc81984b2..660cd49224301 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 0bdc4c4e033c7..7ae4ae474ac2e 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 2511a5dda9d09..5b4b5adcd4953 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 246eaf985251c..3eac51b6df6d2 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

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ivdep

vectori[zs]ation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Darn it, missed the first one, fixed the spelling of optimization. Update coming in a few minutes.

// !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{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignoreVectorDep

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix the ignore_tkr -> ignoreTkr (or ingoreTKR) in a follow up commit.

@@ -1826,6 +1826,9 @@ class UnparseVisitor {
Word("!DIR$ IGNORE_TKR"); // emitted even if tkr list is empty
Walk(" ", tkr, ", ");
},
[&](const CompilerDirective::IgnoreVectorDep &ivdep) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no argument name needed or desired (can raise build warnings)

Copy link
Contributor

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG. Please wait for @klausler

There will be a follow-up patch to implement the lowering for this

Did vector always have a semantics portion to warn if it is not applied to loops?

@Leporacanthicus
Copy link
Contributor Author

LG. Please wait for @klausler

There will be a follow-up patch to implement the lowering for this

Did vector always have a semantics portion to warn if it is not applied to loops?

The follow-up patch here is just my intention to unify style and patterns, as there are other cases of the things that was pointed out in this review, that should be "the same".

There will be similar semantics checks (literally just adding another case for this directive), but that's in the "implementation part" that I'm working on right now.

Copy link
Member

@DavidTruby DavidTruby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but wait for @klausler to approve

@@ -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$ ivdep` tells vecorization to ignore the dependency analysis of the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still missing a 'T'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed... Sorry about the delay, I was hoping to have the rest of this work ready by today, but it's not there yet, and some other work is currently more important... :(

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.
@JDPailleux
Copy link
Contributor

@Leporacanthicus Hello, I am currently proposing an implementation for the IVDEP directive. I wanted to know the status of this PR and when it can be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:parser flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants