|
| 1 | +!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s --check-prefixes HOST |
| 2 | + |
| 3 | + |
| 4 | +!HOST-LABEL: func.func @_QPread_write_section() { |
| 5 | +!HOST: %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFread_write_sectionEi"} |
| 6 | +!HOST: %[[READ:.*]] = fir.address_of(@_QFread_write_sectionEsp_read) : !fir.ref<!fir.array<10xi32>> |
| 7 | +!HOST: %[[C10:.*]] = arith.constant 10 : index |
| 8 | +!HOST: %[[READ_SHAPE:.*]] = fir.shape %[[C10]] : (index) -> !fir.shape<1> |
| 9 | +!HOST: %[[READ_DECL:.*]]:2 = hlfir.declare %[[READ]](%[[READ_SHAPE]]) {uniq_name = "_QFread_write_sectionEsp_read"} : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<10xi32>>, !fir.ref<!fir.array<10xi32>>) |
| 10 | +!HOST: %[[WRITE:.*]] = fir.address_of(@_QFread_write_sectionEsp_write) : !fir.ref<!fir.array<10xi32>> |
| 11 | +!HOST: %[[C10:.*]] = arith.constant 10 : index |
| 12 | +!HOST: %[[WRITE_SHAPE:.*]] = fir.shape %[[C10]] : (index) -> !fir.shape<1> |
| 13 | +!HOST: %[[WRITE_DECL:.*]]:2 = hlfir.declare %[[WRITE]](%[[WRITE_SHAPE]]) {uniq_name = "_QFread_write_sectionEsp_write"} : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<10xi32>>, !fir.ref<!fir.array<10xi32>>) |
| 14 | + |
| 15 | +!HOST: %[[C1:.*]] = arith.constant 1 : index |
| 16 | +!HOST: %[[C2:.*]] = arith.constant 1 : index |
| 17 | +!HOST: %[[C3:.*]] = arith.constant 4 : index |
| 18 | +!HOST: %[[BOUNDS0:.*]] = omp.bounds lower_bound(%[[C2]] : index) upper_bound(%[[C3]] : index) stride(%[[C1]] : index) start_idx(%[[C1]] : index) |
| 19 | +!HOST: %[[MAP0:.*]] = omp.map_info var_ptr(%[[READ_DECL]]#1 : !fir.ref<!fir.array<10xi32>>) map_clauses(tofrom) capture(ByRef) bounds(%[[BOUNDS0]]) -> !fir.ref<!fir.array<10xi32>> {name = "sp_read(2:5)"} |
| 20 | +!HOST: %[[C4:.*]] = arith.constant 1 : index |
| 21 | +!HOST: %[[C5:.*]] = arith.constant 1 : index |
| 22 | +!HOST: %[[C6:.*]] = arith.constant 4 : index |
| 23 | +!HOST: %[[BOUNDS1:.*]] = omp.bounds lower_bound(%[[C5]] : index) upper_bound(%[[C6]] : index) stride(%[[C4]] : index) start_idx(%[[C4]] : index) |
| 24 | +!HOST: %[[MAP1:.*]] = omp.map_info var_ptr(%[[WRITE_DECL]]#1 : !fir.ref<!fir.array<10xi32>>) map_clauses(tofrom) capture(ByRef) bounds(%[[BOUNDS1]]) -> !fir.ref<!fir.array<10xi32>> {name = "sp_write(2:5)"} |
| 25 | +!HOST: omp.target map_entries(%[[MAP0]], %[[MAP1]] : !fir.ref<!fir.array<10xi32>>, !fir.ref<!fir.array<10xi32>>) { |
| 26 | + |
| 27 | +subroutine read_write_section() |
| 28 | + integer :: sp_read(10) = (/1,2,3,4,5,6,7,8,9,10/) |
| 29 | + integer :: sp_write(10) = (/0,0,0,0,0,0,0,0,0,0/) |
| 30 | + |
| 31 | +!$omp target map(tofrom:sp_read(2:5)) map(tofrom:sp_write(2:5)) |
| 32 | + do i = 2, 5 |
| 33 | + sp_write(i) = sp_read(i) |
| 34 | + end do |
| 35 | +!$omp end target |
| 36 | +end subroutine read_write_section |
| 37 | + |
| 38 | + |
| 39 | +module assumed_array_routines |
| 40 | + contains |
| 41 | + |
| 42 | +!HOST-LABEL: func.func @_QMassumed_array_routinesPassumed_shape_array( |
| 43 | +!HOST-SAME: %[[ARG0:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "arr_read_write"}) { |
| 44 | +!HOST: %[[ARG0_DECL:.*]]:2 = hlfir.declare %[[ARG0]] {fortran_attrs = #fir.var_attrs<intent_inout>, uniq_name = "_QMassumed_array_routinesFassumed_shape_arrayEarr_read_write"} : (!fir.box<!fir.array<?xi32>>) -> (!fir.box<!fir.array<?xi32>>, !fir.box<!fir.array<?xi32>>) |
| 45 | +!HOST: %[[C0:.*]] = arith.constant 1 : index |
| 46 | +!HOST: %[[C1:.*]] = arith.constant 0 : index |
| 47 | +!HOST: %[[C2:.*]]:3 = fir.box_dims %[[ARG0_DECL]]#1, %[[C1]] : (!fir.box<!fir.array<?xi32>>, index) -> (index, index, index) |
| 48 | +!HOST: %[[C3:.*]] = arith.constant 1 : index |
| 49 | +!HOST: %[[C4:.*]] = arith.constant 4 : index |
| 50 | +!HOST: %[[BOUNDS:.*]] = omp.bounds lower_bound(%[[C3]] : index) upper_bound(%[[C4]] : index) stride(%[[C2]]#2 : index) start_idx(%[[C0]] : index) {stride_in_bytes = true} |
| 51 | +!HOST: %[[ADDROF:.*]] = fir.box_addr %[[ARG0_DECL]]#1 : (!fir.box<!fir.array<?xi32>>) -> !fir.ref<!fir.array<?xi32>> |
| 52 | +!HOST: %[[MAP:.*]] = omp.map_info var_ptr(%[[ADDROF]] : !fir.ref<!fir.array<?xi32>>) map_clauses(tofrom) capture(ByRef) bounds(%[[BOUNDS]]) -> !fir.ref<!fir.array<?xi32>> {name = "arr_read_write(2:5)"} |
| 53 | +!HOST: omp.target map_entries(%[[MAP]] : !fir.ref<!fir.array<?xi32>>) { |
| 54 | + subroutine assumed_shape_array(arr_read_write) |
| 55 | + integer, intent(inout) :: arr_read_write(:) |
| 56 | + |
| 57 | + !$omp target map(tofrom:arr_read_write(2:5)) |
| 58 | + do i = 2, 5 |
| 59 | + arr_read_write(i) = i |
| 60 | + end do |
| 61 | + !$omp end target |
| 62 | + end subroutine assumed_shape_array |
| 63 | + |
| 64 | + |
| 65 | +!HOST-LABEL: func.func @_QMassumed_array_routinesPassumed_size_array( |
| 66 | +!HOST-SAME: %[[ARG0:.*]]: !fir.ref<!fir.array<?xi32>> {fir.bindc_name = "arr_read_write"}) { |
| 67 | +!HOST: %[[UNDEF:.*]] = fir.undefined index |
| 68 | +!HOST: %[[ARG0_SHAPE:.*]] = fir.shape %[[UNDEF]] : (index) -> !fir.shape<1> |
| 69 | +!HOST: %[[ARG0_DECL:.*]]:2 = hlfir.declare %[[ARG0]](%[[ARG0_SHAPE]]) {fortran_attrs = #fir.var_attrs<intent_inout>, uniq_name = "_QMassumed_array_routinesFassumed_size_arrayEarr_read_write"} : (!fir.ref<!fir.array<?xi32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.ref<!fir.array<?xi32>>) |
| 70 | +!HOST: %[[ALLOCA:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QMassumed_array_routinesFassumed_size_arrayEi"} |
| 71 | +!HOST: %[[C0:.*]] = arith.constant 1 : index |
| 72 | +!HOST: %[[C1:.*]] = arith.constant 1 : index |
| 73 | +!HOST: %[[C2:.*]] = arith.constant 4 : index |
| 74 | +!HOST: %[[BOUNDS:.*]] = omp.bounds lower_bound(%[[C1]] : index) upper_bound(%[[C2]] : index) stride(%[[C0]] : index) start_idx(%[[C0]] : index) |
| 75 | +!HOST: %[[MAP:.*]] = omp.map_info var_ptr(%[[ARG0_DECL]]#1 : !fir.ref<!fir.array<?xi32>>) map_clauses(tofrom) capture(ByRef) bounds(%[[BOUNDS]]) -> !fir.ref<!fir.array<?xi32>> {name = "arr_read_write(2:5)"} |
| 76 | +!HOST: omp.target map_entries(%[[MAP]] : !fir.ref<!fir.array<?xi32>>) { |
| 77 | + subroutine assumed_size_array(arr_read_write) |
| 78 | + integer, intent(inout) :: arr_read_write(*) |
| 79 | + |
| 80 | + !$omp target map(tofrom:arr_read_write(2:5)) |
| 81 | + do i = 2, 5 |
| 82 | + arr_read_write(i) = i |
| 83 | + end do |
| 84 | + !$omp end target |
| 85 | + end subroutine assumed_size_array |
| 86 | + end module assumed_array_routines |
| 87 | + |
| 88 | + |
| 89 | +!HOST-LABEL:func.func @_QPcall_assumed_shape_and_size_array() { |
| 90 | +!HOST: %[[C20:.*]] = arith.constant 20 : index |
| 91 | +!HOST: %[[READ_WRITE:.*]] = fir.alloca !fir.array<20xi32> {bindc_name = "arr_read_write", uniq_name = "_QFcall_assumed_shape_and_size_arrayEarr_read_write"} |
| 92 | +!HOST: %[[SHAPE_READ_WRITE:.*]] = fir.shape %[[C20]] : (index) -> !fir.shape<1> |
| 93 | +!HOST: %[[READ_WRITE_DECL:.*]]:2 = hlfir.declare %[[READ_WRITE]](%[[SHAPE_READ_WRITE]]) {uniq_name = "_QFcall_assumed_shape_and_size_arrayEarr_read_write"} : (!fir.ref<!fir.array<20xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<20xi32>>, !fir.ref<!fir.array<20xi32>>) |
| 94 | +!HOST: %[[LB:.*]] = arith.constant 1 : index |
| 95 | +!HOST: %[[UB:.*]] = arith.constant 10 : index |
| 96 | +!HOST: %[[STEP:.*]] = arith.constant 1 : index |
| 97 | +!HOST: %[[SHAPE_VAL10:.*]] = arith.constant 10 : index |
| 98 | +!HOST: %[[SHAPE:.*]] = fir.shape %[[SHAPE_VAL10]] : (index) -> !fir.shape<1> |
| 99 | +!HOST: %[[READ_WRITE_DESIGNATE:.*]] = hlfir.designate %[[READ_WRITE_DECL]]#0 (%[[LB]]:%[[UB]]:%[[STEP]]) shape %[[SHAPE]] : (!fir.ref<!fir.array<20xi32>>, index, index, index, !fir.shape<1>) -> !fir.ref<!fir.array<10xi32>> |
| 100 | +!HOST: %[[READ_WRITE_EMBOX:.*]] = fir.embox %[[READ_WRITE_DESIGNATE]](%[[SHAPE]]) : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.box<!fir.array<10xi32>> |
| 101 | +!HOST: %[[ARG0:.*]] = fir.convert %[[READ_WRITE_EMBOX]] : (!fir.box<!fir.array<10xi32>>) -> !fir.box<!fir.array<?xi32>> |
| 102 | +!HOST: fir.call @_QMassumed_array_routinesPassumed_shape_array(%[[ARG0]]) fastmath<contract> : (!fir.box<!fir.array<?xi32>>) -> () |
| 103 | +!HOST: %[[LB:.*]] = arith.constant 10 : index |
| 104 | +!HOST: %[[UB:.*]] = arith.constant 20 : index |
| 105 | +!HOST: %[[STEP:.*]] = arith.constant 1 : index |
| 106 | +!HOST: %[[SHAPE_VAL11:.*]] = arith.constant 11 : index |
| 107 | +!HOST: %[[SHAPE:.*]] = fir.shape %[[SHAPE_VAL11]] : (index) -> !fir.shape<1> |
| 108 | +!HOST: %[[READ_WRITE_EMBOX:.*]] = hlfir.designate %[[READ_WRITE_DECL]]#0 (%[[LB]]:%[[UB]]:%[[STEP]]) shape %[[SHAPE]] : (!fir.ref<!fir.array<20xi32>>, index, index, index, !fir.shape<1>) -> !fir.ref<!fir.array<11xi32>> |
| 109 | +!HOST: %[[ARG1:.*]] = fir.convert %[[READ_WRITE_EMBOX]] : (!fir.ref<!fir.array<11xi32>>) -> !fir.ref<!fir.array<?xi32>> |
| 110 | +!HOST: fir.call @_QMassumed_array_routinesPassumed_size_array(%[[ARG1]]) fastmath<contract> : (!fir.ref<!fir.array<?xi32>>) -> () |
| 111 | +!HOST: return |
| 112 | +!HOST:} |
| 113 | + |
| 114 | +subroutine call_assumed_shape_and_size_array |
| 115 | + use assumed_array_routines |
| 116 | + integer :: arr_read_write(20) |
| 117 | + call assumed_shape_array(arr_read_write(1:10)) |
| 118 | + call assumed_size_array(arr_read_write(10:20)) |
| 119 | +end subroutine call_assumed_shape_and_size_array |
0 commit comments