[clang] 0dd72eb - [OpenACC] Implement 'vector' and 'worker' cluase argument parsing

via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 22 11:35:35 PST 2024


Author: erichkeane
Date: 2024-01-22T11:35:30-08:00
New Revision: 0dd72eb269dd485b98afba2c58a1d747db53dcad

URL: https://github.com/llvm/llvm-project/commit/0dd72eb269dd485b98afba2c58a1d747db53dcad
DIFF: https://github.com/llvm/llvm-project/commit/0dd72eb269dd485b98afba2c58a1d747db53dcad.diff

LOG: [OpenACC] Implement 'vector' and 'worker' cluase argument parsing

Both of the clauses 'vector' and 'worker' have an optional 'special'
word followed by an int-expr.  The arguments list is optional, as is the
special word, but if the parens are included, an int-expr is required.

This patch implements parsing for both.

Added: 
    

Modified: 
    clang/include/clang/Basic/OpenACCKinds.h
    clang/lib/Parse/ParseOpenACC.cpp
    clang/test/ParserOpenACC/parse-clauses.c

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/OpenACCKinds.h b/clang/include/clang/Basic/OpenACCKinds.h
index 3d3f128f7784fc..872faec0deaebb 100644
--- a/clang/include/clang/Basic/OpenACCKinds.h
+++ b/clang/include/clang/Basic/OpenACCKinds.h
@@ -154,11 +154,9 @@ enum class OpenACCClauseKind {
   Independent,
   /// 'auto' clause, allowed on 'loop' directives.
   Auto,
-  /// 'worker' clause, allowed on 'loop' and 'routine' directives.
+  /// 'worker' clause, allowed on 'loop', Combined, and 'routine' directives.
   Worker,
-  /// 'vector' clause, allowed on 'loop' and 'routine' directives. Takes no
-  /// arguments for 'routine', so the 'loop' version is not yet implemented
-  /// completely.
+  /// 'vector' clause, allowed on 'loop', Combined, and 'routine' directives.
   Vector,
   /// 'nohost' clause, allowed on 'routine' directives.
   NoHost,

diff  --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index 612ee5ef214c13..8020c455feecbc 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -159,6 +159,8 @@ enum class OpenACCSpecialTokenKind {
   Queues,
   Zero,
   Force,
+  Num,
+  Length,
 };
 
 bool isOpenACCSpecialToken(OpenACCSpecialTokenKind Kind, Token Tok) {
@@ -176,6 +178,10 @@ bool isOpenACCSpecialToken(OpenACCSpecialTokenKind Kind, Token Tok) {
     return Tok.getIdentifierInfo()->isStr("zero");
   case OpenACCSpecialTokenKind::Force:
     return Tok.getIdentifierInfo()->isStr("force");
+  case OpenACCSpecialTokenKind::Num:
+    return Tok.getIdentifierInfo()->isStr("num");
+  case OpenACCSpecialTokenKind::Length:
+    return Tok.getIdentifierInfo()->isStr("length");
   }
   llvm_unreachable("Unknown 'Kind' Passed");
 }
@@ -451,6 +457,9 @@ ClauseParensKind getClauseParensKind(OpenACCDirectiveKind DirKind,
   case OpenACCClauseKind::Self:
     return DirKind == OpenACCDirectiveKind::Update ? ClauseParensKind::Required
                                                    : ClauseParensKind::Optional;
+  case OpenACCClauseKind::Worker:
+  case OpenACCClauseKind::Vector:
+    return ClauseParensKind::Optional;
 
   case OpenACCClauseKind::Default:
   case OpenACCClauseKind::If:
@@ -488,8 +497,6 @@ ClauseParensKind getClauseParensKind(OpenACCDirectiveKind DirKind,
   case OpenACCClauseKind::Invalid:
   case OpenACCClauseKind::NoHost:
   case OpenACCClauseKind::Seq:
-  case OpenACCClauseKind::Worker:
-  case OpenACCClauseKind::Vector:
     return ClauseParensKind::None;
   }
   llvm_unreachable("Unhandled clause kind");
@@ -719,6 +726,18 @@ bool Parser::ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind,
           return true;
         break;
       }
+      case OpenACCClauseKind::Vector:
+      case OpenACCClauseKind::Worker: {
+        tryParseAndConsumeSpecialTokenKind(*this,
+                                           Kind == OpenACCClauseKind::Vector
+                                               ? OpenACCSpecialTokenKind::Length
+                                               : OpenACCSpecialTokenKind::Num,
+                                           Kind);
+        ExprResult IntExpr = ParseOpenACCIntExpr();
+        if (IntExpr.isInvalid())
+          return true;
+        break;
+      }
       default:
         llvm_unreachable("Not an optional parens type?");
       }

