Skip to content

Commit 1d2eea9

Browse files
chandraghaleChandra Ghale
and
Chandra Ghale
authored
[OpenMP] codegen support for masked combined construct masked taskloop simd (#121916)
Added codegen support for combined masked constructs `masked taskloop simd`. Added implementation for `EmitOMPMaskedTaskLoopSimdDirective`. Co-authored-by: Chandra Ghale <[email protected]>
1 parent 9dee7c4 commit 1d2eea9

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

clang/lib/CodeGen/CGStmt.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ void CodeGenFunction::EmitStmt(const Stmt *S, ArrayRef<const Attr *> Attrs) {
339339
cast<OMPMasterTaskLoopSimdDirective>(*S));
340340
break;
341341
case Stmt::OMPMaskedTaskLoopSimdDirectiveClass:
342-
llvm_unreachable("masked taskloop simd directive not supported yet.");
342+
EmitOMPMaskedTaskLoopSimdDirective(
343+
cast<OMPMaskedTaskLoopSimdDirective>(*S));
343344
break;
344345
case Stmt::OMPParallelMasterTaskLoopDirectiveClass:
345346
EmitOMPParallelMasterTaskLoopDirective(

clang/lib/CodeGen/CGStmtOpenMP.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -7994,6 +7994,18 @@ void CodeGenFunction::EmitOMPMasterTaskLoopSimdDirective(
79947994
CGM.getOpenMPRuntime().emitMasterRegion(*this, CodeGen, S.getBeginLoc());
79957995
}
79967996

7997+
void CodeGenFunction::EmitOMPMaskedTaskLoopSimdDirective(
7998+
const OMPMaskedTaskLoopSimdDirective &S) {
7999+
auto &&CodeGen = [this, &S](CodeGenFunction &CGF, PrePostActionTy &Action) {
8000+
Action.Enter(CGF);
8001+
EmitOMPTaskLoopBasedDirective(S);
8002+
};
8003+
auto LPCRegion =
8004+
CGOpenMPRuntime::LastprivateConditionalRAII::disable(*this, S);
8005+
OMPLexicalScope Scope(*this, S);
8006+
CGM.getOpenMPRuntime().emitMaskedRegion(*this, CodeGen, S.getBeginLoc());
8007+
}
8008+
79978009
void CodeGenFunction::EmitOMPParallelMasterTaskLoopDirective(
79988010
const OMPParallelMasterTaskLoopDirective &S) {
79998011
auto &&CodeGen = [this, &S](CodeGenFunction &CGF, PrePostActionTy &Action) {

clang/lib/CodeGen/CodeGenFunction.h

+2
Original file line numberDiff line numberDiff line change
@@ -3872,6 +3872,8 @@ class CodeGenFunction : public CodeGenTypeCache {
38723872
void EmitOMPMasterTaskLoopDirective(const OMPMasterTaskLoopDirective &S);
38733873
void
38743874
EmitOMPMasterTaskLoopSimdDirective(const OMPMasterTaskLoopSimdDirective &S);
3875+
void
3876+
EmitOMPMaskedTaskLoopSimdDirective(const OMPMaskedTaskLoopSimdDirective &S);
38753877
void EmitOMPParallelMasterTaskLoopDirective(
38763878
const OMPParallelMasterTaskLoopDirective &S);
38773879
void EmitOMPParallelMaskedTaskLoopDirective(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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_simd(){
6+
#pragma omp masked taskloop simd
7+
for( int i = 0; i < N; i++)
8+
;
9+
10+
}
11+
12+
int main()
13+
{
14+
masked_taskloop_simd();
15+
}
16+
// CHECK-LABEL: define dso_local void @masked_taskloop_simd(
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_simd()
49+
// CHECK-NEXT: ret i32 0

0 commit comments

Comments
 (0)