Skip to content

Commit 0d8e333

Browse files
committed
[OpenACC] Implement 'vector_length' clause parsing.
The 'vector_length' clause is the first of the 'int-expr' clauses that I've implemented. Currently this is just being parsed as an assignment-expr, since it needs to be usable in a list. Sema implementation will enforce the integral-nature of it.
1 parent af1741e commit 0d8e333

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

clang/include/clang/Basic/OpenACCKinds.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ enum class OpenACCClauseKind {
221221
Collapse,
222222
/// 'bind' clause, allowed on routine constructs.
223223
Bind,
224+
/// 'vector_length' clause, allowed on 'parallel', 'kernels', 'parallel loop',
225+
/// and 'kernels loop' constructs.
226+
VectorLength,
224227

225228
/// Represents an invalid clause, for the purposes of parsing.
226229
Invalid,
@@ -322,6 +325,9 @@ inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out,
322325
case OpenACCClauseKind::Bind:
323326
return Out << "bind";
324327

328+
case OpenACCClauseKind::VectorLength:
329+
return Out << "vector_length";
330+
325331
case OpenACCClauseKind::Invalid:
326332
return Out << "<invalid>";
327333
}

clang/include/clang/Parse/Parser.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3584,7 +3584,9 @@ class Parser : public CodeCompletionHandler {
35843584
/// Parses the clause of the 'bind' argument, which can be a string literal or
35853585
/// an ID expression.
35863586
ExprResult ParseOpenACCBindClauseArgument();
3587-
3587+
/// Parses the clause kind of 'int-expr', which can be any integral
3588+
/// expression.
3589+
ExprResult ParseOpenACCIntExpr();
35883590
private:
35893591
//===--------------------------------------------------------------------===//
35903592
// C++ 14: Templates [temp]

clang/lib/Parse/ParseOpenACC.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
119119
.Case("seq", OpenACCClauseKind::Seq)
120120
.Case("use_device", OpenACCClauseKind::UseDevice)
121121
.Case("vector", OpenACCClauseKind::Vector)
122+
.Case("vector_length", OpenACCClauseKind::VectorLength)
122123
.Case("worker", OpenACCClauseKind::Worker)
123124
.Default(OpenACCClauseKind::Invalid);
124125
}
@@ -469,6 +470,7 @@ ClauseParensKind getClauseParensKind(OpenACCDirectiveKind DirKind,
469470
case OpenACCClauseKind::Reduction:
470471
case OpenACCClauseKind::Collapse:
471472
case OpenACCClauseKind::Bind:
473+
case OpenACCClauseKind::VectorLength:
472474
return ClauseParensKind::Required;
473475

474476
case OpenACCClauseKind::Auto:
@@ -536,6 +538,12 @@ void Parser::ParseOpenACCClauseList(OpenACCDirectiveKind DirKind) {
536538
}
537539
}
538540

541+
ExprResult Parser::ParseOpenACCIntExpr() {
542+
// FIXME: this is required to be an integer expression (or dependent), so we
543+
// should ensure that is the case by passing this to SEMA here.
544+
return getActions().CorrectDelayedTyposInExpr(ParseAssignmentExpression());
545+
}
546+
539547
bool Parser::ParseOpenACCClauseVarList(OpenACCClauseKind Kind) {
540548
// FIXME: Future clauses will require 'special word' parsing, check for one,
541549
// then parse it based on whether it is a clause that requires a 'special
@@ -665,7 +673,7 @@ bool Parser::ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind,
665673
tryParseAndConsumeSpecialTokenKind(*this, OpenACCSpecialTokenKind::Force,
666674
Kind);
667675
ExprResult NumLoops =
668-
getActions().CorrectDelayedTyposInExpr(ParseAssignmentExpression());
676+
getActions().CorrectDelayedTyposInExpr(ParseConstantExpression());
669677
if (NumLoops.isInvalid())
670678
return true;
671679
break;
@@ -676,6 +684,12 @@ bool Parser::ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind,
676684
return true;
677685
break;
678686
}
687+
case OpenACCClauseKind::VectorLength: {
688+
ExprResult IntExpr = ParseOpenACCIntExpr();
689+
if (IntExpr.isInvalid())
690+
return true;
691+
break;
692+
}
679693
default:
680694
llvm_unreachable("Not a required parens type?");
681695
}

clang/test/ParserOpenACC/parse-clauses.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,33 @@ void ReductionClauseParsing() {
698698
#pragma acc serial seq, reduction(&&: Begin, End)
699699
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
700700
#pragma acc serial reduction(||: Begin, End), seq
701+
}
702+
703+
int returns_int();
704+
705+
void IntExprParsing() {
706+
// expected-error@+2{{expected '('}}
707+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
708+
#pragma acc parallel vector_length
709+
710+
// expected-error@+2{{expected expression}}
711+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
712+
#pragma acc parallel vector_length()
713+
714+
// expected-error@+2{{use of undeclared identifier 'invalid'}}
715+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
716+
#pragma acc parallel vector_length(invalid)
717+
718+
// expected-error@+3{{expected ')'}}
719+
// expected-note@+2{{to match this '('}}
720+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
721+
#pragma acc parallel vector_length(5, 4)
722+
723+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
724+
#pragma acc parallel vector_length(5)
725+
726+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
727+
#pragma acc parallel vector_length(returns_int())
701728
}
702729

703730
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}

clang/test/ParserOpenACC/parse-clauses.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ void templ() {
99
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
1010
#pragma acc loop collapse(T::value)
1111
for(;;){}
12+
13+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
14+
#pragma acc parallel vector_length(T::value)
15+
for(;;){}
16+
17+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
18+
#pragma acc parallel vector_length(I)
19+
for(;;){}
1220
}
1321

1422
struct S {

0 commit comments

Comments
 (0)