| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // RUN: fir-opt --bufferize-hlfir %s | FileCheck %s | ||
|
|
||
| // CHECK-LABEL: func.func @simple( | ||
| // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<42xi32>>) { | ||
| // CHECK: omp.parallel { | ||
| // CHECK: omp.workshare { | ||
| // CHECK: %[[VAL_1:.*]] = arith.constant 42 : index | ||
| // CHECK: %[[VAL_2:.*]] = arith.constant 1 : i32 | ||
| // CHECK: %[[VAL_3:.*]] = fir.shape %[[VAL_1]] : (index) -> !fir.shape<1> | ||
| // CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0]](%[[VAL_3]]) {uniq_name = "array"} : (!fir.ref<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>>) | ||
| // CHECK: %[[VAL_5:.*]] = fir.allocmem !fir.array<42xi32> {bindc_name = ".tmp.array", uniq_name = ""} | ||
| // CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_5]](%[[VAL_3]]) {uniq_name = ".tmp.array"} : (!fir.heap<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.heap<!fir.array<42xi32>>, !fir.heap<!fir.array<42xi32>>) | ||
| // CHECK: %[[VAL_7:.*]] = arith.constant true | ||
| // CHECK: %[[VAL_8:.*]] = arith.constant 1 : index | ||
| // CHECK: omp.workshare_loop_wrapper { | ||
| // CHECK: omp.loop_nest (%[[VAL_9:.*]]) : index = (%[[VAL_8]]) to (%[[VAL_1]]) inclusive step (%[[VAL_8]]) { | ||
| // CHECK: %[[VAL_10:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_9]]) : (!fir.ref<!fir.array<42xi32>>, index) -> !fir.ref<i32> | ||
| // CHECK: %[[VAL_11:.*]] = fir.load %[[VAL_10]] : !fir.ref<i32> | ||
| // CHECK: %[[VAL_12:.*]] = arith.subi %[[VAL_11]], %[[VAL_2]] : i32 | ||
| // CHECK: %[[VAL_13:.*]] = hlfir.designate %[[VAL_6]]#0 (%[[VAL_9]]) : (!fir.heap<!fir.array<42xi32>>, index) -> !fir.ref<i32> | ||
| // CHECK: hlfir.assign %[[VAL_12]] to %[[VAL_13]] temporary_lhs : i32, !fir.ref<i32> | ||
| // CHECK: omp.yield | ||
| // CHECK: } | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: %[[VAL_14:.*]] = fir.undefined tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| // CHECK: %[[VAL_15:.*]] = fir.insert_value %[[VAL_14]], %[[VAL_7]], [1 : index] : (tuple<!fir.heap<!fir.array<42xi32>>, i1>, i1) -> tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| // CHECK: %[[VAL_16:.*]] = fir.insert_value %[[VAL_15]], %[[VAL_6]]#0, [0 : index] : (tuple<!fir.heap<!fir.array<42xi32>>, i1>, !fir.heap<!fir.array<42xi32>>) -> tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| // CHECK: hlfir.assign %[[VAL_6]]#0 to %[[VAL_4]]#0 : !fir.heap<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>> | ||
| // CHECK: fir.freemem %[[VAL_6]]#0 : !fir.heap<!fir.array<42xi32>> | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: return | ||
| // CHECK: } | ||
| func.func @simple(%arg: !fir.ref<!fir.array<42xi32>>) { | ||
| omp.parallel { | ||
| omp.workshare { | ||
| %c42 = arith.constant 42 : index | ||
| %c1_i32 = arith.constant 1 : i32 | ||
| %shape = fir.shape %c42 : (index) -> !fir.shape<1> | ||
| %array:2 = hlfir.declare %arg(%shape) {uniq_name = "array"} : (!fir.ref<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>>) | ||
| %elemental = hlfir.elemental %shape unordered : (!fir.shape<1>) -> !hlfir.expr<42xi32> { | ||
| ^bb0(%i: index): | ||
| %ref = hlfir.designate %array#0 (%i) : (!fir.ref<!fir.array<42xi32>>, index) -> !fir.ref<i32> | ||
| %val = fir.load %ref : !fir.ref<i32> | ||
| %sub = arith.subi %val, %c1_i32 : i32 | ||
| hlfir.yield_element %sub : i32 | ||
| } | ||
| hlfir.assign %elemental to %array#0 : !hlfir.expr<42xi32>, !fir.ref<!fir.array<42xi32>> | ||
| hlfir.destroy %elemental : !hlfir.expr<42xi32> | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| return | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| // RUN: fir-opt --split-input-file --lower-workshare --allow-unregistered-dialect %s | FileCheck %s | ||
|
|
||
| // checks: | ||
| // nowait on final omp.single | ||
| func.func @wsfunc(%arg0: !fir.ref<!fir.array<42xi32>>) { | ||
| omp.parallel { | ||
| omp.workshare { | ||
| %c42 = arith.constant 42 : index | ||
| %c1_i32 = arith.constant 1 : i32 | ||
| %0 = fir.shape %c42 : (index) -> !fir.shape<1> | ||
| %1:2 = hlfir.declare %arg0(%0) {uniq_name = "array"} : (!fir.ref<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>>) | ||
| %2 = fir.allocmem !fir.array<42xi32> {bindc_name = ".tmp.array", uniq_name = ""} | ||
| %3:2 = hlfir.declare %2(%0) {uniq_name = ".tmp.array"} : (!fir.heap<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.heap<!fir.array<42xi32>>, !fir.heap<!fir.array<42xi32>>) | ||
| %true = arith.constant true | ||
| %c1 = arith.constant 1 : index | ||
| omp.workshare_loop_wrapper { | ||
| omp.loop_nest (%arg1) : index = (%c1) to (%c42) inclusive step (%c1) { | ||
| %7 = hlfir.designate %1#0 (%arg1) : (!fir.ref<!fir.array<42xi32>>, index) -> !fir.ref<i32> | ||
| %8 = fir.load %7 : !fir.ref<i32> | ||
| %9 = arith.subi %8, %c1_i32 : i32 | ||
| %10 = hlfir.designate %3#0 (%arg1) : (!fir.heap<!fir.array<42xi32>>, index) -> !fir.ref<i32> | ||
| hlfir.assign %9 to %10 temporary_lhs : i32, !fir.ref<i32> | ||
| omp.yield | ||
| } | ||
| omp.terminator | ||
| } | ||
| %4 = fir.undefined tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| %5 = fir.insert_value %4, %true, [1 : index] : (tuple<!fir.heap<!fir.array<42xi32>>, i1>, i1) -> tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| %6 = fir.insert_value %5, %3#0, [0 : index] : (tuple<!fir.heap<!fir.array<42xi32>>, i1>, !fir.heap<!fir.array<42xi32>>) -> tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| hlfir.assign %3#0 to %1#0 : !fir.heap<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>> | ||
| fir.freemem %3#0 : !fir.heap<!fir.array<42xi32>> | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| return | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // checks: | ||
| // fir.alloca hoisted out and copyprivate'd | ||
| func.func @wsfunc(%arg0: !fir.ref<!fir.array<42xi32>>) { | ||
| omp.workshare { | ||
| %c1_i32 = arith.constant 1 : i32 | ||
| %alloc = fir.alloca i32 | ||
| fir.store %c1_i32 to %alloc : !fir.ref<i32> | ||
| %c42 = arith.constant 42 : index | ||
| %0 = fir.shape %c42 : (index) -> !fir.shape<1> | ||
| %1:2 = hlfir.declare %arg0(%0) {uniq_name = "array"} : (!fir.ref<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>>) | ||
| %2 = fir.allocmem !fir.array<42xi32> {bindc_name = ".tmp.array", uniq_name = ""} | ||
| %3:2 = hlfir.declare %2(%0) {uniq_name = ".tmp.array"} : (!fir.heap<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.heap<!fir.array<42xi32>>, !fir.heap<!fir.array<42xi32>>) | ||
| %true = arith.constant true | ||
| %c1 = arith.constant 1 : index | ||
| omp.workshare_loop_wrapper { | ||
| omp.loop_nest (%arg1) : index = (%c1) to (%c42) inclusive step (%c1) { | ||
| %7 = hlfir.designate %1#0 (%arg1) : (!fir.ref<!fir.array<42xi32>>, index) -> !fir.ref<i32> | ||
| %8 = fir.load %7 : !fir.ref<i32> | ||
| %ld = fir.load %alloc : !fir.ref<i32> | ||
| %n8 = arith.subi %8, %ld : i32 | ||
| %9 = arith.subi %n8, %c1_i32 : i32 | ||
| %10 = hlfir.designate %3#0 (%arg1) : (!fir.heap<!fir.array<42xi32>>, index) -> !fir.ref<i32> | ||
| hlfir.assign %9 to %10 temporary_lhs : i32, !fir.ref<i32> | ||
| omp.yield | ||
| } | ||
| omp.terminator | ||
| } | ||
| %4 = fir.undefined tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| %5 = fir.insert_value %4, %true, [1 : index] : (tuple<!fir.heap<!fir.array<42xi32>>, i1>, i1) -> tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| %6 = fir.insert_value %5, %3#0, [0 : index] : (tuple<!fir.heap<!fir.array<42xi32>>, i1>, !fir.heap<!fir.array<42xi32>>) -> tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| "test.test1"(%alloc) : (!fir.ref<i32>) -> () | ||
| hlfir.assign %3#0 to %1#0 : !fir.heap<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>> | ||
| fir.freemem %3#0 : !fir.heap<!fir.array<42xi32>> | ||
| omp.terminator | ||
| } | ||
| return | ||
| } | ||
|
|
||
| // CHECK-LABEL: func.func private @_workshare_copy_heap_42xi32( | ||
| // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.heap<!fir.array<42xi32>>>, | ||
| // CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.heap<!fir.array<42xi32>>>) { | ||
| // CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.heap<!fir.array<42xi32>>> | ||
| // CHECK: fir.store %[[VAL_2]] to %[[VAL_1]] : !fir.ref<!fir.heap<!fir.array<42xi32>>> | ||
| // CHECK: return | ||
| // CHECK: } | ||
|
|
||
| // CHECK-LABEL: func.func @wsfunc( | ||
| // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<42xi32>>) { | ||
| // CHECK: omp.parallel { | ||
| // CHECK: %[[VAL_1:.*]] = fir.alloca !fir.heap<!fir.array<42xi32>> | ||
| // CHECK: omp.single copyprivate(%[[VAL_1]] -> @_workshare_copy_heap_42xi32 : !fir.ref<!fir.heap<!fir.array<42xi32>>>) { | ||
| // CHECK: %[[VAL_2:.*]] = arith.constant 42 : index | ||
| // CHECK: %[[VAL_3:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1> | ||
| // CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0]](%[[VAL_3]]) {uniq_name = "array"} : (!fir.ref<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>>) | ||
| // CHECK: %[[VAL_5:.*]] = fir.allocmem !fir.array<42xi32> {bindc_name = ".tmp.array", uniq_name = ""} | ||
| // CHECK: fir.store %[[VAL_5]] to %[[VAL_1]] : !fir.ref<!fir.heap<!fir.array<42xi32>>> | ||
| // CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_5]](%[[VAL_3]]) {uniq_name = ".tmp.array"} : (!fir.heap<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.heap<!fir.array<42xi32>>, !fir.heap<!fir.array<42xi32>>) | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: %[[VAL_7:.*]] = arith.constant 42 : index | ||
| // CHECK: %[[VAL_8:.*]] = arith.constant 1 : i32 | ||
| // CHECK: %[[VAL_9:.*]] = fir.shape %[[VAL_7]] : (index) -> !fir.shape<1> | ||
| // CHECK: %[[VAL_10:.*]]:2 = hlfir.declare %[[VAL_0]](%[[VAL_9]]) {uniq_name = "array"} : (!fir.ref<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>>) | ||
| // CHECK: %[[VAL_11:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.heap<!fir.array<42xi32>>> | ||
| // CHECK: %[[VAL_12:.*]]:2 = hlfir.declare %[[VAL_11]](%[[VAL_9]]) {uniq_name = ".tmp.array"} : (!fir.heap<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.heap<!fir.array<42xi32>>, !fir.heap<!fir.array<42xi32>>) | ||
| // CHECK: %[[VAL_13:.*]] = arith.constant true | ||
| // CHECK: %[[VAL_14:.*]] = arith.constant 1 : index | ||
| // CHECK: omp.wsloop { | ||
| // CHECK: omp.loop_nest (%[[VAL_15:.*]]) : index = (%[[VAL_14]]) to (%[[VAL_7]]) inclusive step (%[[VAL_14]]) { | ||
| // CHECK: %[[VAL_16:.*]] = hlfir.designate %[[VAL_10]]#0 (%[[VAL_15]]) : (!fir.ref<!fir.array<42xi32>>, index) -> !fir.ref<i32> | ||
| // CHECK: %[[VAL_17:.*]] = fir.load %[[VAL_16]] : !fir.ref<i32> | ||
| // CHECK: %[[VAL_18:.*]] = arith.subi %[[VAL_17]], %[[VAL_8]] : i32 | ||
| // CHECK: %[[VAL_19:.*]] = hlfir.designate %[[VAL_12]]#0 (%[[VAL_15]]) : (!fir.heap<!fir.array<42xi32>>, index) -> !fir.ref<i32> | ||
| // CHECK: hlfir.assign %[[VAL_18]] to %[[VAL_19]] temporary_lhs : i32, !fir.ref<i32> | ||
| // CHECK: omp.yield | ||
| // CHECK: } | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: omp.single nowait { | ||
| // CHECK: %[[VAL_20:.*]] = fir.undefined tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| // CHECK: %[[VAL_21:.*]] = fir.insert_value %[[VAL_20]], %[[VAL_13]], [1 : index] : (tuple<!fir.heap<!fir.array<42xi32>>, i1>, i1) -> tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| // CHECK: hlfir.assign %[[VAL_12]]#0 to %[[VAL_10]]#0 : !fir.heap<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>> | ||
| // CHECK: fir.freemem %[[VAL_12]]#0 : !fir.heap<!fir.array<42xi32>> | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: %[[VAL_22:.*]] = fir.undefined tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| // CHECK: %[[VAL_23:.*]] = fir.insert_value %[[VAL_22]], %[[VAL_13]], [1 : index] : (tuple<!fir.heap<!fir.array<42xi32>>, i1>, i1) -> tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| // CHECK: omp.barrier | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: return | ||
| // CHECK: } | ||
|
|
||
| // CHECK-LABEL: func.func private @_workshare_copy_heap_42xi32( | ||
| // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.heap<!fir.array<42xi32>>>, | ||
| // CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.heap<!fir.array<42xi32>>>) { | ||
| // CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.heap<!fir.array<42xi32>>> | ||
| // CHECK: fir.store %[[VAL_2]] to %[[VAL_1]] : !fir.ref<!fir.heap<!fir.array<42xi32>>> | ||
| // CHECK: return | ||
| // CHECK: } | ||
|
|
||
| // CHECK-LABEL: func.func private @_workshare_copy_i32( | ||
| // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32>, | ||
| // CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i32>) { | ||
| // CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32> | ||
| // CHECK: fir.store %[[VAL_2]] to %[[VAL_1]] : !fir.ref<i32> | ||
| // CHECK: return | ||
| // CHECK: } | ||
|
|
||
| // CHECK-LABEL: func.func @wsfunc( | ||
| // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<42xi32>>) { | ||
| // CHECK: %[[VAL_1:.*]] = fir.alloca i32 | ||
| // CHECK: %[[VAL_2:.*]] = fir.alloca !fir.heap<!fir.array<42xi32>> | ||
| // CHECK: omp.single copyprivate(%[[VAL_1]] -> @_workshare_copy_i32 : !fir.ref<i32>, %[[VAL_2]] -> @_workshare_copy_heap_42xi32 : !fir.ref<!fir.heap<!fir.array<42xi32>>>) { | ||
| // CHECK: %[[VAL_3:.*]] = arith.constant 1 : i32 | ||
| // CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref<i32> | ||
| // CHECK: %[[VAL_4:.*]] = arith.constant 42 : index | ||
| // CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_4]] : (index) -> !fir.shape<1> | ||
| // CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_0]](%[[VAL_5]]) {uniq_name = "array"} : (!fir.ref<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>>) | ||
| // CHECK: %[[VAL_7:.*]] = fir.allocmem !fir.array<42xi32> {bindc_name = ".tmp.array", uniq_name = ""} | ||
| // CHECK: fir.store %[[VAL_7]] to %[[VAL_2]] : !fir.ref<!fir.heap<!fir.array<42xi32>>> | ||
| // CHECK: %[[VAL_8:.*]]:2 = hlfir.declare %[[VAL_7]](%[[VAL_5]]) {uniq_name = ".tmp.array"} : (!fir.heap<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.heap<!fir.array<42xi32>>, !fir.heap<!fir.array<42xi32>>) | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: %[[VAL_9:.*]] = arith.constant 1 : i32 | ||
| // CHECK: %[[VAL_10:.*]] = arith.constant 42 : index | ||
| // CHECK: %[[VAL_11:.*]] = fir.shape %[[VAL_10]] : (index) -> !fir.shape<1> | ||
| // CHECK: %[[VAL_12:.*]]:2 = hlfir.declare %[[VAL_0]](%[[VAL_11]]) {uniq_name = "array"} : (!fir.ref<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>>) | ||
| // CHECK: %[[VAL_13:.*]] = fir.load %[[VAL_2]] : !fir.ref<!fir.heap<!fir.array<42xi32>>> | ||
| // CHECK: %[[VAL_14:.*]]:2 = hlfir.declare %[[VAL_13]](%[[VAL_11]]) {uniq_name = ".tmp.array"} : (!fir.heap<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.heap<!fir.array<42xi32>>, !fir.heap<!fir.array<42xi32>>) | ||
| // CHECK: %[[VAL_15:.*]] = arith.constant true | ||
| // CHECK: %[[VAL_16:.*]] = arith.constant 1 : index | ||
| // CHECK: omp.wsloop { | ||
| // CHECK: omp.loop_nest (%[[VAL_17:.*]]) : index = (%[[VAL_16]]) to (%[[VAL_10]]) inclusive step (%[[VAL_16]]) { | ||
| // CHECK: %[[VAL_18:.*]] = hlfir.designate %[[VAL_12]]#0 (%[[VAL_17]]) : (!fir.ref<!fir.array<42xi32>>, index) -> !fir.ref<i32> | ||
| // CHECK: %[[VAL_19:.*]] = fir.load %[[VAL_18]] : !fir.ref<i32> | ||
| // CHECK: %[[VAL_20:.*]] = fir.load %[[VAL_1]] : !fir.ref<i32> | ||
| // CHECK: %[[VAL_21:.*]] = arith.subi %[[VAL_19]], %[[VAL_20]] : i32 | ||
| // CHECK: %[[VAL_22:.*]] = arith.subi %[[VAL_21]], %[[VAL_9]] : i32 | ||
| // CHECK: %[[VAL_23:.*]] = hlfir.designate %[[VAL_14]]#0 (%[[VAL_17]]) : (!fir.heap<!fir.array<42xi32>>, index) -> !fir.ref<i32> | ||
| // CHECK: hlfir.assign %[[VAL_22]] to %[[VAL_23]] temporary_lhs : i32, !fir.ref<i32> | ||
| // CHECK: omp.yield | ||
| // CHECK: } | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: omp.single nowait { | ||
| // CHECK: %[[VAL_24:.*]] = fir.undefined tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| // CHECK: %[[VAL_25:.*]] = fir.insert_value %[[VAL_24]], %[[VAL_15]], [1 : index] : (tuple<!fir.heap<!fir.array<42xi32>>, i1>, i1) -> tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| // CHECK: "test.test1"(%[[VAL_1]]) : (!fir.ref<i32>) -> () | ||
| // CHECK: hlfir.assign %[[VAL_14]]#0 to %[[VAL_12]]#0 : !fir.heap<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>> | ||
| // CHECK: fir.freemem %[[VAL_14]]#0 : !fir.heap<!fir.array<42xi32>> | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: %[[VAL_26:.*]] = fir.undefined tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| // CHECK: %[[VAL_27:.*]] = fir.insert_value %[[VAL_26]], %[[VAL_15]], [1 : index] : (tuple<!fir.heap<!fir.array<42xi32>>, i1>, i1) -> tuple<!fir.heap<!fir.array<42xi32>>, i1> | ||
| // CHECK: omp.barrier | ||
| // CHECK: return | ||
| // CHECK: } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // RUN: fir-opt --split-input-file --lower-workshare --allow-unregistered-dialect %s | FileCheck %s | ||
|
|
||
| // Check that we correctly handle nowait | ||
|
|
||
| // CHECK-LABEL: func.func @nonowait | ||
| func.func @nonowait(%arg0: !fir.ref<!fir.array<42xi32>>) { | ||
| // CHECK: omp.barrier | ||
| omp.workshare { | ||
| omp.terminator | ||
| } | ||
| return | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // CHECK-LABEL: func.func @nowait | ||
| func.func @nowait(%arg0: !fir.ref<!fir.array<42xi32>>) { | ||
| // CHECK-NOT: omp.barrier | ||
| omp.workshare nowait { | ||
| omp.terminator | ||
| } | ||
| return | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // RUN: fir-opt --split-input-file --lower-workshare --allow-unregistered-dialect %s | FileCheck %s | ||
|
|
||
|
|
||
| // Check if we store the correct values | ||
|
|
||
| func.func @wsfunc() { | ||
| omp.parallel { | ||
| // CHECK: fir.alloca | ||
| // CHECK: fir.alloca | ||
| // CHECK: fir.alloca | ||
| // CHECK: fir.alloca | ||
| // CHECK: fir.alloca | ||
| // CHECK-NOT: fir.alloca | ||
| omp.workshare { | ||
|
|
||
| %t1 = "test.test1"() : () -> i32 | ||
| // CHECK: %[[T1:.*]] = "test.test1" | ||
| // CHECK: fir.store %[[T1]] | ||
| %t2 = "test.test2"() : () -> i32 | ||
| // CHECK: %[[T2:.*]] = "test.test2" | ||
| // CHECK: fir.store %[[T2]] | ||
| %t3 = "test.test3"() : () -> i32 | ||
| // CHECK: %[[T3:.*]] = "test.test3" | ||
| // CHECK-NOT: fir.store %[[T3]] | ||
| %t4 = "test.test4"() : () -> i32 | ||
| // CHECK: %[[T4:.*]] = "test.test4" | ||
| // CHECK: fir.store %[[T4]] | ||
| %t5 = "test.test5"() : () -> i32 | ||
| // CHECK: %[[T5:.*]] = "test.test5" | ||
| // CHECK: fir.store %[[T5]] | ||
| %t6 = "test.test6"() : () -> i32 | ||
| // CHECK: %[[T6:.*]] = "test.test6" | ||
| // CHECK-NOT: fir.store %[[T6]] | ||
|
|
||
|
|
||
| "test.test1"(%t1) : (i32) -> () | ||
| "test.test1"(%t2) : (i32) -> () | ||
| "test.test1"(%t3) : (i32) -> () | ||
|
|
||
| %true = arith.constant true | ||
| fir.if %true { | ||
| "test.test2"(%t3) : (i32) -> () | ||
| } | ||
|
|
||
| %c1_i32 = arith.constant 1 : i32 | ||
|
|
||
| %t5_pure_use = arith.addi %t5, %c1_i32 : i32 | ||
|
|
||
| %t6_mem_effect_use = "test.test8"(%t6) : (i32) -> i32 | ||
| // CHECK: %[[T6_USE:.*]] = "test.test8" | ||
| // CHECK: fir.store %[[T6_USE]] | ||
|
|
||
| %c42 = arith.constant 42 : index | ||
| %c1 = arith.constant 1 : index | ||
| omp.workshare_loop_wrapper { | ||
| omp.loop_nest (%arg1) : index = (%c1) to (%c42) inclusive step (%c1) { | ||
| "test.test10"(%t1) : (i32) -> () | ||
| "test.test10"(%t5_pure_use) : (i32) -> () | ||
| "test.test10"(%t6_mem_effect_use) : (i32) -> () | ||
| omp.yield | ||
| } | ||
| omp.terminator | ||
| } | ||
|
|
||
| "test.test10"(%t2) : (i32) -> () | ||
| fir.if %true { | ||
| "test.test10"(%t4) : (i32) -> () | ||
| } | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| return | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // RUN: fir-opt --split-input-file --lower-workshare --allow-unregistered-dialect %s | FileCheck %s | ||
|
|
||
| // Check that we cleanup unused pure operations from either the parallel or | ||
| // single regions | ||
|
|
||
| func.func @wsfunc() { | ||
| %a = fir.alloca i32 | ||
| omp.parallel { | ||
| omp.workshare { | ||
| %t1 = "test.test1"() : () -> i32 | ||
|
|
||
| %c1 = arith.constant 1 : index | ||
| %c42 = arith.constant 42 : index | ||
|
|
||
| %c2 = arith.constant 2 : index | ||
| "test.test3"(%c2) : (index) -> () | ||
|
|
||
| omp.workshare_loop_wrapper { | ||
| omp.loop_nest (%arg1) : index = (%c1) to (%c42) inclusive step (%c1) { | ||
| "test.test2"() : () -> () | ||
| omp.yield | ||
| } | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| return | ||
| } | ||
|
|
||
| // CHECK-LABEL: func.func @wsfunc() { | ||
| // CHECK: %[[VAL_0:.*]] = fir.alloca i32 | ||
| // CHECK: omp.parallel { | ||
| // CHECK: omp.single { | ||
| // CHECK: %[[VAL_1:.*]] = "test.test1"() : () -> i32 | ||
| // CHECK: %[[VAL_2:.*]] = arith.constant 2 : index | ||
| // CHECK: "test.test3"(%[[VAL_2]]) : (index) -> () | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: %[[VAL_3:.*]] = arith.constant 1 : index | ||
| // CHECK: %[[VAL_4:.*]] = arith.constant 42 : index | ||
| // CHECK: omp.wsloop nowait { | ||
| // CHECK: omp.loop_nest (%[[VAL_5:.*]]) : index = (%[[VAL_3]]) to (%[[VAL_4]]) inclusive step (%[[VAL_3]]) { | ||
| // CHECK: "test.test2"() : () -> () | ||
| // CHECK: omp.yield | ||
| // CHECK: } | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: omp.barrier | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: return | ||
| // CHECK: } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // XFAIL: * | ||
| // RUN: fir-opt --split-input-file --lower-workshare --allow-unregistered-dialect %s | FileCheck %s | ||
|
|
||
| // TODO we can lower these but we have no guarantee that the parent of | ||
| // omp.workshare supports multi-block regions, thus we fail for now. | ||
|
|
||
| func.func @wsfunc() { | ||
| %a = fir.alloca i32 | ||
| omp.parallel { | ||
| omp.workshare { | ||
| ^bb1: | ||
| %c1 = arith.constant 1 : i32 | ||
| cf.br ^bb3(%c1: i32) | ||
| ^bb3(%arg1: i32): | ||
| "test.test2"(%arg1) : (i32) -> () | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| return | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| func.func @wsfunc() { | ||
| %a = fir.alloca i32 | ||
| omp.parallel { | ||
| omp.workshare { | ||
| ^bb1: | ||
| %c1 = arith.constant 1 : i32 | ||
| cf.br ^bb3(%c1: i32) | ||
| ^bb2: | ||
| "test.test2"(%r) : (i32) -> () | ||
| omp.terminator | ||
| ^bb3(%arg1: i32): | ||
| %r = "test.test2"(%arg1) : (i32) -> i32 | ||
| cf.br ^bb2 | ||
| } | ||
| omp.terminator | ||
| } | ||
| return | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // RUN: fir-opt --split-input-file --lower-workshare --allow-unregistered-dialect %s | FileCheck %s | ||
|
|
||
| // Checks that the omp.workshare_loop_wrapper binds to the correct omp.workshare | ||
|
|
||
| func.func @wsfunc() { | ||
| %c1 = arith.constant 1 : index | ||
| %c42 = arith.constant 42 : index | ||
| omp.parallel { | ||
| omp.workshare nowait { | ||
| omp.parallel { | ||
| omp.workshare nowait { | ||
| omp.workshare_loop_wrapper { | ||
| omp.loop_nest (%arg1) : index = (%c1) to (%c42) inclusive step (%c1) { | ||
| "test.test2"() : () -> () | ||
| omp.yield | ||
| } | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| return | ||
| } | ||
|
|
||
| // CHECK-LABEL: func.func @wsfunc() { | ||
| // CHECK: %[[VAL_0:.*]] = arith.constant 1 : index | ||
| // CHECK: %[[VAL_1:.*]] = arith.constant 42 : index | ||
| // CHECK: omp.parallel { | ||
| // CHECK: omp.single nowait { | ||
| // CHECK: omp.parallel { | ||
| // CHECK: omp.wsloop nowait { | ||
| // CHECK: omp.loop_nest (%[[VAL_2:.*]]) : index = (%[[VAL_0]]) to (%[[VAL_1]]) inclusive step (%[[VAL_0]]) { | ||
| // CHECK: "test.test2"() : () -> () | ||
| // CHECK: omp.yield | ||
| // CHECK: } | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: omp.terminator | ||
| // CHECK: } | ||
| // CHECK: return | ||
| // CHECK: } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| // RUN: fir-opt --bufferize-hlfir %s | FileCheck %s | ||
|
|
||
| // Checks that we correctly identify when to use the lowering to | ||
| // omp.workshare_loop_wrapper | ||
|
|
||
| // CHECK-LABEL: @should_parallelize_0 | ||
| // CHECK: omp.workshare_loop_wrapper | ||
| func.func @should_parallelize_0(%arg: !fir.ref<!fir.array<42xi32>>, %idx : index) { | ||
| omp.workshare { | ||
| %c42 = arith.constant 42 : index | ||
| %c1_i32 = arith.constant 1 : i32 | ||
| %shape = fir.shape %c42 : (index) -> !fir.shape<1> | ||
| %array:2 = hlfir.declare %arg(%shape) {uniq_name = "array"} : (!fir.ref<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>>) | ||
| %elemental = hlfir.elemental %shape unordered : (!fir.shape<1>) -> !hlfir.expr<42xi32> { | ||
| ^bb0(%i: index): | ||
| hlfir.yield_element %c1_i32 : i32 | ||
| } | ||
| hlfir.assign %elemental to %array#0 : !hlfir.expr<42xi32>, !fir.ref<!fir.array<42xi32>> | ||
| hlfir.destroy %elemental : !hlfir.expr<42xi32> | ||
| omp.terminator | ||
| } | ||
| return | ||
| } | ||
|
|
||
| // CHECK-LABEL: @should_parallelize_1 | ||
| // CHECK: omp.workshare_loop_wrapper | ||
| func.func @should_parallelize_1(%arg: !fir.ref<!fir.array<42xi32>>, %idx : index) { | ||
| omp.parallel { | ||
| omp.workshare { | ||
| %c42 = arith.constant 42 : index | ||
| %c1_i32 = arith.constant 1 : i32 | ||
| %shape = fir.shape %c42 : (index) -> !fir.shape<1> | ||
| %array:2 = hlfir.declare %arg(%shape) {uniq_name = "array"} : (!fir.ref<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>>) | ||
| %elemental = hlfir.elemental %shape unordered : (!fir.shape<1>) -> !hlfir.expr<42xi32> { | ||
| ^bb0(%i: index): | ||
| hlfir.yield_element %c1_i32 : i32 | ||
| } | ||
| hlfir.assign %elemental to %array#0 : !hlfir.expr<42xi32>, !fir.ref<!fir.array<42xi32>> | ||
| hlfir.destroy %elemental : !hlfir.expr<42xi32> | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| return | ||
| } | ||
|
|
||
|
|
||
| // CHECK-LABEL: @should_not_parallelize_0 | ||
| // CHECK-NOT: omp.workshare_loop_wrapper | ||
| func.func @should_not_parallelize_0(%arg: !fir.ref<!fir.array<42xi32>>, %idx : index) { | ||
| omp.workshare { | ||
| omp.single { | ||
| %c42 = arith.constant 42 : index | ||
| %c1_i32 = arith.constant 1 : i32 | ||
| %shape = fir.shape %c42 : (index) -> !fir.shape<1> | ||
| %array:2 = hlfir.declare %arg(%shape) {uniq_name = "array"} : (!fir.ref<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>>) | ||
| %elemental = hlfir.elemental %shape unordered : (!fir.shape<1>) -> !hlfir.expr<42xi32> { | ||
| ^bb0(%i: index): | ||
| hlfir.yield_element %c1_i32 : i32 | ||
| } | ||
| hlfir.assign %elemental to %array#0 : !hlfir.expr<42xi32>, !fir.ref<!fir.array<42xi32>> | ||
| hlfir.destroy %elemental : !hlfir.expr<42xi32> | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| return | ||
| } | ||
|
|
||
| // CHECK-LABEL: @should_not_parallelize_1 | ||
| // CHECK-NOT: omp.workshare_loop_wrapper | ||
| func.func @should_not_parallelize_1(%arg: !fir.ref<!fir.array<42xi32>>, %idx : index) { | ||
| omp.workshare { | ||
| omp.critical { | ||
| %c42 = arith.constant 42 : index | ||
| %c1_i32 = arith.constant 1 : i32 | ||
| %shape = fir.shape %c42 : (index) -> !fir.shape<1> | ||
| %array:2 = hlfir.declare %arg(%shape) {uniq_name = "array"} : (!fir.ref<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>>) | ||
| %elemental = hlfir.elemental %shape unordered : (!fir.shape<1>) -> !hlfir.expr<42xi32> { | ||
| ^bb0(%i: index): | ||
| hlfir.yield_element %c1_i32 : i32 | ||
| } | ||
| hlfir.assign %elemental to %array#0 : !hlfir.expr<42xi32>, !fir.ref<!fir.array<42xi32>> | ||
| hlfir.destroy %elemental : !hlfir.expr<42xi32> | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| return | ||
| } | ||
|
|
||
| // CHECK-LABEL: @should_not_parallelize_2 | ||
| // CHECK-NOT: omp.workshare_loop_wrapper | ||
| func.func @should_not_parallelize_2(%arg: !fir.ref<!fir.array<42xi32>>, %idx : index) { | ||
| omp.workshare { | ||
| omp.parallel { | ||
| %c42 = arith.constant 42 : index | ||
| %c1_i32 = arith.constant 1 : i32 | ||
| %shape = fir.shape %c42 : (index) -> !fir.shape<1> | ||
| %array:2 = hlfir.declare %arg(%shape) {uniq_name = "array"} : (!fir.ref<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>>) | ||
| %elemental = hlfir.elemental %shape unordered : (!fir.shape<1>) -> !hlfir.expr<42xi32> { | ||
| ^bb0(%i: index): | ||
| hlfir.yield_element %c1_i32 : i32 | ||
| } | ||
| hlfir.assign %elemental to %array#0 : !hlfir.expr<42xi32>, !fir.ref<!fir.array<42xi32>> | ||
| hlfir.destroy %elemental : !hlfir.expr<42xi32> | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| return | ||
| } | ||
|
|
||
| // CHECK-LABEL: @should_not_parallelize_3 | ||
| // CHECK-NOT: omp.workshare_loop_wrapper | ||
| func.func @should_not_parallelize_3(%arg: !fir.ref<!fir.array<42xi32>>, %idx : index) { | ||
| omp.workshare { | ||
| omp.parallel { | ||
| omp.workshare { | ||
| omp.parallel { | ||
| %c42 = arith.constant 42 : index | ||
| %c1_i32 = arith.constant 1 : i32 | ||
| %shape = fir.shape %c42 : (index) -> !fir.shape<1> | ||
| %array:2 = hlfir.declare %arg(%shape) {uniq_name = "array"} : (!fir.ref<!fir.array<42xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<42xi32>>, !fir.ref<!fir.array<42xi32>>) | ||
| %elemental = hlfir.elemental %shape unordered : (!fir.shape<1>) -> !hlfir.expr<42xi32> { | ||
| ^bb0(%i: index): | ||
| hlfir.yield_element %c1_i32 : i32 | ||
| } | ||
| hlfir.assign %elemental to %array#0 : !hlfir.expr<42xi32>, !fir.ref<!fir.array<42xi32>> | ||
| hlfir.destroy %elemental : !hlfir.expr<42xi32> | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| omp.terminator | ||
| } | ||
| return | ||
| } |