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");

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ auto Lambda = [](){};
44
// CHECK: #pragma acc routine(Lambda) worker
55
#pragma acc routine(Lambda) worker
66
int function();
7-
// CHECK: #pragma acc routine(function) vector
8-
#pragma acc routine (function) vector
7+
// CHECK: #pragma acc routine(function) vector nohost
8+
#pragma acc routine (function) vector nohost
99

1010
namespace NS {
1111
int NSFunc();
1212
auto Lambda = [](){};
1313
}
1414
// CHECK: #pragma acc routine(NS::NSFunc) seq
1515
#pragma acc routine(NS::NSFunc) seq
16-
// CHECK: #pragma acc routine(NS::Lambda) gang
17-
#pragma acc routine(NS::Lambda) gang
16+
// CHECK: #pragma acc routine(NS::Lambda) nohost gang
17+
#pragma acc routine(NS::Lambda) nohost gang
1818

1919
constexpr int getInt() { return 1; }
2020

@@ -33,8 +33,8 @@ struct S {
3333
#pragma acc routine(MemFunc) gang(dim:1)
3434
// CHECK: #pragma acc routine(StaticMemFunc) gang(dim: getInt())
3535
#pragma acc routine(StaticMemFunc) gang(dim:getInt())
36-
// CHECK: #pragma acc routine(Lambda) worker
37-
#pragma acc routine(Lambda) worker
36+
// CHECK: #pragma acc routine(Lambda) nohost worker
37+
#pragma acc routine(Lambda) nohost worker
3838
};
3939

4040
// CHECK: #pragma acc routine(S::MemFunc) gang(dim: 1)
@@ -66,10 +66,10 @@ struct DepS {
6666

6767
// CHECK: #pragma acc routine(DepS<T>::Lambda) vector
6868
#pragma acc routine(DepS<T>::Lambda) vector
69-
// CHECK: #pragma acc routine(DepS<T>::MemFunc) seq
70-
#pragma acc routine(DepS<T>::MemFunc) seq
71-
// CHECK: #pragma acc routine(DepS<T>::StaticMemFunc) worker
72-
#pragma acc routine(DepS<T>::StaticMemFunc) worker
69+
// CHECK: #pragma acc routine(DepS<T>::MemFunc) seq nohost
70+
#pragma acc routine(DepS<T>::MemFunc) seq nohost
71+
// CHECK: #pragma acc routine(DepS<T>::StaticMemFunc) nohost worker
72+
#pragma acc routine(DepS<T>::StaticMemFunc) nohost worker
7373
};
7474

7575
// CHECK: #pragma acc routine(DepS<int>::Lambda) gang
@@ -84,8 +84,8 @@ template<typename T>
8484
void TemplFunc() {
8585
// CHECK: #pragma acc routine(T::MemFunc) gang(dim: T::SomethingElse())
8686
#pragma acc routine(T::MemFunc) gang(dim:T::SomethingElse())
87-
// CHECK: #pragma acc routine(T::StaticMemFunc) worker
88-
#pragma acc routine(T::StaticMemFunc) worker
89-
// CHECK: #pragma acc routine(T::Lambda) seq
90-
#pragma acc routine(T::Lambda) seq
87+
// CHECK: #pragma acc routine(T::StaticMemFunc) worker nohost
88+
#pragma acc routine(T::StaticMemFunc) worker nohost
89+
// CHECK: #pragma acc routine(T::Lambda) nohost seq
90+
#pragma acc routine(T::Lambda) nohost seq
9191
}

clang/test/SemaOpenACC/routine-construct-ast.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
#ifndef PCH_HELPER
88
#define PCH_HELPER
99
auto Lambda = [](){};
10-
#pragma acc routine(Lambda) worker
10+
#pragma acc routine(Lambda) worker nohost
1111
// CHECK: OpenACCRoutineDecl{{.*}} routine name_specified
1212
// CHECK-NEXT: DeclRefExpr{{.*}} 'Lambda' '(lambda at
1313
// CHECK-NEXT: worker clause
14+
// CHECK-NEXT: nohost clause
1415
int function();
15-
#pragma acc routine (function) vector
16+
#pragma acc routine (function) nohost vector
1617
// CHECK: OpenACCRoutineDecl{{.*}} routine name_specified
1718
// CHECK-NEXT: DeclRefExpr{{.*}} 'function' 'int ()'
19+
// CHECK-NEXT: nohost clause
1820
// CHECK-NEXT: vector clause
1921