diff  --git a/clang/test/ParserOpenACC/parse-clauses.c b/clang/test/ParserOpenACC/parse-clauses.c
index b6114c73f1b19e..a80173c6eca3d2 100644
--- a/clang/test/ParserOpenACC/parse-clauses.c
+++ b/clang/test/ParserOpenACC/parse-clauses.c
@@ -817,6 +817,96 @@ void IntExprParsing() {
 
   // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
 #pragma acc set default_async(returns_int())
+
+
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop vector
+  // expected-error at +2{{expected expression}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop vector()
+  // expected-error at +3{{invalid tag 'invalid' on 'vector' clause}}
+  // expected-error at +2{{expected expression}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop vector(invalid:)
+  // expected-error at +2{{invalid tag 'invalid' on 'vector' clause}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop vector(invalid:5)
+  // expected-error at +2{{expected expression}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop vector(length:)
+  // expected-error at +3{{invalid tag 'num' on 'vector' clause}}
+  // expected-error at +2{{expected expression}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop vector(num:)
+  // expected-error at +3{{expected ')'}}
+  // expected-note at +2{{to match this '('}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop vector(5, 4)
+  // expected-error at +3{{expected ')'}}
+  // expected-note at +2{{to match this '('}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop vector(length:6,4)
+  // expected-error at +4{{invalid tag 'num' on 'vector' clause}}
+  // expected-error at +3{{expected ')'}}
+  // expected-note at +2{{to match this '('}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop vector(num:6,4)
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop vector(5)
+  // expected-error at +2{{invalid tag 'num' on 'vector' clause}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop vector(num:5)
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop vector(length:5)
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop vector(returns_int())
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop vector(length:returns_int())
+
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop worker
+  // expected-error at +2{{expected expression}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop worker()
+  // expected-error at +3{{invalid tag 'invalid' on 'worker' clause}}
+  // expected-error at +2{{expected expression}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop worker(invalid:)
+  // expected-error at +2{{invalid tag 'invalid' on 'worker' clause}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop worker(invalid:5)
+  // expected-error at +2{{expected expression}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop worker(num:)
+  // expected-error at +3{{invalid tag 'length' on 'worker' clause}}
+  // expected-error at +2{{expected expression}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop worker(length:)
+  // expected-error at +3{{expected ')'}}
+  // expected-note at +2{{to match this '('}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop worker(5, 4)
+  // expected-error at +3{{expected ')'}}
+  // expected-note at +2{{to match this '('}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop worker(num:6,4)
+  // expected-error at +4{{invalid tag 'length' on 'worker' clause}}
+  // expected-error at +3{{expected ')'}}
+  // expected-note at +2{{to match this '('}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop worker(length:6,4)
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop worker(5)
+  // expected-error at +2{{invalid tag 'length' on 'worker' clause}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop worker(length:5)
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop worker(num:5)
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop worker(returns_int())
+  // expected-error at +2{{invalid tag 'length' on 'worker' clause}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc loop worker(length:returns_int())
 }
 
   // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}


        


More information about the cfe-commits mailing list