Skip to content

Commit bcc7c38

Browse files
[clang][OpenMP] New OpenMP 6.0 threadset clause
1 parent 9c56e59 commit bcc7c38

File tree

9 files changed

+147
-8
lines changed

9 files changed

+147
-8
lines changed

clang/include/clang/AST/OpenMPClause.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,13 +1332,13 @@ class OMPDefaultClause : public OMPClause {
13321332
}
13331333
};
13341334

1335-
/// This represents 'threadset' clause in the '#pragma omp ...' directive.
1335+
/// This represents 'threadset' clause in the '#pragma omp task ...' directive.
13361336
///
13371337
/// \code
1338-
/// #pragma omp parallel threadset(shared)
1338+
/// #pragma omp task threadset(omp_pool)
13391339
/// \endcode
1340-
/// In this example directive '#pragma omp parallel' has simple 'threadset'
1341-
/// clause with kind 'shared'.
1340+
/// In this example directive '#pragma omp task' has simple 'threadset'
1341+
/// clause with kind 'omp_pool'.
13421342
class OMPThreadsetClause : public OMPClause {
13431343
friend class OMPClauseReader;
13441344

@@ -1362,9 +1362,9 @@ class OMPThreadsetClause : public OMPClause {
13621362
void setThreadsetKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
13631363

13641364
public:
1365-
/// Build 'threadset' clause with argument \a A ('none' or 'shared').
1365+
/// Build 'threadset' clause with argument \a A ('omp_team' or 'omp_pool').
13661366
///
1367-
/// \param A Argument of the clause ('none' or 'shared').
1367+
/// \param A Argument of the clause ('omp_team' or 'omp_pool').
13681368
/// \param ALoc Starting location of the argument.
13691369
/// \param StartLoc Starting location of the clause.
13701370
/// \param LParenLoc Location of '('.

clang/include/clang/Basic/OpenMPKinds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ enum OpenMPAllocateClauseModifier {
237237
OMPC_ALLOCATE_unknown
238238
};
239239

240-
/// OpenMP modifiers for 'allocate' clause.
240+
/// OpenMP modifiers for 'threadset' clause.
241241
enum OpenMPThreadsetKind {
242242
#define OPENMP_THREADSET_KIND(Name) OMPC_THREADSET_##Name,
243243
#include "clang/Basic/OpenMPKinds.def"

clang/lib/AST/OpenMPClause.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
121121
case OMPC_nowait:
122122
case OMPC_untied:
123123
case OMPC_mergeable:
124+
case OMPC_threadset:
124125
case OMPC_threadprivate:
125126
case OMPC_flush:
126127
case OMPC_depobj:

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,16 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
529529
#include "clang/Basic/OpenMPKinds.def"
530530
}
531531
llvm_unreachable("Invalid OpenMP 'allocate' clause modifier");
532+
case OMPC_threadset:
533+
switch (Type) {
534+
case OMPC_THREADSET_unknown:
535+
return "unknown";
536+
#define OPENMP_THREADSET_KIND(Name) \
537+
case OMPC_THREADSET_##Name: \
538+
return #Name;
539+
#include "clang/Basic/OpenMPKinds.def"
540+
}
541+
llvm_unreachable("Invalid OpenMP 'threadset' clause modifier");
532542
case OMPC_unknown:
533543
case OMPC_threadprivate:
534544
case OMPC_if:

clang/lib/Serialization/ASTReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11440,7 +11440,7 @@ void OMPClauseReader::VisitOMPDefaultClause(OMPDefaultClause *C) {
1144011440
C->setDefaultKindKwLoc(Record.readSourceLocation());
1144111441
}
1144211442

11443-
// Read the parameter of fail clause. This will have been saved when
11443+
// Read the parameter of threadset clause. This will have been saved when
1144411444
// OMPClauseWriter is called.
1144511445
void OMPClauseReader::VisitOMPThreadsetClause(OMPThreadsetClause *C) {
1144611446
C->setLParenLoc(Record.readSourceLocation());

clang/test/OpenMP/task_ast_print.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// RUN: %clang_cc1 -verify -Wno-vla -fopenmp -ast-print %s | FileCheck %s
2+
// RUN: %clang_cc1 -verify -Wno-vla -fopenmp -fopenmp-version=60 -DOMP60 -ast-print %s | FileCheck %s --check-prefix=CHECK60
23
// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
34
// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -verify -Wno-vla %s -ast-print | FileCheck %s
45

56
// RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -ast-print %s | FileCheck %s
7+
// RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -fopenmp-version=60 -DOMP60 -ast-print %s | FileCheck %s --check-prefix=CHECK60
68
// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
79
// RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -verify -Wno-vla %s -ast-print | FileCheck %s
810
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -ast-dump %s | FileCheck %s --check-prefix=DUMP
@@ -101,9 +103,11 @@ T tmain(T argc, T *argv) {
101103
a = 2;
102104
#pragma omp task default(none), private(argc, b) firstprivate(argv) shared(d) if (argc > 0) final(S<T>::TS > 0) priority(argc) affinity(argc, argv[b:argc], arr[:], ([argc][sizeof(T)])argv)
103105
foo();
106+
#ifndef OMP60
104107
#pragma omp taskgroup task_reduction(-: argc)
105108
#pragma omp task if (C) mergeable priority(C) in_reduction(-: argc)
106109
foo();
110+
#endif
107111
return 0;
108112
}
109113

@@ -199,6 +203,14 @@ int main(int argc, char **argv) {
199203
#pragma omp task depend(inout: omp_all_memory)
200204
foo();
201205
// CHECK-NEXT: foo();
206+
#ifdef OMP60
207+
#pragma omp task threadset(omp_pool)
208+
#pragma omp task threadset(omp_team)
209+
foo();
210+
#endif
211+
// CHECK60: #pragma omp task threadset(omp_pool)
212+
// CHECK60: #pragma omp task threadset(omp_team)
213+
// CHECK60-NEXT: foo();
202214
return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x);
203215
}
204216

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// RUN: %clang_cc1 -verify=expected,omp45 -fopenmp -fopenmp-version=45 -std=c++11 -ferror-limit 200 -o - %s
2+
// RUN: %clang_cc1 -verify=expected,omp50 -fopenmp -fopenmp-version=50 -std=c++11 -ferror-limit 200 -o - %s
3+
// RUN: %clang_cc1 -verify=expected,omp51 -fopenmp -fopenmp-version=51 -std=c++11 -ferror-limit 200 -o - %s
4+
// RUN: %clang_cc1 -verify=expected -DOMP60 -fopenmp -fopenmp-version=60 -std=c++11 -ferror-limit 200 -o - %s
5+
6+
// RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-simd -fopenmp-version=45 -std=c++11 -ferror-limit 200 -o - %s
7+
// RUN: %clang_cc1 -verify=expected,omp50 -fopenmp-simd -fopenmp-version=50 -std=c++11 -ferror-limit 200 -o - %s
8+
// RUN: %clang_cc1 -verify=expected,omp51 -fopenmp-simd -fopenmp-version=51 -std=c++11 -ferror-limit 200 -o - %s
9+
// RUN: %clang_cc1 -verify=expected -DOMP60 -fopenmp-simd -fopenmp-version=60 -std=c++11 -ferror-limit 200 -o - %s
10+
11+
#ifdef OMP60
12+
struct ComplexStruct {
13+
int data[10];
14+
struct InnerStruct {
15+
float value;
16+
} inner;
17+
};
18+
19+
// Template class with member functions using 'threadset'.
20+
template <typename T>
21+
class TemplateClass {
22+
public:
23+
void foo() {
24+
#pragma omp task threadset(omp_pool)
25+
{
26+
T temp;
27+
}
28+
}
29+
void bar() {
30+
#pragma omp taskloop threadset(omp_team)
31+
for (int i = 0; i < 10; ++i) {}
32+
}
33+
};
34+
35+
// Valid uses of 'threadset' with 'omp_pool' and 'omp_team' in task directive.
36+
void test_task_threadset_valid() {
37+
int a;
38+
#pragma omp task threadset(omp_pool)
39+
#pragma omp task threadset(omp_team)
40+
#pragma omp task threadset(omp_pool) if(1)
41+
#pragma omp task threadset(omp_team) priority(5)
42+
#pragma omp task threadset(omp_pool) depend(out: a)
43+
#pragma omp parallel
44+
{
45+
#pragma omp task threadset(omp_pool)
46+
{
47+
#pragma omp taskloop threadset(omp_team)
48+
for (int i = 0; i < 5; ++i) {}
49+
}
50+
}
51+
52+
TemplateClass<int> obj;
53+
obj.foo();
54+
obj.bar();
55+
}
56+
57+
// Invalid uses of 'threadset' with incorrect arguments in task directive.
58+
void test_task_threadset_invalid_args() {
59+
#pragma omp task threadset(invalid_arg) // expected-error {{expected 'omp_pool' or 'omp_team' in OpenMP clause 'threadset'}}
60+
#pragma omp task threadset(123) // expected-error {{expected 'omp_pool' or 'omp_team' in OpenMP clause 'threadset'}}
61+
#pragma omp task threadset(omp_pool, omp_team) // expected-error {{expected ')'}} expected-note {{to match this '('}}
62+
#pragma omp task threadset() // expected-error {{expected 'omp_pool' or 'omp_team' in OpenMP clause 'threadset'}}
63+
{}
64+
}
65+
66+
// Valid uses of 'threadset' with 'omp_pool' and 'omp_team' in taskloop directive.
67+
void test_taskloop_threadset_valid() {
68+
#pragma omp taskloop threadset(omp_pool)
69+
for (int i = 0; i < 10; ++i) {}
70+
#pragma omp taskloop threadset(omp_team)
71+
for (int i = 0; i < 10; ++i) {}
72+
#pragma omp taskloop threadset(omp_pool) grainsize(5)
73+
for (int i = 0; i < 10; ++i) {}
74+
#pragma omp taskloop threadset(omp_team) num_tasks(2)
75+
for (int i = 0; i < 10; ++i) {}
76+
}
77+
78+
// Invalid uses of 'threadset' with incorrect arguments in taskloop directive.
79+
void test_taskloop_threadset_invalid_args() {
80+
#pragma omp taskloop threadset(invalid_arg) // expected-error {{expected 'omp_pool' or 'omp_team' in OpenMP clause 'threadset'}}
81+
for (int i = 0; i < 10; ++i) {}
82+
#pragma omp taskloop threadset(123) // expected-error {{expected 'omp_pool' or 'omp_team' in OpenMP clause 'threadset'}}
83+
for (int i = 0; i < 10; ++i) {}
84+
#pragma omp taskloop threadset(omp_pool, omp_team) // expected-error {{expected ')'}} expected-note {{to match this '('}}
85+
for (int i = 0; i < 10; ++i) {}
86+
#pragma omp taskloop threadset() // expected-error {{expected 'omp_pool' or 'omp_team' in OpenMP clause 'threadset'}}
87+
for (int i = 0; i < 10; ++i) {}
88+
}
89+
90+
#else
91+
void test_threadset_not_supported() {
92+
#pragma omp task threadset(omp_pool) // omp45-error {{unexpected OpenMP clause 'threadset' in directive '#pragma omp task'}} omp50-error {{unexpected OpenMP clause 'threadset' in directive '#pragma omp task'}} omp51-error {{unexpected OpenMP clause 'threadset' in directive '#pragma omp task'}}
93+
#pragma omp task threadset(omp_team) // omp45-error {{unexpected OpenMP clause 'threadset' in directive '#pragma omp task'}} omp50-error {{unexpected OpenMP clause 'threadset' in directive '#pragma omp task'}} omp51-error {{unexpected OpenMP clause 'threadset' in directive '#pragma omp task'}}
94+
#pragma omp taskloop threadset(omp_team) // omp45-error {{unexpected OpenMP clause 'threadset' in directive '#pragma omp taskloop'}} omp50-error {{unexpected OpenMP clause 'threadset' in directive '#pragma omp taskloop'}} omp51-error {{unexpected OpenMP clause 'threadset' in directive '#pragma omp taskloop'}}
95+
for (int i = 0; i < 10; ++i) {}
96+
#pragma omp taskloop threadset(omp_pool) // omp45-error {{unexpected OpenMP clause 'threadset' in directive '#pragma omp taskloop'}} omp50-error {{unexpected OpenMP clause 'threadset' in directive '#pragma omp taskloop'}} omp51-error {{unexpected OpenMP clause 'threadset' in directive '#pragma omp taskloop'}}
97+
for (int i = 0; i < 10; ++i) {}
98+
}
99+
#endif

clang/test/OpenMP/taskloop_ast_print.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
2+
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=60 -DOMP60 -ast-print %s | FileCheck %s --check-prefix=CHECK60
23
// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
34
// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -verify %s -ast-print | FileCheck %s
45

56
// RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s | FileCheck %s
7+
// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=60 -DOMP60 -ast-print %s | FileCheck %s --check-prefix=CHECK60
68
// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
79
// RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -verify %s -ast-print | FileCheck %s
810
// expected-no-diagnostics
@@ -87,6 +89,20 @@ int main(int argc, char **argv) {
8789
// CHECK-NEXT: #pragma omp cancel taskgroup
8890
// CHECK-NEXT: #pragma omp cancellation point taskgroup
8991
// CHECK-NEXT: foo();
92+
#ifdef OMP60
93+
#pragma omp taskloop threadset(omp_team)
94+
for (int i = 0; i < 10; ++i) {
95+
#pragma omp taskloop threadset(omp_pool)
96+
for (int j = 0; j < 10; ++j) {
97+
foo();
98+
}
99+
}
100+
#endif
101+
// CHECK60: #pragma omp taskloop threadset(omp_team)
102+
// CHECK60-NEXT: for (int i = 0; i < 10; ++i) {
103+
// CHECK60: #pragma omp taskloop threadset(omp_pool)
104+
// CHECK60-NEXT: for (int j = 0; j < 10; ++j) {
105+
// CHECK60-NEXT: foo();
90106
return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0]));
91107
}
92108

llvm/include/llvm/Frontend/OpenMP/OMP.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,7 @@ def OMP_TaskLoop : Directive<"taskloop"> {
11871187
VersionedClause<OMPC_Final>,
11881188
VersionedClause<OMPC_If>,
11891189
VersionedClause<OMPC_Priority>,
1190+
VersionedClause<OMPC_Threadset, 60>,
11901191
];
11911192
let allowedExclusiveClauses = [
11921193
VersionedClause<OMPC_GrainSize>,

0 commit comments

Comments
 (0)