mirror of
https://github.com/intel/llvm.git
synced 2026-01-14 11:57:39 +08:00
[flang][hlfir] Use complete form of DesignateOp for im/re array designators.
With this change, the lowering provides full slice triples for designators like ...%array_comp%im/re, so that the codegen does not have to figure it out for the array_comp. Basically, ...%array_comp%im/re is lowered the same way as ...%array_comp(:,:,...)%im/re. Reviewed By: jeanPerier Differential Revision: https://reviews.llvm.org/D150842
This commit is contained in:
@@ -650,6 +650,31 @@ private:
|
||||
"Fortran designators can only have one ranked part");
|
||||
return changeElementType(baseType, componentBaseType);
|
||||
}
|
||||
|
||||
if (partInfo.complexPart && partInfo.componentShape) {
|
||||
// Treat ...array_comp%im/re as ...array_comp(:,:,...)%im/re
|
||||
// so that the codegen has the full slice triples for the component
|
||||
// readily available.
|
||||
fir::FirOpBuilder &builder = getBuilder();
|
||||
mlir::Type idxTy = builder.getIndexType();
|
||||
mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1);
|
||||
|
||||
llvm::SmallVector<mlir::Value> resultExtents;
|
||||
// Collect <lb, ub> pairs from the component shape.
|
||||
auto bounds = hlfir::genBounds(loc, builder, partInfo.componentShape);
|
||||
for (auto &boundPair : bounds) {
|
||||
// The default subscripts are <lb, ub, 1>:
|
||||
partInfo.subscripts.emplace_back(hlfir::DesignateOp::Triplet{
|
||||
boundPair.first, boundPair.second, one});
|
||||
auto extentValue = builder.genExtentFromTriplet(
|
||||
loc, boundPair.first, boundPair.second, one, idxTy);
|
||||
resultExtents.push_back(extentValue);
|
||||
}
|
||||
// The result shape is: <max((ub - lb + 1) / 1, 0), ...>.
|
||||
partInfo.resultShape = builder.genShape(loc, resultExtents);
|
||||
return componentBaseType;
|
||||
}
|
||||
|
||||
// scalar%array_comp or scalar%scalar. In any case the shape of this
|
||||
// part-ref is coming from the component.
|
||||
partInfo.resultShape = partInfo.componentShape;
|
||||
|
||||
@@ -30,6 +30,10 @@ type t_array_char
|
||||
integer :: scalar_i
|
||||
character(5) :: array_char_comp(10,20)
|
||||
end type
|
||||
|
||||
type t_complex
|
||||
complex :: array_comp(2:11,3:22)
|
||||
end type
|
||||
end module
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
@@ -330,3 +334,36 @@ subroutine test_array_ref_chain(a)
|
||||
! CHECK: %[[VAL_19:.*]] = arith.constant 5 : index
|
||||
! CHECK: %[[VAL_20:.*]] = hlfir.designate %[[VAL_14]]{"array_comp"} <%[[VAL_17]]> (%[[VAL_18]], %[[VAL_19]]) shape %[[VAL_13]] : (!fir.box<!fir.array<10x!fir.type<_QMcomp_refTt_array{scalar_i:i32,array_comp:!fir.array<10x20xf32>}>>>, !fir.shape<2>, index, index, !fir.shape<1>) -> !fir.box<!fir.array<10xf32>>
|
||||
end subroutine
|
||||
|
||||
subroutine test_scalar_array_complex_chain(a)
|
||||
use comp_ref
|
||||
type(t_complex) :: a
|
||||
print *, a%array_comp%im
|
||||
! CHECK-LABEL: func.func @_QPtest_scalar_array_complex_chain(
|
||||
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest_scalar_array_complex_chainEa"} : (!fir.ref<!fir.type<_QMcomp_refTt_complex{array_comp:!fir.array<10x20x!fir.complex<4>>}>>) -> (!fir.ref<!fir.type<_QMcomp_refTt_complex{array_comp:!fir.array<10x20x!fir.complex<4>>}>>, !fir.ref<!fir.type<_QMcomp_refTt_complex{array_comp:!fir.array<10x20x!fir.complex<4>>}>>)
|
||||
! CHECK: %[[VAL_7:.*]] = arith.constant 10 : index
|
||||
! CHECK: %[[VAL_8:.*]] = arith.constant 20 : index
|
||||
! CHECK: %[[VAL_9:.*]] = arith.constant 2 : index
|
||||
! CHECK: %[[VAL_10:.*]] = arith.constant 3 : index
|
||||
! CHECK: %[[VAL_11:.*]] = fir.shape_shift %[[VAL_9]], %[[VAL_7]], %[[VAL_10]], %[[VAL_8]] : (index, index, index, index) -> !fir.shapeshift<2>
|
||||
! CHECK: %[[VAL_12:.*]] = arith.constant 1 : index
|
||||
! CHECK: %[[VAL_13:.*]] = arith.constant 1 : index
|
||||
! CHECK: %[[VAL_14:.*]] = arith.addi %[[VAL_9]], %[[VAL_7]] : index
|
||||
! CHECK: %[[VAL_15:.*]] = arith.subi %[[VAL_14]], %[[VAL_13]] : index
|
||||
! CHECK: %[[VAL_16:.*]] = arith.addi %[[VAL_10]], %[[VAL_8]] : index
|
||||
! CHECK: %[[VAL_17:.*]] = arith.subi %[[VAL_16]], %[[VAL_13]] : index
|
||||
! CHECK: %[[VAL_18:.*]] = arith.constant 0 : index
|
||||
! CHECK: %[[VAL_19:.*]] = arith.subi %[[VAL_15]], %[[VAL_9]] : index
|
||||
! CHECK: %[[VAL_20:.*]] = arith.addi %[[VAL_19]], %[[VAL_12]] : index
|
||||
! CHECK: %[[VAL_21:.*]] = arith.divsi %[[VAL_20]], %[[VAL_12]] : index
|
||||
! CHECK: %[[VAL_22:.*]] = arith.cmpi sgt, %[[VAL_21]], %[[VAL_18]] : index
|
||||
! CHECK: %[[VAL_23:.*]] = arith.select %[[VAL_22]], %[[VAL_21]], %[[VAL_18]] : index
|
||||
! CHECK: %[[VAL_24:.*]] = arith.constant 0 : index
|
||||
! CHECK: %[[VAL_25:.*]] = arith.subi %[[VAL_17]], %[[VAL_10]] : index
|
||||
! CHECK: %[[VAL_26:.*]] = arith.addi %[[VAL_25]], %[[VAL_12]] : index
|
||||
! CHECK: %[[VAL_27:.*]] = arith.divsi %[[VAL_26]], %[[VAL_12]] : index
|
||||
! CHECK: %[[VAL_28:.*]] = arith.cmpi sgt, %[[VAL_27]], %[[VAL_24]] : index
|
||||
! CHECK: %[[VAL_29:.*]] = arith.select %[[VAL_28]], %[[VAL_27]], %[[VAL_24]] : index
|
||||
! CHECK: %[[VAL_30:.*]] = fir.shape %[[VAL_23]], %[[VAL_29]] : (index, index) -> !fir.shape<2>
|
||||
! CHECK: %[[VAL_31:.*]] = hlfir.designate %[[VAL_1]]#0{"array_comp"} <%[[VAL_11]]> (%[[VAL_9]]:%[[VAL_15]]:%[[VAL_12]], %[[VAL_10]]:%[[VAL_17]]:%[[VAL_12]]) imag shape %[[VAL_30]] : (!fir.ref<!fir.type<_QMcomp_refTt_complex{array_comp:!fir.array<10x20x!fir.complex<4>>}>>, !fir.shapeshift<2>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.box<!fir.array<10x20xf32>>
|
||||
end subroutine
|
||||
|
||||
Reference in New Issue
Block a user