Skip to content

Commit 7d8da04

Browse files
committed
[OpenACC] Implement 'nohost' construct AST/Sema
'nohost' is only valid on routine, and states that the compiler shouldn't compile this routine for the host. It has no arguments, so no checking is required besides putting it in the AST.
1 parent 996092d commit 7d8da04

14 files changed

+96
-24
lines changed

clang/include/clang/AST/OpenACCClause.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,26 @@ class OpenACCSeqClause : public OpenACCClause {
162162
return const_child_range(const_child_iterator(), const_child_iterator());
163163
}
164164
};
165+
// Represents the 'nohost' clause.
166+
class OpenACCNoHostClause : public OpenACCClause {
167+
protected:
168+
OpenACCNoHostClause(SourceLocation BeginLoc, SourceLocation EndLoc)
169+
: OpenACCClause(OpenACCClauseKind::NoHost, BeginLoc, EndLoc) {}
170+
171+
public:
172+
static bool classof(const OpenACCClause *C) {
173+
return C->getClauseKind() == OpenACCClauseKind::NoHost;
174+
}
175+
static OpenACCNoHostClause *
176+
Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
177+
178+
child_range children() {
179+
return child_range(child_iterator(), child_iterator());
180+
}
181+
const_child_range children() const {
182+
return const_child_range(const_child_iterator(), const_child_iterator());
183+
}
184+
};
165185

