Skip to content

Commit aedb30f

Browse files
chandraghaleChandra Ghale
andauthored
[OpenMP] codegen support for masked combined construct parallel masked taskloop (#121741)
Added codegen support for combined masked constructs Parallel masked taskloop. Added implementation for EmitOMPParallelMaskedTaskLoopDirective. --------- Co-authored-by: Chandra Ghale <[email protected]>
1 parent 703e2d5 commit aedb30f

File tree

6 files changed

+89
-2
lines changed

6 files changed

+89
-2
lines changed

clang/docs/OpenMPSupport.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,9 @@ implementation.
320320
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
321321
| misc | nothing directive | :good:`done` | D123286 |
322322
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
323-
| misc | masked construct and related combined constructs | :part:`worked on` | D99995, D100514 |
323+
| misc | masked construct and related combined constructs | :good:`done` | D99995, D100514, PR-121741(parallel_masked_taskloop) |
324+
| | | | PR-121746(parallel_masked_task_loop_simd),PR-121914(masked_taskloop) |
325+
| | | | PR-121916(masked_taskloop_simd) |
324326
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
325327
| misc | default(firstprivate) & default(private) | :good:`done` | D75591 (firstprivate), D125912 (private) |
326328
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,8 @@ OpenMP Support
13031303
- Changed the OpenMP DeviceRTL to use 'generic' IR. The
13041304
``LIBOMPTARGET_DEVICE_ARCHITECTURES`` CMake argument is now unused and will
13051305
always build support for AMDGPU and NVPTX targets.
1306+
- Added support for combined masked constructs 'omp parallel masked taskloop',
1307+
'omp parallel masked taskloop simd','omp masked taskloop' and 'omp masked taskloop simd' directive.
13061308

13071309
Improvements
13081310
^^^^^^^^^^^^

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ void CodeGenFunction::EmitStmt(const Stmt *S, ArrayRef<const Attr *> Attrs) {
346346
cast<OMPParallelMasterTaskLoopDirective>(*S));
347347
break;
348348
case Stmt::OMPParallelMaskedTaskLoopDirectiveClass:
349-
llvm_unreachable("parallel masked taskloop directive not supported yet.");
349+
EmitOMPParallelMaskedTaskLoopDirective(
350+
cast<OMPParallelMaskedTaskLoopDirective>(*S));
350351
break;
351352
case Stmt::OMPParallelMasterTaskLoopSimdDirectiveClass:
352353
EmitOMPParallelMasterTaskLoopSimdDirective(

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8012,6 +8012,24 @@ void CodeGenFunction::EmitOMPParallelMasterTaskLoopDirective(
80128012
emitEmptyBoundParameters);
80138013
}
80148014

8015+
void CodeGenFunction::EmitOMPParallelMaskedTaskLoopDirective(
8016+
const OMPParallelMaskedTaskLoopDirective &S) {
8017+
auto &&CodeGen = [this, &S](CodeGenFunction &CGF, PrePostActionTy &Action) {
8018+
auto &&TaskLoopCodeGen = [&S](CodeGenFunction &CGF,
8019+
PrePostActionTy &Action) {
8020+
Action.Enter(CGF);
8021+
CGF.EmitOMPTaskLoopBasedDirective(S);
8022+
};
8023+
OMPLexicalScope Scope(CGF, S, OMPD_parallel, /*EmitPreInitStmt=*/false);
8024+
CGM.getOpenMPRuntime().emitMaskedRegion(CGF, TaskLoopCodeGen,
8025+
S.getBeginLoc());
8026+
};
8027+
auto LPCRegion =
8028+
CGOpenMPRuntime::LastprivateConditionalRAII::disable(*this, S);
8029+
emitCommonOMPParallelDirective(*this, S, OMPD_masked_taskloop, CodeGen,
8030+
emitEmptyBoundParameters);
8031+
}
8032+
80158033
void CodeGenFunction::EmitOMPParallelMasterTaskLoopSimdDirective(
80168034
const OMPParallelMasterTaskLoopSimdDirective &S) {
80178035
auto &&CodeGen = [this, &S](CodeGenFunction &CGF, PrePostActionTy &Action) {

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3874,6 +3874,8 @@ class CodeGenFunction : public CodeGenTypeCache {
38743874
EmitOMPMasterTaskLoopSimdDirective(const OMPMasterTaskLoopSimdDirective &S);
38753875
void EmitOMPParallelMasterTaskLoopDirective(
38763876
const OMPParallelMasterTaskLoopDirective &S);
3877+
void EmitOMPParallelMaskedTaskLoopDirective(
3878+
const OMPParallelMaskedTaskLoopDirective &S);
38773879
void EmitOMPParallelMasterTaskLoopSimdDirective(
38783880
const OMPParallelMasterTaskLoopSimdDirective &S);
38793881
void EmitOMPDistributeDirective(const OMPDistributeDirective &S);
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --prefix-filecheck-ir-name _ --version 5
2+
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -fopenmp-version=52 -x c -emit-llvm %s -o - | FileCheck %s
3+
// expected-no-diagnostics
4+
#define N 100
5+
void parallel_masked_taskloop(){
6+
#pragma omp parallel masked taskloop
7+
for( int i = 0; i < N; i++)
8+
;
9+
10+
}
11+
12+
int main()
13+
{
14+
parallel_masked_taskloop();
15+
}
16+
// CHECK-LABEL: define dso_local void @parallel_masked_taskloop(
17+
// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
18+
// CHECK-NEXT: [[ENTRY:.*:]]
19+
// CHECK-NEXT: call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @[[GLOB1:[0-9]+]], i32 0, ptr @parallel_masked_taskloop.omp_outlined)
20+
// CHECK-NEXT: ret void
21+
//
22+
//
23+
// CHECK-LABEL: define internal void @parallel_masked_taskloop.omp_outlined(
24+
// CHECK-SAME: ptr noalias noundef [[DOTGLOBAL_TID_:%.*]], ptr noalias noundef [[DOTBOUND_TID_:%.*]]) #[[ATTR1:[0-9]+]] {
25+
// CHECK-NEXT: [[ENTRY:.*:]]
26+
// CHECK-NEXT: [[DOTGLOBAL_TID__ADDR:%.*]] = alloca ptr, align 8
27+
// CHECK-NEXT: [[DOTBOUND_TID__ADDR:%.*]] = alloca ptr, align 8
28+
// CHECK-NEXT: [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]], align 1
29+
// CHECK-NEXT: [[TMP:%.*]] = alloca i32, align 4
30+
// CHECK-NEXT: store ptr [[DOTGLOBAL_TID_]], ptr [[DOTGLOBAL_TID__ADDR]], align 8
31+
// CHECK-NEXT: store ptr [[DOTBOUND_TID_]], ptr [[DOTBOUND_TID__ADDR]], align 8
32+
// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
33+
// CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4
34+
// CHECK-NEXT: [[TMP2:%.*]] = call i32 @__kmpc_masked(ptr @[[GLOB1]], i32 [[TMP1]], i32 0)
35+
// CHECK-NEXT: [[TMP3:%.*]] = icmp ne i32 [[TMP2]], 0
36+
// CHECK-NEXT: br i1 [[TMP3]], label %[[OMP_IF_THEN:.*]], label %[[OMP_IF_END:.*]]
37+
// CHECK: [[OMP_IF_THEN]]:
38+
// CHECK-NEXT: call void @__kmpc_taskgroup(ptr @[[GLOB1]], i32 [[TMP1]])
39+
// CHECK-NEXT: [[TMP4:%.*]] = call ptr @__kmpc_omp_task_alloc(ptr @[[GLOB1]], i32 [[TMP1]], i32 1, i64 80, i64 0, ptr @.omp_task_entry.)
40+
// CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T_WITH_PRIVATES:%.*]], ptr [[TMP4]], i32 0, i32 0
41+
// CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T:%.*]], ptr [[TMP5]], i32 0, i32 5
42+
// CHECK-NEXT: store i64 0, ptr [[TMP6]], align 8
43+
// CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T]], ptr [[TMP5]], i32 0, i32 6
44+
// CHECK-NEXT: store i64 99, ptr [[TMP7]], align 8
45+
// CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T]], ptr [[TMP5]], i32 0, i32 7
46+
// CHECK-NEXT: store i64 1, ptr [[TMP8]], align 8
47+
// CHECK-NEXT: [[TMP9:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T]], ptr [[TMP5]], i32 0, i32 9
48+
// CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 8 [[TMP9]], i8 0, i64 8, i1 false)
49+
// CHECK-NEXT: [[TMP10:%.*]] = load i64, ptr [[TMP8]], align 8
50+
// CHECK-NEXT: call void @__kmpc_taskloop(ptr @[[GLOB1]], i32 [[TMP1]], ptr [[TMP4]], i32 1, ptr [[TMP6]], ptr [[TMP7]], i64 [[TMP10]], i32 1, i32 0, i64 0, ptr null)
51+
// CHECK-NEXT: call void @__kmpc_end_taskgroup(ptr @[[GLOB1]], i32 [[TMP1]])
52+
// CHECK-NEXT: call void @__kmpc_end_masked(ptr @[[GLOB1]], i32 [[TMP1]])
53+
// CHECK-NEXT: br label %[[OMP_IF_END]]
54+
// CHECK: [[OMP_IF_END]]:
55+
// CHECK-NEXT: ret void
56+
//
57+
// CHECK-LABEL: define dso_local i32 @main(
58+
// CHECK-SAME: ) #[[ATTR0]] {
59+
// CHECK-NEXT: [[ENTRY:.*:]]
60+
// CHECK-NEXT: call void @parallel_masked_taskloop()
61+
// CHECK-NEXT: ret i32 0
62+

0 commit comments

Comments
 (0)