Skip to content

Commit d82e759

Browse files
[clang] [OpenMP] Codegen support for threadset
1 parent bcc7c38 commit d82e759

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3691,6 +3691,7 @@ CGOpenMPRuntime::emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc,
36913691
DestructorsFlag = 0x8,
36923692
PriorityFlag = 0x20,
36933693
DetachableFlag = 0x40,
3694+
PoolFlag = 0x80,
36943695
};
36953696
unsigned Flags = Data.Tied ? TiedFlag : 0;
36963697
bool NeedsCleanup = false;
@@ -3700,6 +3701,11 @@ CGOpenMPRuntime::emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc,
37003701
if (NeedsCleanup)
37013702
Flags = Flags | DestructorsFlag;
37023703
}
3704+
if (const auto *Clause = D.getSingleClause<OMPThreadsetClause>()) {
3705+
OpenMPThreadsetKind Kind = Clause->getThreadsetKind();
3706+
if (Kind == OMPC_THREADSET_omp_pool)
3707+
Flags = Flags | PoolFlag;
3708+
}
37033709
if (Data.Priority.getInt())
37043710
Flags = Flags | PriorityFlag;
37053711
if (D.hasClausesOfKind<OMPDetachClause>())

clang/lib/Serialization/ASTReader.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11050,6 +11050,9 @@ OMPClause *OMPClauseReader::readClause() {
1105011050
case llvm::omp::OMPC_mergeable:
1105111051
C = new (Context) OMPMergeableClause();
1105211052
break;
11053+
case llvm::omp::OMPC_threadset:
11054+
C = new (Context) OMPThreadsetClause();
11055+
break;
1105311056
case llvm::omp::OMPC_read:
1105411057
C = new (Context) OMPReadClause();
1105511058
break;

clang/test/OpenMP/task_codegen.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
// RUN: -emit-llvm -o - -DOMP51 | FileCheck %s \
4242
// RUN: --implicit-check-not="{{__kmpc|__tgt}}"
4343

44+
// RUN: %clang_cc1 -verify -Wno-vla -triple x86_64-apple-darwin10 -fopenmp -fopenmp-version=60 -DOMP60 -fopenmp-enable-irbuilder -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK6
45+
// RUN: %clang_cc1 -fopenmp -fopenmp-version=60 -DOMP60 -fopenmp-enable-irbuilder -x c++ -triple x86_64-apple-darwin10 -emit-pch -o %t %s
46+
// RUN: %clang_cc1 -fopenmp -fopenmp-version=60 -DOMP60 -fopenmp-enable-irbuilder -x c++ -triple x86_64-apple-darwin10 -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK6
4447

4548
// expected-no-diagnostics
4649
#ifndef HEADER
@@ -65,6 +68,7 @@ struct S {
6568
S(const S &s) : a(s.a) {}
6669
~S() {}
6770
};
71+
6872
int a;
6973
int main() {
7074
char b;
@@ -147,6 +151,7 @@ int main() {
147151

148152

149153

154+
150155
// s1 = S();
151156

152157

@@ -215,6 +220,19 @@ void test_omp_all_memory()
215220
}
216221
}
217222
#endif // OMP51
223+
224+
#ifdef OMP60
225+
void test_threadset()
226+
{
227+
#pragma omp task threadset(omp_team)
228+
{
229+
}
230+
#pragma omp task threadset(omp_pool)
231+
{
232+
}
233+
}
234+
#endif // OMP60
235+
218236
#endif
219237
// CHECK1-LABEL: define {{[^@]+}}@main
220238
// CHECK1-SAME: () #[[ATTR0:[0-9]+]] {
@@ -10243,3 +10261,18 @@ void test_omp_all_memory()
1024310261
// CHECK4-51-NEXT: call void @__cxx_global_var_init()
1024410262
// CHECK4-51-NEXT: ret void
1024510263
//
10264+
// CHECK6-LABEL: define void @_Z14test_threadsetv()
10265+
// CHECK6-NEXT: entry:
10266+
// CHECK6-NEXT: [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON_23:%.*]], align 1
10267+
// CHECK6-NEXT: [[AGG_CAPTURED2:%.*]] = alloca [[STRUCT_ANON_25:%.*]], align 1
10268+
// CHECK6-NEXT: call i32 @__kmpc_global_thread_num(ptr @[[GLOB_PTR:[0-9]+]])
10269+
// CHECK6-NEXT: [[TMP0:%.*]] = call ptr @__kmpc_omp_task_alloc(ptr @1, i32 %omp_global_thread_num, i32 1, i64 40, i64 1, ptr @.omp_task_entry..[[ENTRY1:[0-9]+]])
10270+
// CHECK6-NEXT: getelementptr inbounds nuw %struct.kmp_task_t_with_privates{{.*}}, ptr %0, i32 0, i32 0
10271+
// CHECK6-NEXT: call i32 @__kmpc_global_thread_num(ptr @[[GLOB_PTR:[0-9]+]])
10272+
// CHECK6-NEXT: call i32 @__kmpc_omp_task(ptr @1, i32 %omp_global_thread_num1, ptr %0)
10273+
// CHECK6-NEXT: call i32 @__kmpc_global_thread_num(ptr @[[GLOB_PTR2:[0-9]+]])
10274+
// CHECK6-NEXT: [[TMP3:%.*]] = call ptr @__kmpc_omp_task_alloc(ptr @1, i32 %omp_global_thread_num3, i32 129, i64 40, i64 1, ptr @.omp_task_entry..[[ENTRY2:[0-9]+]])
10275+
// CHECK6-NEXT: getelementptr inbounds nuw %struct.kmp_task_t_with_privates{{.*}}, ptr %3, i32 0, i32 0
10276+
// CHECK6-NEXT: call i32 @__kmpc_global_thread_num(ptr @[[GLOB_PTR2:[0-9]+]])
10277+
// CHECK6-NEXT: call i32 @__kmpc_omp_task(ptr @1, i32 %omp_global_thread_num4, ptr %3)
10278+
// CHECK6-NEXT: ret void

clang/test/OpenMP/taskloop_codegen.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -x c++ -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
66
// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-apple-darwin10 -emit-pch -o %t %s
77
// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-apple-darwin10 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
8+
89
// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
10+
11+
// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fopenmp-version=60 -DOMP60 -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK6
12+
// RUN: %clang_cc1 -fopenmp -fopenmp-version=60 -DOMP60 -x c++ -triple x86_64-apple-darwin10 -emit-pch -o %t %s
13+
// RUN: %clang_cc1 -fopenmp -fopenmp-version=60 -DOMP60 -x c++ -triple x86_64-apple-darwin10 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK6
914
// expected-no-diagnostics
1015
#ifndef HEADER
1116
#define HEADER
@@ -241,4 +246,52 @@ void taskloop_with_class() {
241246
}
242247
}
243248

