Skip to content

Commit 1ab81f8

Browse files
committed
[OpenACC] Implement 'delete' AST/Sema for 'exit data' construct
'delete' is another clause that has very little compile-time implication, but needs a full AST that takes a var list. This patch ipmlements it fully, plus adds sufficient test coverage.
1 parent 8380baf commit 1ab81f8

23 files changed

+230
-28
lines changed

clang/include/clang/AST/OpenACCClause.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,29 @@ class OpenACCDetachClause final
766766
ArrayRef<Expr *> VarList, SourceLocation EndLoc);
767767
};
768768

769+
class OpenACCDeleteClause final
770+
: public OpenACCClauseWithVarList,
771+
public llvm::TrailingObjects<OpenACCDeleteClause, Expr *> {
772+
773+
OpenACCDeleteClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
774+
ArrayRef<Expr *> VarList, SourceLocation EndLoc)
775+
: OpenACCClauseWithVarList(OpenACCClauseKind::Delete, BeginLoc, LParenLoc,
776+
EndLoc) {
777+
std::uninitialized_copy(VarList.begin(), VarList.end(),
778+
getTrailingObjects<Expr *>());
779+
setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
780+
}
781+
782+
public:
783+
static bool classof(const OpenACCClause *C) {
784+
return C->getClauseKind() == OpenACCClauseKind::Delete;
785+
}
786+
static OpenACCDeleteClause *
787+
Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
788+
ArrayRef<Expr *> VarList, SourceLocation EndLoc);
789+
};
790+
791+
769792
class OpenACCNoCreateClause final
770793
: public OpenACCClauseWithVarList,
771794
public llvm::TrailingObjects<OpenACCNoCreateClause, Expr *> {

clang/include/clang/Basic/OpenACCClauses.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ VISIT_CLAUSE(Create)
3838
CLAUSE_ALIAS(PCreate, Create, true)
3939
CLAUSE_ALIAS(PresentOrCreate, Create, true)
4040
VISIT_CLAUSE(Default)
41+
VISIT_CLAUSE(Delete)
4142
VISIT_CLAUSE(Detach)
4243
VISIT_CLAUSE(DevicePtr)
4344
VISIT_CLAUSE(DeviceType)

clang/include/clang/Sema/SemaOpenACC.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ class SemaOpenACC : public SemaBase {
399399
ClauseKind == OpenACCClauseKind::PCreate ||
400400
ClauseKind == OpenACCClauseKind::PresentOrCreate ||
401401
ClauseKind == OpenACCClauseKind::Attach ||
402+
ClauseKind == OpenACCClauseKind::Delete ||
402403
ClauseKind == OpenACCClauseKind::Detach ||
403404
ClauseKind == OpenACCClauseKind::DevicePtr ||
404405
ClauseKind == OpenACCClauseKind::Reduction ||
@@ -536,6 +537,7 @@ class SemaOpenACC : public SemaBase {
536537
ClauseKind == OpenACCClauseKind::PCreate ||
537538
ClauseKind == OpenACCClauseKind::PresentOrCreate ||
538539
ClauseKind == OpenACCClauseKind::Attach ||
540+
ClauseKind == OpenACCClauseKind::Delete ||
539541
ClauseKind == OpenACCClauseKind::Detach ||
540542
ClauseKind == OpenACCClauseKind::DevicePtr ||
541543
ClauseKind == OpenACCClauseKind::FirstPrivate) &&
@@ -573,6 +575,7 @@ class SemaOpenACC : public SemaBase {
573575
ClauseKind == OpenACCClauseKind::PCreate ||
574576
ClauseKind == OpenACCClauseKind::PresentOrCreate ||
575577
ClauseKind == OpenACCClauseKind::Attach ||
578+
ClauseKind == OpenACCClauseKind::Delete ||
576579
ClauseKind == OpenACCClauseKind::Detach ||
577580
ClauseKind == OpenACCClauseKind::DevicePtr ||
578581
ClauseKind == OpenACCClauseKind::FirstPrivate) &&

clang/lib/AST/OpenACCClause.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bool OpenACCClauseWithVarList::classof(const OpenACCClause *C) {
3232
return OpenACCPrivateClause::classof(C) ||
3333
OpenACCFirstPrivateClause::classof(C) ||
3434
OpenACCDevicePtrClause::classof(C) ||
35-
OpenACCDevicePtrClause::classof(C) ||
35+
OpenACCDeleteClause::classof(C) ||
3636
OpenACCDetachClause::classof(C) || OpenACCAttachClause::classof(C) ||
3737
OpenACCNoCreateClause::classof(C) ||
3838
OpenACCPresentClause::classof(C) || OpenACCCopyClause::classof(C) ||
@@ -288,6 +288,16 @@ OpenACCDetachClause *OpenACCDetachClause::Create(const ASTContext &C,
288288
return new (Mem) OpenACCDetachClause(BeginLoc, LParenLoc, VarList, EndLoc);
289289
}
290290

291+
OpenACCDeleteClause *OpenACCDeleteClause::Create(const ASTContext &C,
292+
SourceLocation BeginLoc,
293+
SourceLocation LParenLoc,
294+
ArrayRef<Expr *> VarList,
295+
SourceLocation EndLoc) {
296+
void *Mem =
297+
C.Allocate(OpenACCDeleteClause::totalSizeToAlloc<Expr *>(VarList.size()));
298+
return new (Mem) OpenACCDeleteClause(BeginLoc, LParenLoc, VarList, EndLoc);
299+
}
300+
291301
OpenACCDevicePtrClause *OpenACCDevicePtrClause::Create(const ASTContext &C,
292302
SourceLocation BeginLoc,
293303
SourceLocation LParenLoc,
@@ -564,6 +574,13 @@ void OpenACCClausePrinter::VisitDetachClause(const OpenACCDetachClause &C) {
564574
OS << ")";
565575
}
566576

577+
void OpenACCClausePrinter::VisitDeleteClause(const OpenACCDeleteClause &C) {
578+
OS << "delete(";
579+
llvm::interleaveComma(C.getVarList(), OS,
580+
[&](const Expr *E) { printExpr(E); });
581+
OS << ")";
582+
}
583+
567584
void OpenACCClausePrinter::VisitDevicePtrClause(
568585
const OpenACCDevicePtrClause &C) {
569586
OS << "deviceptr(";

clang/lib/AST/StmtProfile.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,6 +2611,12 @@ void OpenACCClauseProfiler::VisitDetachClause(
26112611
Profiler.VisitStmt(E);
26122612
}
26132613

2614+
void OpenACCClauseProfiler::VisitDeleteClause(
2615+
const OpenACCDeleteClause &Clause) {
2616+
for (auto *E : Clause.getVarList())
2617+
Profiler.VisitStmt(E);
2618+
}
2619+
26142620
void OpenACCClauseProfiler::VisitDevicePtrClause(
26152621
const OpenACCDevicePtrClause &Clause) {
26162622
for (auto *E : Clause.getVarList())

clang/lib/AST/TextNodeDumper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ void TextNodeDumper::Visit(const OpenACCClause *C) {
412412
case OpenACCClauseKind::IfPresent:
413413
case OpenACCClauseKind::Independent:
414414
case OpenACCClauseKind::Detach:
415+
case OpenACCClauseKind::Delete:
415416
case OpenACCClauseKind::DevicePtr:
416417
case OpenACCClauseKind::Finalize:
417418
case OpenACCClauseKind::FirstPrivate:

clang/lib/Parse/ParseOpenACC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,6 @@ Parser::OpenACCClauseParseResult Parser::ParseOpenACCClauseParams(
998998
// make sure we get the right differentiator.
999999
assert(DirKind == OpenACCDirectiveKind::Update);
10001000
[[fallthrough]];
1001-
case OpenACCClauseKind::Delete:
10021001
case OpenACCClauseKind::Device:
10031002
case OpenACCClauseKind::DeviceResident:
10041003
case OpenACCClauseKind::Host:
@@ -1007,6 +1006,7 @@ Parser::OpenACCClauseParseResult Parser::ParseOpenACCClauseParams(
10071006
ParseOpenACCVarList(ClauseKind);
10081007
break;
10091008
case OpenACCClauseKind::Attach:
1009+
case OpenACCClauseKind::Delete:
10101010
case OpenACCClauseKind::Detach:
10111011
case OpenACCClauseKind::DevicePtr:
10121012
ParsedClause.setVarListDetails(ParseOpenACCVarList(ClauseKind),

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,15 @@ bool doesClauseApplyToDirective(OpenACCDirectiveKind DirectiveKind,
425425
return false;
426426
}
427427
}
428+
case OpenACCClauseKind::Delete: {
429+
switch (DirectiveKind) {
430+
case OpenACCDirectiveKind::ExitData:
431+
return true;
432+
default:
433+
return false;
434+
}
435+
}
436+
428437
case OpenACCClauseKind::Detach: {
429438
switch (DirectiveKind) {
430439
case OpenACCDirectiveKind::ExitData:
@@ -1066,6 +1075,17 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitDetachClause(
10661075
Clause.getEndLoc());
10671076
}
10681077

1078+
OpenACCClause *SemaOpenACCClauseVisitor::VisitDeleteClause(
1079+
SemaOpenACC::OpenACCParsedClause &Clause) {
1080+
// ActOnVar ensured that everything is a valid variable reference, so there
1081+
// really isn't anything to do here. GCC does some duplicate-finding, though
1082+
// it isn't apparent in the standard where this is justified.
1083+
return OpenACCDeleteClause::Create(Ctx, Clause.getBeginLoc(),
1084+
Clause.getLParenLoc(), Clause.getVarList(),
1085+
Clause.getEndLoc());
1086+
}
1087+
1088+
10691089
OpenACCClause *SemaOpenACCClauseVisitor::VisitDevicePtrClause(
10701090
SemaOpenACC::OpenACCParsedClause &Clause) {
10711091
// Restrictions only properly implemented on 'compute'/'combined'/'data'

clang/lib/Sema/TreeTransform.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11777,6 +11777,17 @@ void OpenACCClauseTransform<Derived>::VisitDetachClause(
1177711777
ParsedClause.getEndLoc());
1177811778
}
1177911779

11780+
template <typename Derived>
11781+
void OpenACCClauseTransform<Derived>::VisitDeleteClause(
11782+
const OpenACCDeleteClause &C) {
11783+
ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11784+
/*IsReadOnly=*/false, /*IsZero=*/false);
11785+
NewClause = OpenACCDeleteClause::Create(
11786+
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11787+
ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11788+
ParsedClause.getEndLoc());
11789+
}
11790+
1178011791
template <typename Derived>
1178111792
void OpenACCClauseTransform<Derived>::VisitDevicePtrClause(
1178211793
const OpenACCDevicePtrClause &C) {

clang/lib/Serialization/ASTReader.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12435,6 +12435,12 @@ OpenACCClause *ASTRecordReader::readOpenACCClause() {
1243512435
return OpenACCDetachClause::Create(getContext(), BeginLoc, LParenLoc,
1243612436
VarList, EndLoc);
1243712437
}
12438+
case OpenACCClauseKind::Delete: {
12439+
SourceLocation LParenLoc = readSourceLocation();
12440+
llvm::SmallVector<Expr *> VarList = readOpenACCVarList();
12441+
return OpenACCDeleteClause::Create(getContext(), BeginLoc, LParenLoc,
12442+
VarList, EndLoc);
12443+
}
1243812444
case OpenACCClauseKind::DevicePtr: {
1243912445
SourceLocation LParenLoc = readSourceLocation();
1244012446
llvm::SmallVector<Expr *> VarList = readOpenACCVarList();
@@ -12578,7 +12584,6 @@ OpenACCClause *ASTRecordReader::readOpenACCClause() {
1257812584

1257912585
case OpenACCClauseKind::NoHost:
1258012586
case OpenACCClauseKind::UseDevice:
12581-
case OpenACCClauseKind::Delete:
1258212587
case OpenACCClauseKind::Device:
1258312588
case OpenACCClauseKind::DeviceResident:
1258412589
case OpenACCClauseKind::Host:

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8362,6 +8362,12 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
83628362
writeOpenACCVarList(DC);
83638363
return;
83648364
}
8365+
case OpenACCClauseKind::Delete: {
8366+
const auto *DC = cast<OpenACCDeleteClause>(C);
8367+
writeSourceLocation(DC->getLParenLoc());
8368+
writeOpenACCVarList(DC);
8369+
return;
8370+
}
83658371
case OpenACCClauseKind::DevicePtr: {
83668372
const auto *DPC = cast<OpenACCDevicePtrClause>(C);
83678373
writeSourceLocation(DPC->getLParenLoc());
@@ -8506,7 +8512,6 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
85068512

85078513
case OpenACCClauseKind::NoHost:
85088514
case OpenACCClauseKind::UseDevice:
8509-
case OpenACCClauseKind::Delete:
85108515
case OpenACCClauseKind::Device:
85118516
case OpenACCClauseKind::DeviceResident:
85128517
case OpenACCClauseKind::Host:

clang/test/AST/ast-print-openacc-data-construct.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,10 @@ void foo() {
120120
// CHECK: #pragma acc exit data copyout(i) detach(iPtr, arrayPtr[0])
121121
#pragma acc exit data copyout(i) detach(iPtr, arrayPtr[0])
122122

123+
// CHECK: #pragma acc exit data copyout(i) delete(i, array[1], array, array[1:2])
124+
#pragma acc exit data copyout(i) delete(i, array[1], array, array[1:2])
125+
;
126+
127+
// CHECK: #pragma acc exit data copyout(i) delete(i, array[1], array, array[1:2])
128+
#pragma acc exit data copyout(i) delete(i, array[1], array, array[1:2])
123129
}

clang/test/ParserOpenACC/parse-clauses.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,10 @@ void VarListClauses() {
510510
#pragma acc serial firstprivate(s.array[s.value : 5], s.value), self
511511
for(int i = 0; i < 5;++i) {}
512512

513-
// expected-error@+2{{expected ','}}
514-
// expected-warning@+1{{OpenACC clause 'delete' not yet implemented, clause ignored}}
513+
// expected-error@+1{{expected ','}}
515514
#pragma acc exit data delete(s.array[s.value] s.array[s.value :5] ) async
516515
for(int i = 0; i < 5;++i) {}
517516

518-
// expected-warning@+1{{OpenACC clause 'delete' not yet implemented, clause ignored}}
519517
#pragma acc exit data delete(s.array[s.value : 5], s.value),async
520518
for(int i = 0; i < 5;++i) {}
521519

clang/test/ParserOpenACC/parse-clauses.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ void templ() {
3535
#pragma acc parallel async
3636
for(;;){}
3737

38-
// expected-warning@+1{{OpenACC clause 'delete' not yet implemented, clause ignored}}
39-
#pragma acc exit data delete(I)
38+
39+
T t;
40+
#pragma acc exit data delete(t)
4041
;
4142
}
4243

clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void uses() {
6969
for(unsigned i = 0; i < 5; ++i);
7070
#pragma acc parallel loop auto attach(VarPtr)
7171
for(unsigned i = 0; i < 5; ++i);
72-
// expected-warning@+1{{OpenACC clause 'delete' not yet implemented}}
72+
// expected-error@+1{{OpenACC 'delete' clause is not valid on 'parallel loop' directive}}
7373
#pragma acc parallel loop auto delete(Var)
7474
for(unsigned i = 0; i < 5; ++i);
7575
// expected-error@+1{{OpenACC 'detach' clause is not valid on 'parallel loop' directive}}
@@ -186,7 +186,7 @@ void uses() {
186186
for(unsigned i = 0; i < 5; ++i);
187187
#pragma acc parallel loop attach(VarPtr) auto
188188
for(unsigned i = 0; i < 5; ++i);
189-
// expected-warning@+1{{OpenACC clause 'delete' not yet implemented}}
189+
// expected-error@+1{{OpenACC 'delete' clause is not valid on 'parallel loop' directive}}
190190
#pragma acc parallel loop delete(Var) auto
191191
for(unsigned i = 0; i < 5; ++i);
192192
// expected-error@+1{{OpenACC 'detach' clause is not valid on 'parallel loop' directive}}
@@ -304,7 +304,7 @@ void uses() {
304304
for(unsigned i = 0; i < 5; ++i);
305305
#pragma acc parallel loop independent attach(VarPtr)
306306
for(unsigned i = 0; i < 5; ++i);
307-
// expected-warning@+1{{OpenACC clause 'delete' not yet implemented}}
307+
// expected-error@+1{{OpenACC 'delete' clause is not valid on 'parallel loop' directive}}
308308
#pragma acc parallel loop independent delete(Var)
309309
for(unsigned i = 0; i < 5; ++i);
310310
// expected-error@+1{{OpenACC 'detach' clause is not valid on 'parallel loop' directive}}
@@ -421,7 +421,7 @@ void uses() {
421421
for(unsigned i = 0; i < 5; ++i);
422422
#pragma acc parallel loop attach(VarPtr) independent
423423
for(unsigned i = 0; i < 5; ++i);
424-
// expected-warning@+1{{OpenACC clause 'delete' not yet implemented}}
424+
// expected-error@+1{{OpenACC 'delete' clause is not valid on 'parallel loop' directive}}
425425
#pragma acc parallel loop delete(Var) independent
426426
for(unsigned i = 0; i < 5; ++i);
427427
// expected-error@+1{{OpenACC 'detach' clause is not valid on 'parallel loop' directive}}
@@ -547,7 +547,7 @@ void uses() {
547547
for(unsigned i = 0; i < 5; ++i);
548548
#pragma acc parallel loop seq attach(VarPtr)
549549
for(unsigned i = 0; i < 5; ++i);
550-
// expected-warning@+1{{OpenACC clause 'delete' not yet implemented}}
550+
// expected-error@+1{{OpenACC 'delete' clause is not valid on 'parallel loop' directive}}
551551
#pragma acc parallel loop seq delete(Var)
552552
for(unsigned i = 0; i < 5; ++i);
553553
// expected-error@+1{{OpenACC 'detach' clause is not valid on 'parallel loop' directive}}
@@ -670,7 +670,7 @@ void uses() {
670670
for(unsigned i = 0; i < 5; ++i);
671671
#pragma acc parallel loop attach(VarPtr) seq
672672
for(unsigned i = 0; i < 5; ++i);
673-
// expected-warning@+1{{OpenACC clause 'delete' not yet implemented}}
673+
// expected-error@+1{{OpenACC 'delete' clause is not valid on 'parallel loop' directive}}
674674
#pragma acc parallel loop delete(Var) seq
675675
for(unsigned i = 0; i < 5; ++i);
676676
// expected-error@+1{{OpenACC 'detach' clause is not valid on 'parallel loop' directive}}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ void uses() {
9595
// expected-note@+1{{previous clause is here}}
9696
#pragma acc parallel loop device_type(*) attach(Var)
9797
for(int i = 0; i < 5; ++i);
98-
// expected-error@+2{{OpenACC clause 'delete' may not follow a 'device_type' clause in a 'serial loop' construct}}
99-
// expected-note@+1{{previous clause is here}}
98+
// expected-error@+1{{OpenACC 'delete' clause is not valid on 'serial loop' directive}}
10099
#pragma acc serial loop device_type(*) delete(Var)
101100
for(int i = 0; i < 5; ++i);
102101
// expected-error@+1{{OpenACC 'detach' clause is not valid on 'kernels loop' directive}}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ void uses() {
9999
// expected-note@+1{{previous clause is here}}
100100
#pragma acc kernels device_type(*) attach(Var)
101101
while(1);
102-
// expected-error@+2{{OpenACC clause 'delete' may not follow a 'device_type' clause in a 'kernels' construct}}
103-
// expected-note@+1{{previous clause is here}}
102+
// expected-error@+1{{OpenACC 'delete' clause is not valid on 'kernels' directive}}
104103
#pragma acc kernels device_type(*) delete(Var)
105104
while(1);
106105
// expected-error@+1{{OpenACC 'detach' clause is not valid on 'kernels' directive}}

0 commit comments

Comments
 (0)