2022
namespace NS {
@@ -227,18 +229,20 @@ void TemplFunc() {
227229
// CHECK-NEXT: NestedNameSpecifier{{.*}} 'T'
228230
// CHECK-NEXT: gang clause
229231
// CHECK-NEXT: CallExpr{{.*}}'<dependent type>'
230-
#pragma acc routine(T::StaticMemFunc) worker
232+
#pragma acc routine(T::StaticMemFunc) nohost worker
231233
// CHECK-NEXT: DeclStmt
232234
// CHECK-NEXT: OpenACCRoutineDecl{{.*}} routine name_specified
233235
// CHECK-NEXT: DependentScopeDeclRefExpr{{.*}}'<dependent type>'
234236
// CHECK-NEXT: NestedNameSpecifier{{.*}} 'T'
237+
// CHECK-NEXT: nohost clause
235238
// CHECK-NEXT: worker clause
236-
#pragma acc routine(T::Lambda) seq
239+
#pragma acc routine(T::Lambda) seq nohost
237240
// CHECK-NEXT: DeclStmt
238241
// CHECK-NEXT: OpenACCRoutineDecl{{.*}} routine name_specified
239242
// CHECK-NEXT: DependentScopeDeclRefExpr{{.*}}'<dependent type>'
240243
// CHECK-NEXT: NestedNameSpecifier{{.*}} 'T'
241244
// CHECK-NEXT: seq clause
245+
// CHECK-NEXT: nohost clause
242246

243247
// Instantiation:
244248
// CHECK: FunctionDecl{{.*}} TemplFunc 'void ()' implicit_instantiation
@@ -254,13 +258,15 @@ void TemplFunc() {
254258
// CHECK-NEXT: OpenACCRoutineDecl{{.*}} routine name_specified
255259
// CHECK-NEXT: DeclRefExpr{{.*}} 'StaticMemFunc' 'void ()'
256260
// CHECK-NEXT: NestedNameSpecifier{{.*}} 'S'
261+
// CHECK-NEXT: nohost clause
257262
// CHECK-NEXT: worker clause
258263

259264
// CHECK-NEXT: DeclStmt
260265
// CHECK-NEXT: OpenACCRoutineDecl{{.*}} routine name_specified
261266
// CHECK-NEXT: DeclRefExpr{{.*}} 'Lambda' 'const S::(lambda at
262267
// CHECK-NEXT: NestedNameSpecifier{{.*}} 'S'
263268
// CHECK-NEXT: seq clause
269+
// CHECK-NEXT: nohost clause
264270
}
265271

266272
void usage() {

clang/test/SemaOpenACC/routine-construct-clauses.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
void Func();
44

55
#pragma acc routine(Func) worker
6-
#pragma acc routine(Func) vector
7-
#pragma acc routine(Func) seq
6+
#pragma acc routine(Func) vector nohost
7+
#pragma acc routine(Func) nohost seq
88
#pragma acc routine(Func) gang
99

1010
// Only 1 of worker, vector, seq, gang.
@@ -56,6 +56,10 @@ void Func();
5656
// expected-error@+2{{OpenACC clause 'gang' may not appear on the same construct as a 'gang' clause on a 'routine' construct}}
5757
// expected-note@+1{{previous clause is here}}
5858
#pragma acc routine(Func) gang gang
59+
// expected-error@+1{{REQUIRED}}
60+
#pragma acc routine(Func)
61+
// expected-error@+1{{REQUIRED}}
62+
#pragma acc routine(Func) nohost
5963

6064
// only the 'dim' syntax for gang is legal.
6165
#pragma acc routine(Func) gang(dim:1)
@@ -106,8 +110,8 @@ struct DependentT {
106110
// expected-error@+1{{argument to 'gang' clause dimension must be 1, 2, or 3: evaluated to -5}}
107111
#pragma acc routine(Func) gang(dim:T::Neg())
108112
// expected-error@+1{{argument to 'gang' clause dimension must be 1, 2, or 3: evaluated to 0}}
109-
#pragma acc routine(Func) gang(dim:T::Zero())
110-
#pragma acc routine(Func) gang(dim:T::One())
113+
#pragma acc routine(Func) gang(dim:T::Zero()) nohost
114+
#pragma acc routine(Func) nohost gang(dim:T::One())
111115
#pragma acc routine(Func) gang(dim:T::Two())
112116
#pragma acc routine(Func) gang(dim:T::Three())
113117
// expected-error@+1{{argument to 'gang' clause dimension must be 1, 2, or 3: evaluated to 4}}

clang/tools/libclang/CIndex.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2973,6 +2973,7 @@ void OpenACCClauseEnqueue::VisitAutoClause(const OpenACCAutoClause &C) {}
29732973
void OpenACCClauseEnqueue::VisitIndependentClause(
29742974
const OpenACCIndependentClause &C) {}
29752975
void OpenACCClauseEnqueue::VisitSeqClause(const OpenACCSeqClause &C) {}
2976+
void OpenACCClauseEnqueue::VisitNoHostClause(const OpenACCNoHostClause &C) {}
29762977
void OpenACCClauseEnqueue::VisitFinalizeClause(const OpenACCFinalizeClause &C) {
29772978
}
29782979
void OpenACCClauseEnqueue::VisitIfPresentClause(

0 commit comments

Comments
 (0)