Skip to content

Commit c66dbbe

Browse files
committed
[OpenACC] Implement 'capture' modifier Sema/AST
The 'capture' modifier is an OpenACC 3.3NEXT (AKA 3.4) feature, which permits a new kind of identifying the memory location of variables in a data clause. However, it is only valid on data, combined, or compute constructs. This patch implements all of the proper restrictions.
1 parent 1a1927a commit c66dbbe

16 files changed

+100
-36
lines changed

clang/include/clang/Basic/OpenACCKinds.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,8 @@ enum class OpenACCModifierKind : uint8_t {
642642
AlwaysOut = 1 << 2,
643643
Readonly = 1 << 3,
644644
Zero = 1 << 4,
645-
LLVM_MARK_AS_BITMASK_ENUM(Zero)
645+
Capture = 1 << 5,
646+
LLVM_MARK_AS_BITMASK_ENUM(Capture)
646647
};
647648

648649
inline bool isOpenACCModifierBitSet(OpenACCModifierKind List,
@@ -690,6 +691,13 @@ inline StreamTy &printOpenACCModifierKind(StreamTy &Out,
690691
Out << "zero";
691692
First = false;
692693
}
694+
695+
if (isOpenACCModifierBitSet(Mods, OpenACCModifierKind::Capture)) {
696+
if (!First)
697+
Out << ", ";
698+
Out << "capture";
699+
First = false;
700+
}
693701
return Out;
694702
}
695703
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out,

clang/lib/Parse/ParseOpenACC.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ OpenACCModifierKind Parser::tryParseModifierList(OpenACCClauseKind CK) {
691691
.Case("alwaysout", OpenACCModifierKind::AlwaysOut)
692692
.Case("readonly", OpenACCModifierKind::Readonly)
693693
.Case("zero", OpenACCModifierKind::Zero)
694+
.Case("capture", OpenACCModifierKind::Capture)
694695
.Default(OpenACCModifierKind::Invalid);
695696
};
696697

clang/lib/Sema/SemaOpenACCClause.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,31 +198,50 @@ class SemaOpenACCClauseVisitor {
198198
Mods = CheckSingle(Mods, ValidKinds, OpenACCModifierKind::AlwaysOut);
199199
Mods = CheckSingle(Mods, ValidKinds, OpenACCModifierKind::Readonly);
200200
Mods = CheckSingle(Mods, ValidKinds, OpenACCModifierKind::Zero);
201+
Mods = CheckSingle(Mods, ValidKinds, OpenACCModifierKind::Capture);
201202
return Mods;
202203
};
203204

205+
// The 'capture' modifier is only valid on copyin, copyout, and create on
206+
// structured data or compute constructs (which also includes combined).
207+
bool IsStructuredDataOrCompute =
208+
Clause.getDirectiveKind() == OpenACCDirectiveKind::Data ||
209+
isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) ||
210+
isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind());
211+
204212
switch (Clause.getClauseKind()) {
205213
default:
206214
llvm_unreachable("Only for copy, copyin, copyout, create");
207215
case OpenACCClauseKind::Copy:
208216
case OpenACCClauseKind::PCopy:
209217
case OpenACCClauseKind::PresentOrCopy:
218+
// COPY: Capture always
210219
return Check(OpenACCModifierKind::Always | OpenACCModifierKind::AlwaysIn |
211-
OpenACCModifierKind::AlwaysOut);
220+
OpenACCModifierKind::AlwaysOut |
221+
OpenACCModifierKind::Capture);
212222
case OpenACCClauseKind::CopyIn:
213223
case OpenACCClauseKind::PCopyIn:
214224
case OpenACCClauseKind::PresentOrCopyIn:
225+
// COPYIN: Capture only struct.data & compute
215226
return Check(OpenACCModifierKind::Always | OpenACCModifierKind::AlwaysIn |
216-
OpenACCModifierKind::Readonly);
227+
OpenACCModifierKind::Readonly |
228+
(IsStructuredDataOrCompute ? OpenACCModifierKind::Capture
229+
: OpenACCModifierKind::Invalid));
217230
case OpenACCClauseKind::CopyOut:
218231
case OpenACCClauseKind::PCopyOut:
219232
case OpenACCClauseKind::PresentOrCopyOut:
233+
// COPYOUT: Capture only struct.data & compute
220234
return Check(OpenACCModifierKind::Always | OpenACCModifierKind::AlwaysIn |
221-
OpenACCModifierKind::Zero);
235+
OpenACCModifierKind::Zero |
236+
(IsStructuredDataOrCompute ? OpenACCModifierKind::Capture
237+
: OpenACCModifierKind::Invalid));
222238
case OpenACCClauseKind::Create:
223239
case OpenACCClauseKind::PCreate:
224240
case OpenACCClauseKind::PresentOrCreate:
225-
return Check(OpenACCModifierKind::Zero);
241+
// CREATE: Capture only struct.data & compute
242+
return Check(OpenACCModifierKind::Zero |
243+
(IsStructuredDataOrCompute ? OpenACCModifierKind::Capture
244+
: OpenACCModifierKind::Invalid));
226245
}
227246
llvm_unreachable("didn't return from switch above?");
228247
}

