// Test hlfir.designate operation parse, verify (no errors), and unparse. // RUN: fir-opt %s | fir-opt | FileCheck %s // array(1) func.func @array_ref(%arg0 : !fir.ref>) { %c1 = arith.constant 1 : index %0 = hlfir.designate %arg0 (%c1) : (!fir.ref>, index) -> !fir.ref return } // CHECK-LABEL: func.func @array_ref( // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref>) { // CHECK: %[[VAL_1:.*]] = arith.constant 1 : index // CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_0]] (%[[VAL_1]]) : (!fir.ref>, index) -> !fir.ref // array(1, 2:3:4, 5) func.func @array_section(%arg0 : !fir.box>) { %c1 = arith.constant 1 : index %c2 = arith.constant 2 : index %c3 = arith.constant 3 : index %c4 = arith.constant 4 : index %c5 = arith.constant 5 : index %shape = fir.undefined !fir.shape<1> %0 = hlfir.designate %arg0 (%c1, %c2:%c3:%c4, %c5) shape %shape: (!fir.box>, index, index, index, index, index, !fir.shape<1>) -> !fir.box> return } // CHECK-LABEL: func.func @array_section( // CHECK-SAME: %[[VAL_0:.*]]: !fir.box>) { // CHECK: %[[VAL_1:.*]] = arith.constant 1 : index // CHECK: %[[VAL_2:.*]] = arith.constant 2 : index // CHECK: %[[VAL_3:.*]] = arith.constant 3 : index // CHECK: %[[VAL_4:.*]] = arith.constant 4 : index // CHECK: %[[VAL_5:.*]] = arith.constant 5 : index // CHECK: %[[VAL_6:.*]] = fir.undefined !fir.shape<1> // CHECK: %[[VAL_7:.*]] = hlfir.designate %[[VAL_0]] (%[[VAL_1]], %[[VAL_2]]:%[[VAL_3]]:%[[VAL_4]], %[[VAL_5]]) shape %[[VAL_6]] : (!fir.box>, index, index, index, index, index, !fir.shape<1>) -> !fir.box> // array%comp func.func @component_ref(%arg0 : !fir.box>>) { %shape = fir.undefined !fir.shape<1> %0 = hlfir.designate %arg0 {"i"} shape %shape: (!fir.box>>, !fir.shape<1>) -> !fir.box> return } // CHECK-LABEL: func.func @component_ref( // CHECK-SAME: %[[VAL_0:.*]]: !fir.box>>) { // CHECK: %[[VAL_1:.*]] = fir.undefined !fir.shape<1> // CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_0]]{"i"} shape %[[VAL_1]] : (!fir.box>>, !fir.shape<1>) -> !fir.box> // array%array_comp(1) func.func @component_array_ref(%arg0 : !fir.box}>>>) { %c1 = arith.constant 1 : index %component_shape = fir.undefined !fir.shapeshift<1> %result_shape = fir.undefined !fir.shape<1> %0 = hlfir.designate %arg0 {"array_comp"}<%component_shape>(%c1) shape %result_shape : (!fir.box}>>>, !fir.shapeshift<1>, index, !fir.shape<1>) -> !fir.box> return } // CHECK-LABEL: func.func @component_array_ref( // CHECK-SAME: %[[VAL_0:.*]]: !fir.box}>>>) { // CHECK: %[[VAL_1:.*]] = arith.constant 1 : index // CHECK: %[[VAL_2:.*]] = fir.undefined !fir.shapeshift<1> // CHECK: %[[VAL_3:.*]] = fir.undefined !fir.shape<1> // CHECK: %[[VAL_4:.*]] = hlfir.designate %[[VAL_0]]{"array_comp"} <%[[VAL_2]]> (%[[VAL_1]]) shape %[[VAL_3]] : (!fir.box}>>>, !fir.shapeshift<1>, index, !fir.shape<1>) -> !fir.box> // char(3:4) func.func @substring(%arg0 : !fir.boxchar<1>) { %c2 = arith.constant 2 : index %c3 = arith.constant 3 : index %c4 = arith.constant 4 : index %0 = hlfir.designate %arg0 substr %c3, %c4 typeparams %c2: (!fir.boxchar<1>, index, index, index) -> !fir.boxchar<1> return } // CHECK-LABEL: func.func @substring( // CHECK-SAME: %[[VAL_0:.*]]: !fir.boxchar<1>) { // CHECK: %[[VAL_1:.*]] = arith.constant 2 : index // CHECK: %[[VAL_2:.*]] = arith.constant 3 : index // CHECK: %[[VAL_3:.*]] = arith.constant 4 : index // CHECK: %[[VAL_4:.*]] = hlfir.designate %[[VAL_0]] substr %[[VAL_2]], %[[VAL_3]] typeparams %[[VAL_1]] : (!fir.boxchar<1>, index, index, index) -> !fir.boxchar<1> // char_array(3:4) func.func @array_substring(%arg0 : !fir.box>>) { %c2 = arith.constant 2 : index %c3 = arith.constant 3 : index %c4 = arith.constant 4 : index %shape = fir.undefined !fir.shape<1> %0 = hlfir.designate %arg0 substr %c3, %c4 shape %shape typeparams %c2 : (!fir.box>>, index, index, !fir.shape<1>, index) -> !fir.box>> return } // CHECK-LABEL: func.func @array_substring( // CHECK-SAME: %[[VAL_0:.*]]: !fir.box>>) { // CHECK: %[[VAL_1:.*]] = arith.constant 2 : index // CHECK: %[[VAL_2:.*]] = arith.constant 3 : index // CHECK: %[[VAL_3:.*]] = arith.constant 4 : index // CHECK: %[[VAL_4:.*]] = fir.undefined !fir.shape<1> // CHECK: %[[VAL_5:.*]] = hlfir.designate %[[VAL_0]] substr %[[VAL_2]], %[[VAL_3]] shape %[[VAL_4]] typeparams %[[VAL_1]] : (!fir.box>>, index, index, !fir.shape<1>, index) -> !fir.box>> func.func @real_part(%arg0 : !fir.ref>) { %0 = hlfir.designate %arg0 real : (!fir.ref>) -> !fir.ref> return } // CHECK-LABEL: func.func @real_part( // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref>) { // CHECK: %[[VAL_1:.*]] = hlfir.designate %[[VAL_0]] real : (!fir.ref>) -> !fir.ref> func.func @imag_part_mlir_complex(%arg0 : !fir.ref>) { %0 = hlfir.designate %arg0 imag : (!fir.ref>) -> !fir.ref return } // CHECK-LABEL: func.func @imag_part_mlir_complex( // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref>) { // CHECK: %[[VAL_1:.*]] = hlfir.designate %[[VAL_0]] imag : (!fir.ref>) -> !fir.ref // array%array_complex_comp(1)%im func.func @component_array_ref_cplx_part(%arg0 : !fir.box>}>>>) { %c1 = arith.constant 1 : index %component_shape = fir.undefined !fir.shapeshift<1> %result_shape = fir.undefined !fir.shape<1> %0 = hlfir.designate %arg0 {"array_comp"}<%component_shape>(%c1) imag shape %result_shape : (!fir.box>}>>>, !fir.shapeshift<1>, index, !fir.shape<1>) -> !fir.box>> return } // CHECK-LABEL: func.func @component_array_ref_cplx_part( // CHECK-SAME: %[[VAL_0:.*]]: !fir.box>}>>>) { // CHECK: %[[VAL_1:.*]] = arith.constant 1 : index // CHECK: %[[VAL_2:.*]] = fir.undefined !fir.shapeshift<1> // CHECK: %[[VAL_3:.*]] = fir.undefined !fir.shape<1> // CHECK: %[[VAL_4:.*]] = hlfir.designate %[[VAL_0]]{"array_comp"} <%[[VAL_2]]> (%[[VAL_1]]) imag shape %[[VAL_3]] : (!fir.box>}>>>, !fir.shapeshift<1>, index, !fir.shape<1>) -> !fir.box>> // pdt_array(1) func.func @pdt(%arg0 : !fir.box>>) { %c1 = arith.constant 1 : index %0 = hlfir.designate %arg0(%c1) typeparams %c1 : (!fir.box>>, index, index) -> !fir.box> return } // CHECK-LABEL: func.func @pdt( // CHECK-SAME: %[[VAL_0:.*]]: !fir.box>>) { // CHECK: %[[VAL_1:.*]] = arith.constant 1 : index // CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_0]] (%[[VAL_1]]) typeparams %[[VAL_1]] : (!fir.box>>, index, index) -> !fir.box>