Skip to content

Commit dd5ce45

Browse files
committed
[OpenACC] Implement 'use_device' clause parsing
'use_device' is effectively identical to the 'copy' parsing in that it has required parens and no 'special' name, so this is a pretty trivial impementation. There are a number of other similar situation clauses I'll do in a followup patch.
1 parent 3ede817 commit dd5ce45

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

clang/include/clang/Basic/OpenACCKinds.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ enum class OpenACCClauseKind {
101101
/// 'copy' clause, allowed on Compute and Combined Constructs, plus 'data' and
102102
/// 'declare'.
103103
Copy,
104+
/// 'use_device' clause, allowed on 'host_data' construct.
105+
UseDevice,
104106
/// Represents an invalid clause, for the purposes of parsing.
105107
Invalid,
106108
};

clang/lib/Parse/ParseOpenACC.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
9999
.Case("nohost", OpenACCClauseKind::NoHost)
100100
.Case("self", OpenACCClauseKind::Self)
101101
.Case("seq", OpenACCClauseKind::Seq)
102+
.Case("use_device", OpenACCClauseKind::UseDevice)
102103
.Case("vector", OpenACCClauseKind::Vector)
103104
.Case("worker", OpenACCClauseKind::Worker)
104105
.Default(OpenACCClauseKind::Invalid);
@@ -336,7 +337,8 @@ bool ClauseHasOptionalParens(OpenACCClauseKind Kind) {
336337

337338
bool ClauseHasRequiredParens(OpenACCClauseKind Kind) {
338339
return Kind == OpenACCClauseKind::Default || Kind == OpenACCClauseKind::If ||
339-
Kind == OpenACCClauseKind::Copy;
340+
Kind == OpenACCClauseKind::Copy ||
341+
Kind == OpenACCClauseKind::UseDevice;
340342
}
341343

342344
ExprResult ParseOpenACCConditionalExpr(Parser &P) {
@@ -461,6 +463,7 @@ bool Parser::ParseOpenACCClauseParams(OpenACCClauseKind Kind) {
461463
return true;
462464
break;
463465
}
466+
case OpenACCClauseKind::UseDevice:
464467
case OpenACCClauseKind::Copy:
465468
if (ParseOpenACCClauseVarList(Kind))
466469
return true;

clang/test/ParserOpenACC/parse-clauses.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void VarListClauses() {
365365
#pragma acc serial copy(s.array[s.value]), seq
366366

367367
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
368-
#pragma acc serial copy(s.array[s.value : 5]), seq
368+
#pragma acc serial copy(s.array[s.value], s.array[s.value :5] ), seq
369369

370370
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
371371
#pragma acc serial copy(HasMem.MemArr[3].array[1]), seq
@@ -398,6 +398,13 @@ void VarListClauses() {
398398
// expected-error@+2{{expected expression}}
399399
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
400400
#pragma acc serial copy(HasMem.MemArr[3:]), seq
401+
402+
// expected-error@+2{{expected ','}}
403+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
404+
#pragma acc serial use_device(s.array[s.value] s.array[s.value :5] ), seq
405+
406+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
407+
#pragma acc serial use_device(s.array[s.value : 5]), seq
401408
}
402409

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

0 commit comments

Comments
 (0)