Skip to content

Commit 30f9a4f

Browse files
chandraghaleChandra Ghale
and
Chandra Ghale
authored
[OpenMP] codegen support for masked combined construct parallel masked taskloop simd. (#121746)
Added codegen support for combined masked constructs `Parallel masked taskloop simd`. Added implementation for `EmitOMPParallelMaskedTaskLoopSimdDirective`. Co-authored-by: Chandra Ghale <[email protected]>
1 parent f879da7 commit 30f9a4f

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

clang/lib/CodeGen/CGStmt.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ void CodeGenFunction::EmitStmt(const Stmt *S, ArrayRef<const Attr *> Attrs) {
355355
cast<OMPParallelMasterTaskLoopSimdDirective>(*S));
356356
break;
357357
case Stmt::OMPParallelMaskedTaskLoopSimdDirectiveClass:
358-
llvm_unreachable(
359-
"parallel masked taskloop simd directive not supported yet.");
358+
EmitOMPParallelMaskedTaskLoopSimdDirective(
359+
cast<OMPParallelMaskedTaskLoopSimdDirective>(*S));
360360
break;
361361
case Stmt::OMPDistributeDirectiveClass:
362362
EmitOMPDistributeDirective(cast<OMPDistributeDirective>(*S));

clang/lib/CodeGen/CGStmtOpenMP.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -8072,6 +8072,24 @@ void CodeGenFunction::EmitOMPParallelMasterTaskLoopSimdDirective(
80728072
emitEmptyBoundParameters);
80738073
}
80748074

8075+
void CodeGenFunction::EmitOMPParallelMaskedTaskLoopSimdDirective(
8076+
const OMPParallelMaskedTaskLoopSimdDirective &S) {
8077+
auto &&CodeGen = [this, &S](CodeGenFunction &CGF, PrePostActionTy &Action) {
8078+
auto &&TaskLoopCodeGen = [&S](CodeGenFunction &CGF,
8079+
PrePostActionTy &Action) {
8080+
Action.Enter(CGF);
8081+
CGF.EmitOMPTaskLoopBasedDirective(S);
8082+
};
8083+
OMPLexicalScope Scope(CGF, S, OMPD_parallel, /*EmitPreInitStmt=*/false);
8084+
CGM.getOpenMPRuntime().emitMaskedRegion(CGF, TaskLoopCodeGen,
8085+
S.getBeginLoc());
8086+
};
8087+
auto LPCRegion =
8088+
CGOpenMPRuntime::LastprivateConditionalRAII::disable(*this, S);
8089+
emitCommonOMPParallelDirective(*this, S, OMPD_masked_taskloop_simd, CodeGen,
8090+
emitEmptyBoundParameters);
8091+
}
8092+
80758093
// Generate the instructions for '#pragma omp target update' directive.
80768094
void CodeGenFunction::EmitOMPTargetUpdateDirective(
80778095
const OMPTargetUpdateDirective &S) {

clang/lib/CodeGen/CodeGenFunction.h

+2
Original file line numberDiff line numberDiff line change
@@ -3885,6 +3885,8 @@ class CodeGenFunction : public CodeGenTypeCache {
38853885
const OMPParallelMaskedTaskLoopDirective &S);
38863886
void EmitOMPParallelMasterTaskLoopSimdDirective(
38873887
const OMPParallelMasterTaskLoopSimdDirective &S);
3888+
void EmitOMPParallelMaskedTaskLoopSimdDirective(
3889+
const OMPParallelMaskedTaskLoopSimdDirective &S);
38883890
void EmitOMPDistributeDirective(const OMPDistributeDirective &S);
38893891
void EmitOMPDistributeParallelForDirective(
38903892
const OMPDistributeParallelForDirective &S);
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_simd(){
6+
#pragma omp parallel masked taskloop simd
7+
for( int i = 0; i < N; i++)
8+
;
9+
10+
}
11+
12+
int main()
13+
{
14+
parallel_masked_taskloop_simd();
15+
}
16+
// CHECK-LABEL: define dso_local void @parallel_masked_taskloop_simd(
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_simd.omp_outlined)
20+
// CHECK-NEXT: ret void
21+
//
22+
//
23+
// CHECK-LABEL: define internal void @parallel_masked_taskloop_simd.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_simd()
61+
// CHECK-NEXT: ret i32 0
62+

0 commit comments

Comments
 (0)