Skip to content

Commit 0c790fc

Browse files
author
Chandra Ghale
committed
codegen support for masked combined construct parallel masked taskloop
1 parent d34f7ea commit 0c790fc

File tree

4 files changed

+84
-1
lines changed

4 files changed

+84
-1
lines changed

clang/lib/CodeGen/CGStmt.cpp

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

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8024,6 +8024,24 @@ void CodeGenFunction::EmitOMPParallelMasterTaskLoopDirective(
80248024
emitEmptyBoundParameters);
80258025
}
80268026

8027+
void CodeGenFunction::EmitOMPParallelMaskedTaskLoopDirective(
8028+
const OMPParallelMaskedTaskLoopDirective &S) {
8029+
auto &&CodeGen = [this, &S](CodeGenFunction &CGF, PrePostActionTy &Action) {
8030+
auto &&TaskLoopCodeGen = [&S](CodeGenFunction &CGF,
8031+
PrePostActionTy &Action) {
8032+
Action.Enter(CGF);
8033+
CGF.EmitOMPTaskLoopBasedDirective(S);
8034+
};
8035+
OMPLexicalScope Scope(CGF, S, OMPD_parallel, /*EmitPreInitStmt=*/false);
8036+
CGM.getOpenMPRuntime().emitMaskedRegion(CGF, TaskLoopCodeGen,
8037+
S.getBeginLoc());
8038+
};
8039+
auto LPCRegion =
8040+
CGOpenMPRuntime::LastprivateConditionalRAII::disable(*this, S);
8041+
emitCommonOMPParallelDirective(*this, S, OMPD_masked_taskloop, CodeGen,
8042+
emitEmptyBoundParameters);
8043+
}
8044+
80278045
void CodeGenFunction::EmitOMPParallelMasterTaskLoopSimdDirective(
80288046
const OMPParallelMasterTaskLoopSimdDirective &S) {
80298047
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
@@ -3867,6 +3867,8 @@ class CodeGenFunction : public CodeGenTypeCache {
38673867
EmitOMPMasterTaskLoopSimdDirective(const OMPMasterTaskLoopSimdDirective &S);
38683868
void EmitOMPParallelMasterTaskLoopDirective(
38693869
const OMPParallelMasterTaskLoopDirective &S);
3870+
void EmitOMPParallelMaskedTaskLoopDirective(
3871+
const OMPParallelMaskedTaskLoopDirective &S);
38703872
void EmitOMPParallelMasterTaskLoopSimdDirective(
38713873
const OMPParallelMasterTaskLoopSimdDirective &S);
38723874
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)