Skip to content

Commit 62a384c

Browse files
committed
[OpenACC} Implement 'async' parsing.
async just takes an integral value, but it has a little bit of special rules in sema, so it is implemented slightly differently than int-expr. This patch implements async parsing.
1 parent 72ce629 commit 62a384c

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

clang/include/clang/Basic/OpenACCKinds.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,15 @@ enum class OpenACCClauseKind {
232232
DeviceNum,
233233
/// 'default_async' clause, allowed on 'set' construct.
234234
DefaultAsync,
235-
/// 'device_type' clause, allowed on Constructs, 'data', 'init', 'shutdown',
235+
/// 'device_type' clause, allowed on Compute, 'data', 'init', 'shutdown',
236236
/// 'set', update', 'loop', 'routine', and Combined constructs.
237237
DeviceType,
238238
/// 'dtype' clause, an alias for 'device_type', stored separately for
239239
/// diagnostic purposes.
240240
DType,
241+
/// 'async' clause, allowed on Compute, Data, 'update', 'wait', and Combined
242+
/// constructs.
243+
Async,
241244

242245
/// Represents an invalid clause, for the purposes of parsing.
243246
Invalid,
@@ -360,6 +363,9 @@ inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out,
360363
case OpenACCClauseKind::DType:
361364
return Out << "dtype";
362365

366+
case OpenACCClauseKind::Async:
367+
return Out << "async";
368+
363369
case OpenACCClauseKind::Invalid:
364370
return Out << "<invalid>";
365371
}

clang/include/clang/Parse/Parser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3589,6 +3589,9 @@ class Parser : public CodeCompletionHandler {
35893589
ExprResult ParseOpenACCIntExpr();
35903590
/// Parses the 'device-type-list', which is a list of identifiers.
35913591
bool ParseOpenACCDeviceTypeList();
3592+
/// Parses the 'async-argument', which is an integral value with two
3593+
/// 'special' values that are likely negative (but come from Macros).
3594+
ExprResult ParseOpenACCAsyncArgument();
35923595

35933596
private:
35943597
//===--------------------------------------------------------------------===//

clang/lib/Parse/ParseOpenACC.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
8989

9090
return llvm::StringSwitch<OpenACCClauseKind>(
9191
Tok.getIdentifierInfo()->getName())
92+
.Case("async", OpenACCClauseKind::Async)
9293
.Case("attach", OpenACCClauseKind::Attach)
9394
.Case("auto", OpenACCClauseKind::Auto)
9495
.Case("bind", OpenACCClauseKind::Bind)
@@ -459,6 +460,7 @@ ClauseParensKind getClauseParensKind(OpenACCDirectiveKind DirKind,
459460
case OpenACCClauseKind::Self:
460461
return DirKind == OpenACCDirectiveKind::Update ? ClauseParensKind::Required
461462
: ClauseParensKind::Optional;
463+
case OpenACCClauseKind::Async:
462464
case OpenACCClauseKind::Worker:
463465
case OpenACCClauseKind::Vector:
464466
return ClauseParensKind::Optional;
@@ -784,6 +786,12 @@ bool Parser::ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind,
784786
return true;
785787
break;
786788
}
789+
case OpenACCClauseKind::Async: {
790+
ExprResult AsyncArg = ParseOpenACCAsyncArgument();
791+
if (AsyncArg.isInvalid())
792+
return true;
793+
break;
794+
}
787795
default:
788796
llvm_unreachable("Not an optional parens type?");
789797
}
@@ -793,6 +801,17 @@ bool Parser::ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind,
793801
return false;
794802
}
795803

804+
/// OpenACC 3.3 section 2.16:
805+
/// In this section and throughout the specification, the term async-argument
806+
/// means a nonnegative scalar integer expression (int for C or C++, integer for
807+
/// Fortran), or one of the special values acc_async_noval or acc_async_sync, as
808+
/// defined in the C header file and the Fortran openacc module. The special
809+
/// values are negative values, so as not to conflict with a user-specified
810+
/// nonnegative async-argument.
811+
ExprResult Parser::ParseOpenACCAsyncArgument() {
812+
return getActions().CorrectDelayedTyposInExpr(ParseAssignmentExpression());
813+
}
814+
796815
/// OpenACC 3.3, section 2.16:
797816
/// In this section and throughout the specification, the term wait-argument
798817
/// means:

clang/test/ParserOpenACC/parse-clauses.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,34 @@ void device_type() {
10191019

10201020
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
10211021
#pragma acc parallel device_type(ident, auto, int, float) dtype(ident, auto, int, float)
1022+
}
1023+
1024+
#define acc_async_sync -1
1025+
void AsyncArgument() {
1026+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
1027+
#pragma acc parallel async
1028+
1029+
// expected-error@+2{{expected expression}}
1030+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
1031+
#pragma acc parallel async()
1032+
1033+
// expected-error@+2{{use of undeclared identifier 'invalid'}}
1034+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
1035+
#pragma acc parallel async(invalid)
1036+
1037+
// expected-error@+3{{expected ')'}}
1038+
// expected-note@+2{{to match this '('}}
1039+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
1040+
#pragma acc parallel async(4, 3)
1041+
1042+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
1043+
#pragma acc parallel async(returns_int())
1044+
1045+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
1046+
#pragma acc parallel async(5)
1047+
1048+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
1049+
#pragma acc parallel async(acc_async_sync)
10221050
}
10231051

10241052
// 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
@@ -17,6 +17,14 @@ void templ() {
1717
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
1818
#pragma acc parallel vector_length(I)
1919
for(;;){}
20+
21+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
22+
#pragma acc parallel async(T::value)
23+
for(;;){}
24+
25+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
26+
#pragma acc parallel async(I)
27+
for(;;){}
2028
}
2129

2230
struct S {

0 commit comments

Comments
 (0)