1 // RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
3 // Only check the overall shape of the code and the presence of relevant
4 // runtime calls. Actual IR checking is done at the OpenMPIRBuilder level.
6 omp.reduction.declare @add_f32 : f32
9 %0 = llvm.mlir.constant(0.0 : f32) : f32
13 ^bb1(%arg0: f32, %arg1: f32):
14 %1 = llvm.fadd %arg0, %arg1 : f32
18 ^bb2(%arg2: !llvm.ptr<f32>, %arg3: !llvm.ptr<f32>):
19 %2 = llvm.load %arg3 : !llvm.ptr<f32>
20 llvm.atomicrmw fadd %arg2, %2 monotonic : !llvm.ptr<f32>, f32
24 // CHECK-LABEL: @simple_reduction
25 llvm.func @simple_reduction(%lb : i64, %ub : i64, %step : i64) {
26 %c1 = llvm.mlir.constant(1 : i32) : i32
27 %0 = llvm.alloca %c1 x i32 : (i32) -> !llvm.ptr<f32>
29 omp.wsloop reduction(@add_f32 -> %0 : !llvm.ptr<f32>)
30 for (%iv) : i64 = (%lb) to (%ub) step (%step) {
31 %1 = llvm.mlir.constant(2.0 : f32) : f32
32 omp.reduction %1, %0 : f32, !llvm.ptr<f32>
40 // Call to the outlined function.
41 // CHECK: call void {{.*}} @__kmpc_fork_call
42 // CHECK-SAME: @[[OUTLINED:[A-Za-z_.][A-Za-z0-9_.]*]]
45 // CHECK: define internal void @[[OUTLINED]]
47 // Private reduction variable and its initialization.
48 // CHECK: %[[PRIVATE:.+]] = alloca float
49 // CHECK: store float 0.000000e+00, ptr %[[PRIVATE]]
51 // Call to the reduction function.
52 // CHECK: call i32 @__kmpc_reduce
53 // CHECK-SAME: @[[REDFUNC:[A-Za-z_.][A-Za-z0-9_.]*]]
56 // CHECK: %[[PARTIAL:.+]] = load float, ptr %[[PRIVATE]]
57 // CHECK: atomicrmw fadd ptr %{{.*}}, float %[[PARTIAL]]
59 // Non-atomic reduction:
61 // CHECK: call void @__kmpc_end_reduce
62 // CHECK: br label %[[FINALIZE:.+]]
64 // CHECK: [[FINALIZE]]:
65 // CHECK: call void @__kmpc_barrier
67 // Update of the private variable using the reduction region
68 // (the body block currently comes after all the other blocks).
69 // CHECK: %[[PARTIAL:.+]] = load float, ptr %[[PRIVATE]]
70 // CHECK: %[[UPDATED:.+]] = fadd float %[[PARTIAL]], 2.000000e+00
71 // CHECK: store float %[[UPDATED]], ptr %[[PRIVATE]]
73 // Reduction function.
74 // CHECK: define internal void @[[REDFUNC]]