166186
/// Represents a clause that has a list of parameters.
167187
class OpenACCClauseWithParams : public OpenACCClause {

clang/include/clang/Basic/OpenACCClauses.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ VISIT_CLAUSE(IfPresent)
5656
VISIT_CLAUSE(Independent)
5757
VISIT_CLAUSE(Link)
5858
VISIT_CLAUSE(NoCreate)
59+
VISIT_CLAUSE(NoHost)
5960
VISIT_CLAUSE(NumGangs)
6061
VISIT_CLAUSE(NumWorkers)
6162
VISIT_CLAUSE(Present)

clang/lib/AST/OpenACCClause.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,13 @@ OpenACCSeqClause *OpenACCSeqClause::Create(const ASTContext &C,
534534
return new (Mem) OpenACCSeqClause(BeginLoc, EndLoc);
535535
}
536536

537+
OpenACCNoHostClause *OpenACCNoHostClause::Create(const ASTContext &C,
538+
SourceLocation BeginLoc,
539+
SourceLocation EndLoc) {
540+
void *Mem = C.Allocate(sizeof(OpenACCNoHostClause));
541+
return new (Mem) OpenACCNoHostClause(BeginLoc, EndLoc);
542+
}
543+
537544
OpenACCGangClause *
538545
OpenACCGangClause::Create(const ASTContext &C, SourceLocation BeginLoc,
539546
SourceLocation LParenLoc,
@@ -871,6 +878,10 @@ void OpenACCClausePrinter::VisitSeqClause(const OpenACCSeqClause &C) {
871878
OS << "seq";
872879
}
873880

881+
void OpenACCClausePrinter::VisitNoHostClause(const OpenACCNoHostClause &C) {
882+
OS << "nohost";
883+
}
884+
874885
void OpenACCClausePrinter::VisitCollapseClause(const OpenACCCollapseClause &C) {
875886
OS << "collapse(";
876887
if (C.hasForce())

clang/lib/AST/StmtProfile.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,6 +2719,8 @@ void OpenACCClauseProfiler::VisitIndependentClause(
27192719
const OpenACCIndependentClause &Clause) {}
27202720

27212721
void OpenACCClauseProfiler::VisitSeqClause(const OpenACCSeqClause &Clause) {}
2722+
void OpenACCClauseProfiler::VisitNoHostClause(
2723+
const OpenACCNoHostClause &Clause) {}
27222724

27232725
void OpenACCClauseProfiler::VisitGangClause(const OpenACCGangClause &Clause) {
27242726
for (unsigned I = 0; I < Clause.getNumExprs(); ++I) {

clang/lib/AST/TextNodeDumper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ void TextNodeDumper::Visit(const OpenACCClause *C) {
423423
case OpenACCClauseKind::FirstPrivate:
424424
case OpenACCClauseKind::Link:
425425
case OpenACCClauseKind::NoCreate:
426+
case OpenACCClauseKind::NoHost:
426427
case OpenACCClauseKind::NumGangs:
427428
case OpenACCClauseKind::NumWorkers:
428429
case OpenACCClauseKind::Present:

clang/lib/Sema/SemaOpenACCClause.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,14 @@ bool doesClauseApplyToDirective(OpenACCDirectiveKind DirectiveKind,
475475
return false;
476476
}
477477
}
478+
case OpenACCClauseKind::NoHost: {
479+
switch (DirectiveKind) {
480+
case OpenACCDirectiveKind::Routine:
481+
return true;
482+
default:
483+
return false;
484+
}
485+
}
478486
}
479487

480488
default:
@@ -1286,6 +1294,12 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitAutoClause(
12861294
Clause.getEndLoc());
12871295
}
12881296

1297+
OpenACCClause *SemaOpenACCClauseVisitor::VisitNoHostClause(
1298+
SemaOpenACC::OpenACCParsedClause &Clause) {
1299+
return OpenACCNoHostClause::Create(Ctx, Clause.getBeginLoc(),
1300+
Clause.getEndLoc());
1301+
}
1302+
12891303
OpenACCClause *SemaOpenACCClauseVisitor::VisitIndependentClause(
12901304
SemaOpenACC::OpenACCParsedClause &Clause) {
12911305
// OpenACC 3.3 2.9:

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,12 @@ void OpenACCDeclClauseInstantiator::VisitSeqClause(const OpenACCSeqClause &C) {
11091109
ParsedClause.getBeginLoc(),
11101110
ParsedClause.getEndLoc());
11111111
}
1112+
void OpenACCDeclClauseInstantiator::VisitNoHostClause(
1113+
const OpenACCNoHostClause &C) {
1114+
NewClause = OpenACCNoHostClause::Create(SemaRef.getASTContext(),
1115+
ParsedClause.getBeginLoc(),
1116+
ParsedClause.getEndLoc());
1117+
}
11121118

11131119
void OpenACCDeclClauseInstantiator::VisitWorkerClause(
11141120
const OpenACCWorkerClause &C) {

clang/lib/Sema/TreeTransform.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11875,6 +11875,11 @@ void OpenACCClauseTransform<Derived>::VisitDeviceResidentClause(
1187511875
const OpenACCDeviceResidentClause &C) {
1187611876
llvm_unreachable("device_resident clause not valid unless a decl transform");
1187711877
}
11878+
template <typename Derived>
11879+
void OpenACCClauseTransform<Derived>::VisitNoHostClause(
11880+
const OpenACCNoHostClause &C) {
11881+
llvm_unreachable("device_resident clause not valid unless a decl transform");
11882+
}
1187811883

1187911884
template <typename Derived>
1188011885
void OpenACCClauseTransform<Derived>::VisitCopyInClause(

clang/lib/Serialization/ASTReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12733,6 +12733,8 @@ OpenACCClause *ASTRecordReader::readOpenACCClause() {
1273312733
}
1273412734
case OpenACCClauseKind::Seq:
1273512735
return OpenACCSeqClause::Create(getContext(), BeginLoc, EndLoc);
12736+
case OpenACCClauseKind::NoHost:
12737+
return OpenACCNoHostClause::Create(getContext(), BeginLoc, EndLoc);
1273612738
case OpenACCClauseKind::Finalize:
1273712739
return OpenACCFinalizeClause::Create(getContext(), BeginLoc, EndLoc);
1273812740
case OpenACCClauseKind::IfPresent:
@@ -12795,7 +12797,6 @@ OpenACCClause *ASTRecordReader::readOpenACCClause() {
1279512797
LParenLoc, VarList, EndLoc);
1279612798
}
1279712799

12798-
case OpenACCClauseKind::NoHost:
1279912800
case OpenACCClauseKind::Bind:
1280012801
case OpenACCClauseKind::Invalid:
1280112802
llvm_unreachable("Clause serialization not yet implemented");

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8783,6 +8783,7 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
87838783
}
87848784
case OpenACCClauseKind::Seq:
87858785
case OpenACCClauseKind::Independent:
8786+
case OpenACCClauseKind::NoHost:
87868787
case OpenACCClauseKind::Auto:
87878788
case OpenACCClauseKind::Finalize:
87888789
case OpenACCClauseKind::IfPresent:
@@ -8843,7 +8844,6 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
88438844
return;
88448845
}
88458846

8846-
case OpenACCClauseKind::NoHost:
88478847
case OpenACCClauseKind::Bind:
88488848
case OpenACCClauseKind::Invalid:
88498849
llvm_unreachable("Clause serialization not yet implemented");

0 commit comments

Comments
 (0)