Skip to content

Commit 003eb5e

Browse files
committed
[OpenACC] Implement 'finalize' clause sema
This is a very simple clause as far as sema is concerned. It is only valid on 'exit data', and doesn't have any rules involving it, so it is simply applied and passed onto the MLIR.
1 parent 668d968 commit 003eb5e

20 files changed

+171
-33
lines changed

clang/include/clang/AST/OpenACCClause.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class OpenACCClause {
3838
SourceLocation getBeginLoc() const { return Location.getBegin(); }
3939
SourceLocation getEndLoc() const { return Location.getEnd(); }
4040

41-
static bool classof(const OpenACCClause *) { return false; }
41+
static bool classof(const OpenACCClause *) { return true; }
4242

4343
using child_iterator = StmtIterator;
4444
using const_child_iterator = ConstStmtIterator;
@@ -76,6 +76,28 @@ class OpenACCAutoClause : public OpenACCClause {
7676
}
7777
};
7878

79+
// Represents the 'finalize' clause.
80+
class OpenACCFinalizeClause : public OpenACCClause {
81+
protected:
82+
OpenACCFinalizeClause(SourceLocation BeginLoc, SourceLocation EndLoc)
83+
: OpenACCClause(OpenACCClauseKind::Finalize, BeginLoc, EndLoc) {}
84+
85+
public:
86+
static bool classof(const OpenACCClause *C) {
87+
return C->getClauseKind() == OpenACCClauseKind::Finalize;
88+
}
89+
90+
static OpenACCFinalizeClause *
91+
Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
92+
93+
child_range children() {
94+
return child_range(child_iterator(), child_iterator());
95+
}
96+
const_child_range children() const {
97+
return const_child_range(const_child_iterator(), const_child_iterator());
98+
}
99+
};
100+
79101
// Represents the 'independent' clause.
80102
class OpenACCIndependentClause : public OpenACCClause {
81103
protected:

clang/include/clang/Basic/OpenACCClauses.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ VISIT_CLAUSE(Default)
4141
VISIT_CLAUSE(DevicePtr)
4242
VISIT_CLAUSE(DeviceType)
4343
CLAUSE_ALIAS(DType, DeviceType, false)
44+
VISIT_CLAUSE(Finalize)
4445
VISIT_CLAUSE(FirstPrivate)
4546
VISIT_CLAUSE(Gang)
4647
VISIT_CLAUSE(If)

clang/lib/AST/OpenACCClause.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,14 @@ OpenACCVectorClause *OpenACCVectorClause::Create(const ASTContext &C,
444444
return new (Mem) OpenACCVectorClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
445445
}
446446

447+
OpenACCFinalizeClause *OpenACCFinalizeClause::Create(const ASTContext &C,
448+
SourceLocation BeginLoc,
449+
SourceLocation EndLoc) {
450+
void *Mem =
451+
C.Allocate(sizeof(OpenACCFinalizeClause), alignof(OpenACCFinalizeClause));
452+
return new (Mem) OpenACCFinalizeClause(BeginLoc, EndLoc);
453+
}
454+
447455
//===----------------------------------------------------------------------===//
448456
// OpenACC clauses printing methods
449457
//===----------------------------------------------------------------------===//
@@ -685,3 +693,7 @@ void OpenACCClausePrinter::VisitVectorClause(const OpenACCVectorClause &C) {
685693
OS << ")";
686694
}
687695
}
696+
697+
void OpenACCClausePrinter::VisitFinalizeClause(const OpenACCFinalizeClause &C) {
698+
OS << "finalize";
699+
}

clang/lib/AST/StmtProfile.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,6 +2558,9 @@ void OpenACCClauseProfiler::VisitSelfClause(const OpenACCSelfClause &Clause) {
25582558
Profiler.VisitStmt(Clause.getConditionExpr());
25592559
}
25602560

2561+
void OpenACCClauseProfiler::VisitFinalizeClause(
2562+
const OpenACCFinalizeClause &Clause) {}
2563+
25612564
void OpenACCClauseProfiler::VisitNumGangsClause(
25622565
const OpenACCNumGangsClause &Clause) {
25632566
for (auto *E : Clause.getIntExprs())

clang/lib/AST/TextNodeDumper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ void TextNodeDumper::Visit(const OpenACCClause *C) {
411411
case OpenACCClauseKind::If:
412412
case OpenACCClauseKind::Independent:
413413
case OpenACCClauseKind::DevicePtr:
414+
case OpenACCClauseKind::Finalize:
414415
case OpenACCClauseKind::FirstPrivate:
415416
case OpenACCClauseKind::NoCreate:
416417
case OpenACCClauseKind::NumGangs:

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@ bool doesClauseApplyToDirective(OpenACCDirectiveKind DirectiveKind,
408408
return false;
409409
}
410410
}
411+
case OpenACCClauseKind::Finalize: {
412+
switch (DirectiveKind) {
413+
case OpenACCDirectiveKind::ExitData:
414+
return true;
415+
default:
416+
return false;
417+
}
418+
}
411419
}
412420

