Skip to content

Commit 6f558e0

Browse files
chandraghaleChandra Ghale
and
Chandra Ghale
authored
[OpenMP] codegen support for masked combined construct masked taskloop (#121914)
Added codegen support for combined masked constructs `masked taskloop.` Added implementation for `EmitOMPMaskedTaskLoopDirective`. --------- Co-authored-by: Chandra Ghale <[email protected]>
1 parent b861539 commit 6f558e0

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ void CodeGenFunction::EmitStmt(const Stmt *S, ArrayRef<const Attr *> Attrs) {
332332
EmitOMPMasterTaskLoopDirective(cast<OMPMasterTaskLoopDirective>(*S));
333333
break;
334334
case Stmt::OMPMaskedTaskLoopDirectiveClass:
335-
llvm_unreachable("masked taskloop directive not supported yet.");
335+
EmitOMPMaskedTaskLoopDirective(cast<OMPMaskedTaskLoopDirective>(*S));
336336
break;
337337
case Stmt::OMPMasterTaskLoopSimdDirectiveClass:
338338
EmitOMPMasterTaskLoopSimdDirective(

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7982,6 +7982,18 @@ void CodeGenFunction::EmitOMPMasterTaskLoopDirective(
79827982
CGM.getOpenMPRuntime().emitMasterRegion(*this, CodeGen, S.getBeginLoc());
79837983
}
79847984

7985+
void CodeGenFunction::EmitOMPMaskedTaskLoopDirective(
7986+
const OMPMaskedTaskLoopDirective &S) {
7987+
auto &&CodeGen = [this, &S](CodeGenFunction &CGF, PrePostActionTy &Action) {
7988+
Action.Enter(CGF);
7989+
EmitOMPTaskLoopBasedDirective(S);
7990+
};
7991+
auto LPCRegion =
7992+
CGOpenMPRuntime::LastprivateConditionalRAII::disable(*this, S);
7993+
OMPLexicalScope Scope(*this, S, std::nullopt, /*EmitPreInitStmt=*/false);
7994+
CGM.getOpenMPRuntime().emitMaskedRegion(*this, CodeGen, S.getBeginLoc());
7995+
}
7996+
79857997
void CodeGenFunction::EmitOMPMasterTaskLoopSimdDirective(
79867998
const OMPMasterTaskLoopSimdDirective &S) {
79877999
auto &&CodeGen = [this, &S](CodeGenFunction &CGF, PrePostActionTy &Action) {

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3870,6 +3870,7 @@ class CodeGenFunction : public CodeGenTypeCache {
38703870
void EmitOMPTaskLoopDirective(const OMPTaskLoopDirective &S);
38713871
void EmitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective &S);
38723872
void EmitOMPMasterTaskLoopDirective(const OMPMasterTaskLoopDirective &S);
3873+
void EmitOMPMaskedTaskLoopDirective(const OMPMaskedTaskLoopDirective &S);
38733874
void
38743875
EmitOMPMasterTaskLoopSimdDirective(const OMPMasterTaskLoopSimdDirective &S);
38753876
void
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 masked_taskloop(){
6+
#pragma omp masked taskloop
7+
for( int i = 0; i < N; i++)
8+
;
9+
10+
}
11+
12+
int main()
13+
{
14+
masked_taskloop();
15+
}
16+
// CHECK-LABEL: define dso_local void @masked_taskloop(
17+
// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
18+
// CHECK-NEXT: [[ENTRY:.*:]]
19+
// CHECK-NEXT: [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]], align 1
20+
// CHECK-NEXT: [[TMP:%.*]] = alloca i32, align 4
21+
// CHECK-NEXT: [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1:[0-9]+]])
22+
// CHECK-NEXT: [[TMP1:%.*]] = call i32 @__kmpc_masked(ptr @[[GLOB1]], i32 [[TMP0]], i32 0)
23+
// CHECK-NEXT: [[TMP2:%.*]] = icmp ne i32 [[TMP1]], 0
24+
// CHECK-NEXT: br i1 [[TMP2]], label %[[OMP_IF_THEN:.*]], label %[[OMP_IF_END:.*]]
25+
// CHECK: [[OMP_IF_THEN]]:
26+
// CHECK-NEXT: call void @__kmpc_taskgroup(ptr @[[GLOB1]], i32 [[TMP0]])
27+
// CHECK-NEXT: [[TMP3:%.*]] = call ptr @__kmpc_omp_task_alloc(ptr @[[GLOB1]], i32 [[TMP0]], i32 1, i64 80, i64 0, ptr @.omp_task_entry.)
28+
// CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T_WITH_PRIVATES:%.*]], ptr [[TMP3]], i32 0, i32 0
29+
// CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T:%.*]], ptr [[TMP4]], i32 0, i32 5
30+
// CHECK-NEXT: store i64 0, ptr [[TMP5]], align 8
31+
// CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T]], ptr [[TMP4]], i32 0, i32 6
32+
// CHECK-NEXT: store i64 99, ptr [[TMP6]], align 8
33+
// CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T]], ptr [[TMP4]], i32 0, i32 7
34+
// CHECK-NEXT: store i64 1, ptr [[TMP7]], align 8
35+
// CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T]], ptr [[TMP4]], i32 0, i32 9
36+
// CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 8 [[TMP8]], i8 0, i64 8, i1 false)
37+
// CHECK-NEXT: [[TMP9:%.*]] = load i64, ptr [[TMP7]], align 8
38+
// CHECK-NEXT: call void @__kmpc_taskloop(ptr @[[GLOB1]], i32 [[TMP0]], ptr [[TMP3]], i32 1, ptr [[TMP5]], ptr [[TMP6]], i64 [[TMP9]], i32 1, i32 0, i64 0, ptr null)
39+
// CHECK-NEXT: call void @__kmpc_end_taskgroup(ptr @[[GLOB1]], i32 [[TMP0]])
40+
// CHECK-NEXT: call void @__kmpc_end_masked(ptr @[[GLOB1]], i32 [[TMP0]])
41+
// CHECK-NEXT: br label %[[OMP_IF_END]]
42+
// CHECK: [[OMP_IF_END]]:
43+
// CHECK-NEXT: ret void
44+
//
45+
// CHECK-LABEL: define dso_local i32 @main(
46+
// CHECK-SAME: ) #[[ATTR0]] {
47+
// CHECK-NEXT: [[ENTRY:.*:]]
48+
// CHECK-NEXT: call void @masked_taskloop()
49+
// CHECK-NEXT: ret i32 0
50+

0 commit comments

Comments
 (0)