109 lines · plain
1// RUN: fir-opt --lower-workdistribute %s | FileCheck %s2 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 workdistribute8// y = 3.0_real329// !$omp end target teams workdistribute10 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 : index20// 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 : index22// 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 : index24// CHECK: %[[VAL_79:.*]] = arith.remsi %[[VAL_73]], %[[VAL_77]]#1 : index25// CHECK: %[[VAL_80:.*]] = arith.addi %[[VAL_79]], %[[VAL_78]] : index26// CHECK: %[[VAL_81:.*]] = arith.divsi %[[VAL_73]], %[[VAL_77]]#1 : index27// CHECK: %[[VAL_82:.*]] = arith.remsi %[[VAL_81]], %[[VAL_75]]#1 : index28// CHECK: %[[VAL_83:.*]] = arith.addi %[[VAL_82]], %[[VAL_78]] : index29// 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.yield32// CHECK: }33// CHECK: } {omp.composite}34// CHECK: } {omp.composite}35// CHECK: omp.terminator36// CHECK: } {omp.composite}37// CHECK: omp.terminator38// CHECK: }39// CHECK: omp.terminator40// CHECK: }41// CHECK: omp.terminator42// CHECK: }43// CHECK: return44// CHECK: }45// CHECK: func.func private @_FortranAAssign(!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) attributes {fir.runtime}46 47module attributes {llvm.target_triple = "amdgcn-amd-amdhsa", omp.is_gpu = true, omp.is_target_device = true} {48func.func @x(%arr : !fir.ref<!fir.array<?x?xf32>>) {49 %c0 = arith.constant 0 : index50 %c1 = arith.constant 1 : index51 %c78 = arith.constant 78 : index52 %cst = arith.constant 3.000000e+00 : f3253 %0 = fir.alloca i3254 %1 = fir.alloca i3255 %c10 = arith.constant 10 : index56 %c20 = arith.constant 20 : index57 %194 = arith.subi %c10, %c1 : index58 %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 : index60 %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 : index66 %201 = fir.load %arg7 : !fir.ref<i32>67 %202 = fir.load %arg6 : !fir.ref<i32>68 %203 = fir.convert %202 : (i32) -> i6469 %204 = fir.convert %201 : (i32) -> i6470 %205 = fir.convert %204 : (i64) -> index71 %206 = arith.cmpi sgt, %205, %c0_0 : index72 %207 = fir.convert %203 : (i64) -> index73 %208 = arith.cmpi sgt, %207, %c0_0 : index74 %209 = arith.select %208, %207, %c0_0 : index75 %210 = arith.select %206, %205, %c0_0 : index76 %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 f3283 %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 : i3289 %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.terminator94 }95 omp.terminator96 }97 omp.terminator98 }99 return100}101 102func.func private @_FortranAAssign(!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) attributes {fir.runtime}103 104fir.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}109