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:

0 commit comments

Comments
 (0)