413421
default:
@@ -1604,6 +1612,14 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitGangClause(
16041612
GangKinds, IntExprs, Clause.getEndLoc());
16051613
}
16061614

1615+
OpenACCClause *SemaOpenACCClauseVisitor::VisitFinalizeClause(
1616+
SemaOpenACC::OpenACCParsedClause &Clause) {
1617+
// There isn't anything to do here, this is only valid on one construct, and
1618+
// has no associated rules.
1619+
return OpenACCFinalizeClause::Create(Ctx, Clause.getBeginLoc(),
1620+
Clause.getEndLoc());
1621+
}
1622+
16071623
OpenACCClause *SemaOpenACCClauseVisitor::VisitSeqClause(
16081624
SemaOpenACC::OpenACCParsedClause &Clause) {
16091625
// Restrictions only properly implemented on 'loop' constructs and combined ,

clang/lib/Sema/TreeTransform.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11978,6 +11978,13 @@ void OpenACCClauseTransform<Derived>::VisitSeqClause(
1197811978
ParsedClause.getBeginLoc(),
1197911979
ParsedClause.getEndLoc());
1198011980
}
11981+
template <typename Derived>
11982+
void OpenACCClauseTransform<Derived>::VisitFinalizeClause(
11983+
const OpenACCFinalizeClause &C) {
11984+
NewClause = OpenACCFinalizeClause::Create(Self.getSema().getASTContext(),
11985+
ParsedClause.getBeginLoc(),
11986+
ParsedClause.getEndLoc());
11987+
}
1198111988

1198211989
template <typename Derived>
1198311990
void OpenACCClauseTransform<Derived>::VisitReductionClause(

clang/lib/Serialization/ASTReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12534,6 +12534,8 @@ OpenACCClause *ASTRecordReader::readOpenACCClause() {
1253412534
}
1253512535
case OpenACCClauseKind::Seq:
1253612536
return OpenACCSeqClause::Create(getContext(), BeginLoc, EndLoc);
12537+
case OpenACCClauseKind::Finalize:
12538+
return OpenACCFinalizeClause::Create(getContext(), BeginLoc, EndLoc);
1253712539
case OpenACCClauseKind::Independent:
1253812540
return OpenACCIndependentClause::Create(getContext(), BeginLoc, EndLoc);
1253912541
case OpenACCClauseKind::Auto:
@@ -12579,7 +12581,6 @@ OpenACCClause *ASTRecordReader::readOpenACCClause() {
1257912581
VectorExpr, EndLoc);
1258012582
}
1258112583

12582-
case OpenACCClauseKind::Finalize:
1258312584
case OpenACCClauseKind::IfPresent:
1258412585
case OpenACCClauseKind::NoHost:
1258512586
case OpenACCClauseKind::UseDevice:

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8451,6 +8451,7 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
84518451
case OpenACCClauseKind::Seq:
84528452
case OpenACCClauseKind::Independent:
84538453
case OpenACCClauseKind::Auto:
8454+
case OpenACCClauseKind::Finalize:
84548455
// Nothing to do here, there is no additional information beyond the
84558456
// begin/end loc and clause kind.
84568457
return;
@@ -8496,7 +8497,6 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
84968497
return;
84978498
}
84988499

8499-
case OpenACCClauseKind::Finalize:
85008500
case OpenACCClauseKind::IfPresent:
85018501
case OpenACCClauseKind::NoHost:
85028502
case OpenACCClauseKind::UseDevice:

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,7 @@ void foo() {
110110
// CHECK: #pragma acc data default(none) attach(iPtr, arrayPtr[0])
111111
#pragma acc data default(none) attach(iPtr, arrayPtr[0])
112112
;
113+
114+
// CHECK: #pragma acc exit data copyout(i) finalize
115+
#pragma acc exit data copyout(i) finalize
113116
}

0 commit comments

Comments
 (0)