clang/test/SemaOpenACC/combined-construct-copy-clause.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ void ModList() {
8282
// expected-error@+1{{OpenACC 'zero' modifier not valid on 'copy' clause}}
8383
#pragma acc kernels loop copy(zero: V1)
8484
for(int i = 5; i < 10;++i);
85-
#pragma acc parallel loop copy(always, alwaysin, alwaysout: V1)
85+
#pragma acc parallel loop copy(capture:V1)
86+
for(int i = 5; i < 10;++i);
87+
#pragma acc parallel loop copy(always, alwaysin, alwaysout, capture: V1)
8688
for(int i = 5; i < 10;++i);
8789
}

clang/test/SemaOpenACC/combined-construct-copyin-clause.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ void ModList() {
8989
// expected-error@+1{{OpenACC 'zero' modifier not valid on 'copyin' clause}}
9090
#pragma acc kernels loop copyin(zero: V1)
9191
for(int i = 5; i < 10;++i);
92-
#pragma acc parallel loop copyin(always, alwaysin, readonly: V1)
92+
#pragma acc parallel loop copyin(capture:V1)
93+
for(int i = 5; i < 10;++i);
94+
#pragma acc parallel loop copyin(always, alwaysin, readonly, capture: V1)
9395
for(int i = 5; i < 10;++i);
9496
}

clang/test/SemaOpenACC/combined-construct-copyout-clause.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ void ModList() {
8888
// expected-error@+1{{OpenACC 'readonly' modifier not valid on 'copyout' clause}}
8989
#pragma acc kernels loop copyout(readonly: V1)
9090
for(int i = 0; i < 6;++i);
91-
#pragma acc parallel loop copyout(always, alwaysin, zero: V1)
92-
for(int i = 0; i < 6;++i);
91+
#pragma acc parallel loop copyout(capture:V1)
92+
for(int i = 5; i < 10;++i);
93+
#pragma acc parallel loop copyout(always, alwaysin, zero, capture: V1)
94+
for(int i = 5; i < 10;++i);
9395
}
9496

clang/test/SemaOpenACC/combined-construct-create-clause.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,6 @@ void ModList() {
9999
for(int i = 5; i < 10;++i);
100100
#pragma acc kernels loop create(zero: V1)
101101
for(int i = 5; i < 10;++i);
102+
#pragma acc parallel loop create(capture:V1)
103+
for(int i = 5; i < 10;++i);
102104
}

clang/test/SemaOpenACC/compute-construct-copy-clause.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ void ModList() {
9595
// expected-error@+1{{OpenACC 'zero' modifier not valid on 'copy' clause}}
9696
#pragma acc kernels copy(zero: V1)
9797
for(int i = 5; i < 10;++i);
98-
#pragma acc parallel copy(always, alwaysin, alwaysout: V1)
98+
#pragma acc parallel copy(capture:V1)
99+
for(int i = 5; i < 10;++i);
100+
#pragma acc parallel copy(always, alwaysin, alwaysout, capture: V1)
99101
for(int i = 5; i < 10;++i);
100102
}

clang/test/SemaOpenACC/compute-construct-copyin-clause.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ void ModList() {
8888
// expected-error@+1{{OpenACC 'zero' modifier not valid on 'copyin' clause}}
8989
#pragma acc kernels copyin(zero: V1)
9090
for(int i = 5; i < 10;++i);
91-
#pragma acc parallel copyin(always, alwaysin, readonly: V1)
91+
#pragma acc parallel copyin(capture:V1)
92+
for(int i = 5; i < 10;++i);
93+
#pragma acc parallel copyin(always, alwaysin, readonly, capture: V1)
9294
for(int i = 5; i < 10;++i);
9395
}

clang/test/SemaOpenACC/compute-construct-copyout-clause.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ void ModList() {
8888
// expected-error@+1{{OpenACC 'readonly' modifier not valid on 'copyout' clause}}
8989
#pragma acc kernels copyout(readonly: V1)
9090
for(int i = 0; i < 6;++i);
91-
#pragma acc parallel copyout(always, alwaysin, zero: V1)
92-
for(int i = 0; i < 6;++i);
91+
#pragma acc parallel copyout(capture:V1)
92+
for(int i = 5; i < 10;++i);
93+
#pragma acc parallel copyout(always, alwaysin, zero, capture: V1)
94+
for(int i = 5; i < 10;++i);
9395
}

0 commit comments

Comments
 (0)