1 // RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
3 // tests a wsloop private + firstprivate + reduction to make sure block structure
4 // is handled properly.
6 omp.private {type = private} @_QFwsloop_privateEi_private_ref_i32 : !llvm.ptr alloc {
7 ^bb0(%arg0: !llvm.ptr):
8 %0 = llvm.mlir.constant(1 : i64) : i64
9 %1 = llvm.alloca %0 x i32 {bindc_name = "i", pinned} : (i64) -> !llvm.ptr
10 omp.yield(%1 : !llvm.ptr)
13 llvm.func @foo_free(!llvm.ptr)
15 omp.private {type = firstprivate} @_QFwsloop_privateEc_firstprivate_ref_c8 : !llvm.ptr alloc {
16 ^bb0(%arg0: !llvm.ptr):
17 %0 = llvm.mlir.constant(1 : i64) : i64
18 %1 = llvm.alloca %0 x !llvm.array<1 x i8> {bindc_name = "c", pinned} : (i64) -> !llvm.ptr
19 omp.yield(%1 : !llvm.ptr)
21 ^bb0(%arg0: !llvm.ptr, %arg1: !llvm.ptr):
22 %0 = llvm.load %arg0 : !llvm.ptr -> !llvm.array<1 x i8>
23 llvm.store %0, %arg1 : !llvm.array<1 x i8>, !llvm.ptr
24 omp.yield(%arg1 : !llvm.ptr)
26 ^bb0(%arg0: !llvm.ptr):
27 llvm.call @foo_free(%arg0) : (!llvm.ptr) -> ()
31 omp.declare_reduction @max_f32 : f32 init {
33 %0 = llvm.mlir.constant(-3.40282347E+38 : f32) : f32
36 ^bb0(%arg0: f32, %arg1: f32):
37 %0 = llvm.intr.maxnum(%arg0, %arg1) {fastmathFlags = #llvm.fastmath<contract>} : (f32, f32) -> f32
41 llvm.func @wsloop_private_(%arg0: !llvm.ptr {fir.bindc_name = "y"}) attributes {fir.internal_name = "_QPwsloop_private", frame_pointer = #llvm.framePointerKind<all>, target_cpu = "x86-64"} {
42 %0 = llvm.mlir.constant(1 : i64) : i64
43 %1 = llvm.alloca %0 x f32 {bindc_name = "x"} : (i64) -> !llvm.ptr
44 %3 = llvm.alloca %0 x i32 {bindc_name = "i"} : (i64) -> !llvm.ptr
45 %5 = llvm.alloca %0 x !llvm.array<1 x i8> {bindc_name = "c"} : (i64) -> !llvm.ptr
46 %6 = llvm.mlir.constant(1 : i32) : i32
47 %7 = llvm.mlir.constant(10 : i32) : i32
48 %8 = llvm.mlir.constant(0 : i32) : i32
50 omp.wsloop private(@_QFwsloop_privateEc_firstprivate_ref_c8 %5 -> %arg1, @_QFwsloop_privateEi_private_ref_i32 %3 -> %arg2 : !llvm.ptr, !llvm.ptr) reduction(@max_f32 %1 -> %arg3 : !llvm.ptr) {
51 omp.loop_nest (%arg4) : i32 = (%8) to (%7) inclusive step (%6) {
60 // CHECK: call void {{.*}} @__kmpc_fork_call(ptr @1, i32 1, ptr @[[OUTLINED:.*]], ptr %{{.*}})
62 // CHECK: define internal void @[[OUTLINED:.*]]{{.*}} {
64 // First, check that all memory for privates and reductions is allocated.
65 // CHECK: omp.par.entry:
66 // CHECK: %[[CHR:.*]] = alloca [1 x i8], i64 1, align 1
67 // CHECK: %[[INT:.*]] = alloca i32, i64 1, align 4
68 // CHECK: %[[FLT:.*]] = alloca float, align 4
69 // CHECK: %[[RED_ARR:.*]] = alloca [1 x ptr], align 8
70 // CHECK: br label %[[LATE_ALLOC_BB:.*]]
72 // CHECK: [[LATE_ALLOC_BB]]:
73 // CHECK: br label %[[PRIVATE_CPY_BB:.*]]
75 // Second, check that first private was properly copied.
76 // CHECK: [[PRIVATE_CPY_BB:.*]]:
77 // CHECK: %[[CHR_VAL:.*]] = load [1 x i8], ptr %{{.*}}, align 1
78 // CHECK: store [1 x i8] %[[CHR_VAL]], ptr %[[CHR]], align 1
79 // CHECK: br label %[[RED_INIT_BB:.*]]
81 // Third, check that reduction init took place.
82 // CHECK: [[RED_INIT_BB]]:
83 // CHECK: store float 0x{{.*}}, ptr %[[FLT]], align 4
85 // Finally, check for the private dealloc region
86 // CHECK: call void @foo_free(ptr %[[CHR]])