249+
#ifdef OMP60
250+
void test_threadset()
251+
{
252+
#pragma omp taskloop threadset(omp_team)
253+
for (int i = 0; i < 10; ++i) {
254+
}
255+
#pragma omp taskloop threadset(omp_pool)
256+
for (int i = 0; i < 10; ++i) {
257+
}
258+
}
259+
#endif // OMP60
260+
// CHECK6-LABEL: define void @_Z14test_threadsetv()
261+
// CHECK6-NEXT: entry:
262+
// CHECK6-NEXT: [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON_14:%.*]], align 1
263+
// CHECK6-NEXT: %[[TMP:.*]] = alloca i32, align 4
264+
// CHECK6-NEXT: [[AGG_CAPTURED1:%.*]] = alloca [[STRUCT_ANON_16:%.*]], align 1
265+
// CHECK6-NEXT: %[[TMP2:.*]] = alloca i32, align 4
266+
// CHECK6-NEXT: %[[TID0:.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB_PTR:[0-9]+]])
267+
// CHECK6-NEXT: call void @__kmpc_taskgroup(ptr @1, i32 %[[TID0:.*]])
268+
// CHECK6-NEXT: %[[TID1:.*]] = call ptr @__kmpc_omp_task_alloc(ptr @1, i32 %[[TID0:.*]], i32 1, i64 80, i64 1, ptr @.omp_task_entry..[[ENTRY1:[0-9]+]])
269+
// CHECK6-NEXT: %[[TID2:.*]] = getelementptr inbounds nuw %struct.kmp_task_t_with_privates{{.*}}, ptr %[[TID1:.*]], i32 0, i32 0
270+
// CHECK6-NEXT: %[[TID3:.*]] = getelementptr inbounds nuw %struct.kmp_task_t{{.*}}, ptr %[[TID2:.*]], i32 0, i32 5
271+
// CHECK6-NEXT: store i64 0, ptr %[[TID3:.*]], align 8
272+
// CHECK6-NEXT: %[[TID4:.*]] = getelementptr inbounds nuw %struct.kmp_task_t{{.*}}, ptr %[[TID2:.*]], i32 0, i32 6
273+
// CHECK6-NEXT: store i64 9, ptr %[[TID4:.*]], align 8
274+
// CHECK6-NEXT: %[[TID5:.*]] = getelementptr inbounds nuw %struct.kmp_task_t{{.*}}, ptr %[[TID2:.*]], i32 0, i32 7
275+
// CHECK6-NEXT: store i64 1, ptr %[[TID5:.*]], align 8
276+
// CHECK6-NEXT: %[[TID6:.*]] = getelementptr inbounds nuw %struct.kmp_task_t{{.*}}, ptr %[[TID2:.*]], i32 0, i32 9
277+
// CHECK6-NEXT: call void @llvm.memset.p0.i64(ptr align 8 %[[TID6:.*]], i8 0, i64 8, i1 false)
278+
// CHECK6-NEXT: %[[TID7:.*]] = load i64, ptr %[[TID5:.*]], align 8
279+
// CHECK6-NEXT: call void @__kmpc_taskloop(ptr @1, i32 %[[TID0:.*]], ptr %[[TID1:.*]], i32 1, ptr %[[TID3:.*]], ptr %4, i64 %[[TID7:.*]], i32 1, i32 0, i64 0, ptr null)
280+
// CHECK6-NEXT: call void @__kmpc_end_taskgroup(ptr @1, i32 %[[TID0:.*]])
281+
// CHECK6-NEXT: call void @__kmpc_taskgroup(ptr @1, i32 %[[TID0:.*]])
282+
// CHECK6-NEXT: %[[TID8:.*]] = call ptr @__kmpc_omp_task_alloc(ptr @1, i32 %[[TID0:.*]], i32 129, i64 80, i64 1, ptr @.omp_task_entry..[[ENTRY1:[0-9]+]])
283+
// CHECK6-NEXT: %[[TID9:.*]] = getelementptr inbounds nuw %struct.kmp_task_t_with_privates{{.*}}, ptr %[[TID8:.*]], i32 0, i32 0
284+
// CHECK6-NEXT: %[[TID10:.*]] = getelementptr inbounds nuw %struct.kmp_task_t{{.*}}, ptr %[[TID9:.*]], i32 0, i32 5
285+
// CHECK6-NEXT: store i64 0, ptr %[[TID10:.*]], align 8
286+
// CHECK6-NEXT: %[[TID11:.*]] = getelementptr inbounds nuw %struct.kmp_task_t{{.*}}, ptr %[[TID9:.*]], i32 0, i32 6
287+
// CHECK6-NEXT: store i64 9, ptr %[[TID11:.*]], align 8
288+
// CHECK6-NEXT: %[[TID12:.*]] = getelementptr inbounds nuw %struct.kmp_task_t{{.*}}, ptr %[[TID9:.*]], i32 0, i32 7
289+
// CHECK6-NEXT: store i64 1, ptr %[[TID12:.*]], align 8
290+
// CHECK6-NEXT: %[[TID13:.*]] = getelementptr inbounds nuw %struct.kmp_task_t{{.*}}, ptr %[[TID9:.*]], i32 0, i32 9
291+
// CHECK6-NEXT: call void @llvm.memset.p0.i64(ptr align 8 [[TID13:.*]], i8 0, i64 8, i1 false)
292+
// CHECK6-NEXT: %[[TID14:.*]] = load i64, ptr [[TID12:.*]], align 8
293+
// CHECK6-NEXT: call void @__kmpc_taskloop(ptr @1, i32 %[[TID0:.*]], ptr %[[TID8:.*]], i32 1, ptr %[[TID10:.*]], ptr %[[TID11:.*]], i64 %[[TID14:.*]], i32 1, i32 0, i64 0, ptr null)
294+
// CHECK6-NEXT: call void @__kmpc_end_taskgroup(ptr @1, i32 %[[TID0:.*]])
295+
// CHECK6-NEXT: ret void
296+
244297
#endif

0 commit comments

Comments
 (0)