|
| 1 | +// RUN: fir-opt --lower-workdistribute %s | FileCheck %s |
| 2 | + |
| 3 | +// Test lowering of workdistribute for a scalar assignment within a target teams workdistribute region. |
| 4 | +// The test checks that the scalar assignment is correctly lowered to wsloop and loop_nest operations. |
| 5 | + |
| 6 | +// Example Fortran code: |
| 7 | +// !$omp target teams workdistribute |
| 8 | +// y = 3.0_real32 |
| 9 | +// !$omp end target teams workdistribute |
| 10 | + |
| 11 | + |
| 12 | +// CHECK-LABEL: func.func @x( |
| 13 | +// CHECK: omp.target {{.*}} { |
| 14 | +// CHECK: omp.teams { |
| 15 | +// CHECK: omp.parallel { |
| 16 | +// CHECK: omp.distribute { |
| 17 | +// CHECK: omp.wsloop { |
| 18 | +// CHECK: omp.loop_nest (%[[VAL_73:.*]]) : index = (%[[VAL_66:.*]]) to (%[[VAL_72:.*]]) inclusive step (%[[VAL_67:.*]]) { |
| 19 | +// CHECK: %[[VAL_74:.*]] = arith.constant 0 : index |
| 20 | +// CHECK: %[[VAL_75:.*]]:3 = fir.box_dims %[[VAL_64:.*]], %[[VAL_74]] : (!fir.box<!fir.array<?x?xf32>>, index) -> (index, index, index) |
| 21 | +// CHECK: %[[VAL_76:.*]] = arith.constant 1 : index |
| 22 | +// CHECK: %[[VAL_77:.*]]:3 = fir.box_dims %[[VAL_64]], %[[VAL_76]] : (!fir.box<!fir.array<?x?xf32>>, index) -> (index, index, index) |
| 23 | +// CHECK: %[[VAL_78:.*]] = arith.constant 1 : index |
| 24 | +// CHECK: %[[VAL_79:.*]] = arith.remsi %[[VAL_73]], %[[VAL_77]]#1 : index |
| 25 | +// CHECK: %[[VAL_80:.*]] = arith.addi %[[VAL_79]], %[[VAL_78]] : index |
| 26 | +// CHECK: %[[VAL_81:.*]] = arith.divsi %[[VAL_73]], %[[VAL_77]]#1 : index |
| 27 | +// CHECK: %[[VAL_82:.*]] = arith.remsi %[[VAL_81]], %[[VAL_75]]#1 : index |
| 28 | +// CHECK: %[[VAL_83:.*]] = arith.addi %[[VAL_82]], %[[VAL_78]] : index |
| 29 | +// CHECK: %[[VAL_84:.*]] = fir.array_coor %[[VAL_64]] %[[VAL_83]], %[[VAL_80]] : (!fir.box<!fir.array<?x?xf32>>, index, index) -> !fir.ref<f32> |
| 30 | +// CHECK: fir.store %[[VAL_65:.*]] to %[[VAL_84]] : !fir.ref<f32> |
| 31 | +// CHECK: omp.yield |
| 32 | +// CHECK: } |
| 33 | +// CHECK: } {omp.composite} |
| 34 | +// CHECK: } {omp.composite} |
| 35 | +// CHECK: omp.terminator |
| 36 | +// CHECK: } {omp.composite} |
| 37 | +// CHECK: omp.terminator |
| 38 | +// CHECK: } |
| 39 | +// CHECK: omp.terminator |
| 40 | +// CHECK: } |
| 41 | +// CHECK: omp.terminator |
| 42 | +// CHECK: } |
| 43 | +// CHECK: return |
| 44 | +// CHECK: } |
| 45 | +// CHECK: func.func private @_FortranAAssign(!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) attributes {fir.runtime} |
| 46 | + |
| 47 | +module attributes {llvm.target_triple = "amdgcn-amd-amdhsa", omp.is_gpu = true, omp.is_target_device = true} { |
| 48 | +func.func @x(%arr : !fir.ref<!fir.array<?x?xf32>>) { |
| 49 | + %c0 = arith.constant 0 : index |
| 50 | + %c1 = arith.constant 1 : index |
| 51 | + %c78 = arith.constant 78 : index |
| 52 | + %cst = arith.constant 3.000000e+00 : f32 |
| 53 | + %0 = fir.alloca i32 |
| 54 | + %1 = fir.alloca i32 |
| 55 | + %c10 = arith.constant 10 : index |
| 56 | + %c20 = arith.constant 20 : index |
| 57 | + %194 = arith.subi %c10, %c1 : index |
| 58 | + %195 = omp.map.bounds lower_bound(%c0 : index) upper_bound(%194 : index) extent(%c10 : index) stride(%c1 : index) start_idx(%c1 : index) |
| 59 | + %196 = arith.subi %c20, %c1 : index |
| 60 | + %197 = omp.map.bounds lower_bound(%c0 : index) upper_bound(%196 : index) extent(%c20 : index) stride(%c1 : index) start_idx(%c1 : index) |
| 61 | + %198 = omp.map.info var_ptr(%arr : !fir.ref<!fir.array<?x?xf32>>, f32) map_clauses(implicit, tofrom) capture(ByRef) bounds(%195, %197) -> !fir.ref<!fir.array<?x?xf32>> {name = "y"} |
| 62 | + %199 = omp.map.info var_ptr(%1 : !fir.ref<i32>, i32) map_clauses(implicit, exit_release_or_enter_alloc) capture(ByCopy) -> !fir.ref<i32> {name = ""} |
| 63 | + %200 = omp.map.info var_ptr(%0 : !fir.ref<i32>, i32) map_clauses(implicit, exit_release_or_enter_alloc) capture(ByCopy) -> !fir.ref<i32> {name = ""} |
| 64 | + omp.target map_entries(%198 -> %arg5, %199 -> %arg6, %200 -> %arg7 : !fir.ref<!fir.array<?x?xf32>>, !fir.ref<i32>, !fir.ref<i32>) { |
| 65 | + %c0_0 = arith.constant 0 : index |
| 66 | + %201 = fir.load %arg7 : !fir.ref<i32> |
| 67 | + %202 = fir.load %arg6 : !fir.ref<i32> |
| 68 | + %203 = fir.convert %202 : (i32) -> i64 |
| 69 | + %204 = fir.convert %201 : (i32) -> i64 |
| 70 | + %205 = fir.convert %204 : (i64) -> index |
| 71 | + %206 = arith.cmpi sgt, %205, %c0_0 : index |
| 72 | + %207 = fir.convert %203 : (i64) -> index |
| 73 | + %208 = arith.cmpi sgt, %207, %c0_0 : index |
| 74 | + %209 = arith.select %208, %207, %c0_0 : index |
| 75 | + %210 = arith.select %206, %205, %c0_0 : index |
| 76 | + %211 = fir.shape %210, %209 : (index, index) -> !fir.shape<2> |
| 77 | + %212 = fir.declare %arg5(%211) {uniq_name = "_QFFaxpy_array_workdistributeEy"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.ref<!fir.array<?x?xf32>> |
| 78 | + %213 = fir.embox %212(%211) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>> |
| 79 | + omp.teams { |
| 80 | + %214 = fir.alloca !fir.box<!fir.array<?x?xf32>> {pinned} |
| 81 | + omp.workdistribute { |
| 82 | + %215 = fir.alloca f32 |
| 83 | + %216 = fir.embox %215 : (!fir.ref<f32>) -> !fir.box<f32> |
| 84 | + %217 = fir.shape %210, %209 : (index, index) -> !fir.shape<2> |
| 85 | + %218 = fir.embox %212(%217) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>> |
| 86 | + fir.store %218 to %214 : !fir.ref<!fir.box<!fir.array<?x?xf32>>> |
| 87 | + %219 = fir.address_of(@_QQclXf9c642d28e5bba1f07fa9a090b72f4fc) : !fir.ref<!fir.char<1,78>> |
| 88 | + %c39_i32 = arith.constant 39 : i32 |
| 89 | + %220 = fir.convert %214 : (!fir.ref<!fir.box<!fir.array<?x?xf32>>>) -> !fir.ref<!fir.box<none>> |
| 90 | + %221 = fir.convert %216 : (!fir.box<f32>) -> !fir.box<none> |
| 91 | + %222 = fir.convert %219 : (!fir.ref<!fir.char<1,78>>) -> !fir.ref<i8> |
| 92 | + fir.call @_FortranAAssign(%220, %221, %222, %c39_i32) : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) -> () |
| 93 | + omp.terminator |
| 94 | + } |
| 95 | + omp.terminator |
| 96 | + } |
| 97 | + omp.terminator |
| 98 | + } |
| 99 | + return |
| 100 | +} |
| 101 | + |
| 102 | +func.func private @_FortranAAssign(!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) attributes {fir.runtime} |
| 103 | + |
| 104 | +fir.global linkonce @_QQclXf9c642d28e5bba1f07fa9a090b72f4fc constant : !fir.char<1,78> { |
| 105 | + %0 = fir.string_lit "File: /work/github/skc7/llvm-project/build_fomp_reldebinfo/saxpy_tests/\00"(78) : !fir.char<1,78> |
| 106 | + fir.has_value %0 : !fir.char<1,78> |
| 107 | +} |
| 108 | +} |
0 commit comments