diff --git a/flang/include/flang/Optimizer/Builder/Runtime/Allocatable.h b/flang/include/flang/Optimizer/Builder/Runtime/Allocatable.h --- a/flang/include/flang/Optimizer/Builder/Runtime/Allocatable.h +++ b/flang/include/flang/Optimizer/Builder/Runtime/Allocatable.h @@ -9,8 +9,9 @@ #ifndef FORTRAN_OPTIMIZER_BUILDER_RUNTIME_ALLOCATABLE_H #define FORTRAN_OPTIMIZER_BUILDER_RUNTIME_ALLOCATABLE_H +#include "mlir/IR/Value.h" + namespace mlir { -class Value; class Location; } // namespace mlir @@ -37,5 +38,18 @@ void genAllocatableApplyMold(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value desc, mlir::Value mold, int rank); +/// Generate runtime call to set the bounds (\p lowerBound and \p upperBound) +/// for the specified dimension \p dimIndex (zero-based) in the given +/// \p desc descriptor. +void genAllocatableSetBounds(fir::FirOpBuilder &builder, mlir::Location loc, + mlir::Value desc, mlir::Value dimIndex, + mlir::Value lowerBound, mlir::Value upperBound); + +/// Generate runtime call to allocate an allocatable entity +/// as described by the given \p desc descriptor. +void genAllocatableAllocate(fir::FirOpBuilder &builder, mlir::Location loc, + mlir::Value desc, mlir::Value hasStat = {}, + mlir::Value errMsg = {}); + } // namespace fir::runtime #endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_ALLOCATABLE_H diff --git a/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp b/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp --- a/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp @@ -54,3 +54,38 @@ fir::runtime::createArguments(builder, loc, fTy, desc, mold, rankVal)}; builder.create(loc, func, args); } + +void fir::runtime::genAllocatableSetBounds(fir::FirOpBuilder &builder, + mlir::Location loc, mlir::Value desc, + mlir::Value dimIndex, + mlir::Value lowerBound, + mlir::Value upperBound) { + mlir::func::FuncOp func{ + fir::runtime::getRuntimeFunc(loc, + builder)}; + mlir::FunctionType fTy{func.getFunctionType()}; + llvm::SmallVector args{fir::runtime::createArguments( + builder, loc, fTy, desc, dimIndex, lowerBound, upperBound)}; + builder.create(loc, func, args); +} + +void fir::runtime::genAllocatableAllocate(fir::FirOpBuilder &builder, + mlir::Location loc, mlir::Value desc, + mlir::Value hasStat, + mlir::Value errMsg) { + mlir::func::FuncOp func{ + fir::runtime::getRuntimeFunc(loc, builder)}; + mlir::FunctionType fTy{func.getFunctionType()}; + mlir::Value sourceFile{fir::factory::locationToFilename(builder, loc)}; + mlir::Value sourceLine{ + fir::factory::locationToLineNo(builder, loc, fTy.getInput(4))}; + if (!hasStat) + hasStat = builder.createBool(loc, false); + if (!errMsg) { + mlir::Type boxNoneTy = fir::BoxType::get(builder.getNoneType()); + errMsg = builder.create(loc, boxNoneTy).getResult(); + } + llvm::SmallVector args{fir::runtime::createArguments( + builder, loc, fTy, desc, hasStat, errMsg, sourceFile, sourceLine)}; + builder.create(loc, func, args); +} diff --git a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp --- a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp @@ -163,9 +163,52 @@ static std::pair createArrayTemp(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Type exprType, mlir::Value shape, - mlir::ValueRange extents, mlir::ValueRange lenParams) { + mlir::ValueRange extents, mlir::ValueRange lenParams, + std::optional polymorphicMold) { mlir::Type sequenceType = hlfir::getFortranElementOrSequenceType(exprType); llvm::StringRef tmpName{".tmp.array"}; + + if (polymorphicMold) { + // Create *allocated* polymorphic temporary using the dynamic type + // of the mold and the provided shape/extents. The created temporary + // array will be written element per element, that is why it has to be + // allocated. + mlir::Type boxHeapType = fir::HeapType::get(sequenceType); + mlir::Value alloc = fir::factory::genNullBoxStorage( + builder, loc, fir::ClassType::get(boxHeapType)); + mlir::Value isHeapAlloc = builder.createBool(loc, true); + fir::FortranVariableFlagsAttr declAttrs = + fir::FortranVariableFlagsAttr::get( + builder.getContext(), fir::FortranVariableFlagsEnum::allocatable); + + auto declareOp = builder.create(loc, alloc, tmpName, + /*shape=*/nullptr, + lenParams, declAttrs); + + int rank = extents.size(); + fir::runtime::genAllocatableApplyMold(builder, loc, alloc, + polymorphicMold->getFirBase(), rank); + if (!extents.empty()) { + mlir::Type idxTy = builder.getIndexType(); + mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1); + unsigned dim = 0; + for (mlir::Value extent : extents) { + mlir::Value dimIndex = builder.createIntegerConstant(loc, idxTy, dim++); + fir::runtime::genAllocatableSetBounds(builder, loc, alloc, dimIndex, + one, extent); + } + } + if (!lenParams.empty()) { + // We should call AllocatableSetDerivedLength() here. + // TODO: does the mold provide the length parameters or + // the operation itself or should they be in sync? + TODO(loc, "polymorphic type with length parameters in HLFIR"); + } + fir::runtime::genAllocatableAllocate(builder, loc, alloc); + + return {hlfir::Entity{declareOp.getBase()}, isHeapAlloc}; + } + mlir::Value allocmem = builder.createHeapTemporary(loc, sequenceType, tmpName, extents, lenParams); auto declareOp = @@ -676,10 +719,17 @@ builder.setListener(&listener); mlir::Value shape = adaptor.getShape(); + std::optional mold; + if (adaptor.getMold()) + mold = getBufferizedExprStorage(adaptor.getMold()); auto extents = hlfir::getIndexExtents(loc, builder, shape); auto [temp, cleanup] = createArrayTemp(loc, builder, elemental.getType(), shape, extents, - adaptor.getTypeparams()); + adaptor.getTypeparams(), mold); + // If the box load is needed, we'd better place it outside + // of the loop nest. + temp = derefPointersAndAllocatables(loc, builder, temp); + // Generate a loop nest looping around the fir.elemental shape and clone // fir.elemental region inside the inner loop. hlfir::LoopNest loopNest = diff --git a/flang/test/HLFIR/elemental-codegen.fir b/flang/test/HLFIR/elemental-codegen.fir --- a/flang/test/HLFIR/elemental-codegen.fir +++ b/flang/test/HLFIR/elemental-codegen.fir @@ -139,3 +139,221 @@ // CHECK: %[[VAL_13:.*]] = fir.insert_value %[[VAL_12]], %[[VAL_4]]#0, [0 : index] : (tuple>, i1>, !fir.heap>) -> tuple>, i1> // CHECK: return // CHECK: } + +func.func @test_polymorphic(%arg0: !fir.class> {fir.bindc_name = "x"}, %arg1: !fir.class>> {fir.bindc_name = "y"}, %ex0 : index, %ex1 : index) { + %1:2 = hlfir.declare %arg0 {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtestEx"} : (!fir.class>) -> (!fir.class>, !fir.class>) + %2:2 = hlfir.declare %arg1 {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtestEy"} : (!fir.class>>) -> (!fir.class>>, !fir.class>>) + %4 = fir.shape %ex0, %ex1 : (index, index) -> !fir.shape<2> + %5 = hlfir.elemental %4 mold %1#0 unordered : (!fir.shape<2>, !fir.class>) -> !hlfir.expr?> { + ^bb0(%arg3: index, %arg4: index): + %6 = hlfir.designate %2#0 (%arg3, %arg4) : (!fir.class>>, index, index) -> !fir.class> + %7 = hlfir.as_expr %6 : (!fir.class>) -> !hlfir.expr?> + hlfir.yield_element %7 : !hlfir.expr?> + } + return +} +// CHECK-LABEL: func.func @test_polymorphic( +// CHECK-SAME: %[[VAL_0:.*]]: !fir.class> {fir.bindc_name = "x"}, +// CHECK-SAME: %[[VAL_1:.*]]: !fir.class>> {fir.bindc_name = "y"}, +// CHECK-SAME: %[[EX0:.*]]: index, +// CHECK-SAME: %[[EX1:.*]]: index) { +// CHECK: %[[VAL_4:.*]] = fir.alloca !fir.class>>> +// CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_0]] {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtestEx"} : (!fir.class>) -> (!fir.class>, !fir.class>) +// CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_1]] {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtestEy"} : (!fir.class>>) -> (!fir.class>>, !fir.class>>) +// CHECK: %[[VAL_7:.*]] = fir.shape %[[EX0]], %[[EX1]] : (index, index) -> !fir.shape<2> +// CHECK: %[[VAL_8:.*]] = fir.zero_bits !fir.heap>> +// CHECK: %[[VAL_9:.*]] = arith.constant 0 : index +// CHECK: %[[VAL_10:.*]] = fir.shape %[[VAL_9]], %[[VAL_9]] : (index, index) -> !fir.shape<2> +// CHECK: %[[VAL_11:.*]] = fir.embox %[[VAL_8]](%[[VAL_10]]) : (!fir.heap>>, !fir.shape<2>) -> !fir.class>>> +// CHECK: fir.store %[[VAL_11]] to %[[VAL_4]] : !fir.ref>>>> +// CHECK: %[[VAL_12:.*]] = arith.constant true +// CHECK: %[[VAL_13:.*]]:2 = hlfir.declare %[[VAL_4]] {fortran_attrs = #fir.var_attrs, uniq_name = ".tmp.array"} : (!fir.ref>>>>) -> (!fir.ref>>>>, !fir.ref>>>>) +// CHECK: %[[RANK:.*]] = arith.constant 2 : i32 +// CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_4]] : (!fir.ref>>>>) -> !fir.ref> +// CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_5]]#1 : (!fir.class>) -> !fir.box +// CHECK: %[[VAL_17:.*]] = fir.call @_FortranAAllocatableApplyMold(%[[VAL_15]], %[[VAL_16]], %[[RANK]]) : (!fir.ref>, !fir.box, i32) -> none +// CHECK: %[[VAL_18:.*]] = arith.constant 1 : index +// CHECK: %[[VAL_19:.*]] = arith.constant 0 : index +// CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_4]] : (!fir.ref>>>>) -> !fir.ref> +// CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_19]] : (index) -> i32 +// CHECK: %[[VAL_22:.*]] = fir.convert %[[VAL_18]] : (index) -> i64 +// CHECK: %[[VAL_23:.*]] = fir.convert %[[EX0]] : (index) -> i64 +// CHECK: %[[VAL_24:.*]] = fir.call @_FortranAAllocatableSetBounds(%[[VAL_20]], %[[VAL_21]], %[[VAL_22]], %[[VAL_23]]) : (!fir.ref>, i32, i64, i64) -> none +// CHECK: %[[VAL_25:.*]] = arith.constant 1 : index +// CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_4]] : (!fir.ref>>>>) -> !fir.ref> +// CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_25]] : (index) -> i32 +// CHECK: %[[VAL_28:.*]] = fir.convert %[[VAL_18]] : (index) -> i64 +// CHECK: %[[VAL_29:.*]] = fir.convert %[[EX1]] : (index) -> i64 +// CHECK: %[[VAL_30:.*]] = fir.call @_FortranAAllocatableSetBounds(%[[VAL_26]], %[[VAL_27]], %[[VAL_28]], %[[VAL_29]]) : (!fir.ref>, i32, i64, i64) -> none +// CHECK: %[[VAL_31:.*]] = fir.address_of(@_QQcl. +// CHECK: %[[VAL_32:.*]] = arith.constant {{.*}} : index +// CHECK: %[[VAL_33:.*]] = arith.constant {{.*}} : i32 +// CHECK: %[[VAL_34:.*]] = arith.constant false +// CHECK: %[[VAL_35:.*]] = fir.absent !fir.box +// CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_4]] : (!fir.ref>>>>) -> !fir.ref> +// CHECK: %[[VAL_37:.*]] = fir.convert %[[VAL_31]] : (!fir.ref>) -> !fir.ref +// CHECK: %[[VAL_38:.*]] = fir.call @_FortranAAllocatableAllocate(%[[VAL_36]], %[[VAL_34]], %[[VAL_35]], %[[VAL_37]], %[[VAL_33]]) : (!fir.ref>, i1, !fir.box, !fir.ref, i32) -> i32 +// CHECK: %[[VAL_39:.*]] = fir.load %[[VAL_13]]#0 : !fir.ref>>>> +// CHECK: %[[VAL_40:.*]] = arith.constant 1 : index +// CHECK: fir.do_loop %[[VAL_41:.*]] = %[[VAL_40]] to %[[EX1]] step %[[VAL_40]] unordered { +// CHECK: fir.do_loop %[[VAL_42:.*]] = %[[VAL_40]] to %[[EX0]] step %[[VAL_40]] unordered { +// CHECK: %[[VAL_43:.*]] = hlfir.designate %[[VAL_6]]#0 (%[[VAL_42]], %[[VAL_41]]) : (!fir.class>>, index, index) -> !fir.class> +// CHECK: %[[VAL_44:.*]] = arith.constant 0 : index +// CHECK: %[[VAL_45:.*]]:3 = fir.box_dims %[[VAL_39]], %[[VAL_44]] : (!fir.class>>>, index) -> (index, index, index) +// CHECK: %[[VAL_46:.*]] = arith.constant 1 : index +// CHECK: %[[VAL_47:.*]]:3 = fir.box_dims %[[VAL_39]], %[[VAL_46]] : (!fir.class>>>, index) -> (index, index, index) +// CHECK: %[[VAL_48:.*]] = arith.constant 1 : index +// CHECK: %[[VAL_49:.*]] = arith.subi %[[VAL_45]]#0, %[[VAL_48]] : index +// CHECK: %[[VAL_50:.*]] = arith.addi %[[VAL_42]], %[[VAL_49]] : index +// CHECK: %[[VAL_51:.*]] = arith.subi %[[VAL_47]]#0, %[[VAL_48]] : index +// CHECK: %[[VAL_52:.*]] = arith.addi %[[VAL_41]], %[[VAL_51]] : index +// CHECK: %[[VAL_53:.*]] = hlfir.designate %[[VAL_39]] (%[[VAL_50]], %[[VAL_52]]) : (!fir.class>>>, index, index) -> !fir.class> +// CHECK: hlfir.assign %[[VAL_43]] to %[[VAL_53]] temporary_lhs : !fir.class>, !fir.class> +// CHECK: } +// CHECK: } +// CHECK: %[[VAL_54:.*]] = fir.undefined tuple>>>, i1> +// CHECK: %[[VAL_55:.*]] = fir.insert_value %[[VAL_54]], %[[VAL_12]], [1 : index] : (tuple>>>, i1>, i1) -> tuple>>>, i1> +// CHECK: %[[VAL_56:.*]] = fir.insert_value %[[VAL_55]], %[[VAL_39]], [0 : index] : (tuple>>>, i1>, !fir.class>>>) -> tuple>>>, i1> +// CHECK: return +// CHECK: } + +// Test that hlfir.expr mold is properly applied for the second hlfir.elemental. +func.func @test_polymorphic_expr(%arg0: !fir.class> {fir.bindc_name = "x"}, %arg1: !fir.class>> {fir.bindc_name = "y"}, %ex0 : index, %ex1 : index) { + %1:2 = hlfir.declare %arg0 {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtestEx"} : (!fir.class>) -> (!fir.class>, !fir.class>) + %2:2 = hlfir.declare %arg1 {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtestEy"} : (!fir.class>>) -> (!fir.class>>, !fir.class>>) + %4 = fir.shape %ex0, %ex1 : (index, index) -> !fir.shape<2> + %5 = hlfir.elemental %4 mold %1#0 unordered : (!fir.shape<2>, !fir.class>) -> !hlfir.expr?> { + ^bb0(%arg3: index, %arg4: index): + %6 = hlfir.designate %2#0 (%arg3, %arg4) : (!fir.class>>, index, index) -> !fir.class> + %7 = hlfir.as_expr %6 : (!fir.class>) -> !hlfir.expr?> + hlfir.yield_element %7 : !hlfir.expr?> + } + %8 = hlfir.elemental %4 mold %5 unordered : (!fir.shape<2>, !hlfir.expr?>) -> !hlfir.expr?> { + ^bb0(%arg3: index, %arg4: index): + %9 = hlfir.apply %5, %arg3, %arg4 : (!hlfir.expr?>, index, index) -> !hlfir.expr?> + hlfir.yield_element %9 : !hlfir.expr?> + } + return +} +// CHECK-LABEL: func.func @test_polymorphic_expr( +// CHECK-SAME: %[[VAL_0:.*]]: !fir.class> {fir.bindc_name = "x"}, +// CHECK-SAME: %[[VAL_1:.*]]: !fir.class>> {fir.bindc_name = "y"}, +// CHECK-SAME: %[[VAL_2:.*]]: index, +// CHECK-SAME: %[[VAL_3:.*]]: index) { +// CHECK: %[[VAL_4:.*]] = fir.alloca !fir.class>>> +// CHECK: %[[VAL_5:.*]] = fir.alloca !fir.class>>> +// CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_0]] {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtestEx"} : (!fir.class>) -> (!fir.class>, !fir.class>) +// CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_1]] {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtestEy"} : (!fir.class>>) -> (!fir.class>>, !fir.class>>) +// CHECK: %[[VAL_8:.*]] = fir.shape %[[VAL_2]], %[[VAL_3]] : (index, index) -> !fir.shape<2> +// CHECK: %[[VAL_9:.*]] = fir.zero_bits !fir.heap>> +// CHECK: %[[VAL_10:.*]] = arith.constant 0 : index +// CHECK: %[[VAL_11:.*]] = fir.shape %[[VAL_10]], %[[VAL_10]] : (index, index) -> !fir.shape<2> +// CHECK: %[[VAL_12:.*]] = fir.embox %[[VAL_9]](%[[VAL_11]]) : (!fir.heap>>, !fir.shape<2>) -> !fir.class>>> +// CHECK: fir.store %[[VAL_12]] to %[[VAL_5]] : !fir.ref>>>> +// CHECK: %[[VAL_13:.*]] = arith.constant true +// CHECK: %[[VAL_14:.*]]:2 = hlfir.declare %[[VAL_5]] {fortran_attrs = #fir.var_attrs, uniq_name = ".tmp.array"} : (!fir.ref>>>>) -> (!fir.ref>>>>, !fir.ref>>>>) +// CHECK: %[[VAL_15:.*]] = arith.constant 2 : i32 +// CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_5]] : (!fir.ref>>>>) -> !fir.ref> +// CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_6]]#1 : (!fir.class>) -> !fir.box +// CHECK: %[[VAL_18:.*]] = fir.call @_FortranAAllocatableApplyMold(%[[VAL_16]], %[[VAL_17]], %[[VAL_15]]) : (!fir.ref>, !fir.box, i32) -> none +// CHECK: %[[VAL_19:.*]] = arith.constant 1 : index +// CHECK: %[[VAL_20:.*]] = arith.constant 0 : index +// CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_5]] : (!fir.ref>>>>) -> !fir.ref> +// CHECK: %[[VAL_22:.*]] = fir.convert %[[VAL_20]] : (index) -> i32 +// CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_19]] : (index) -> i64 +// CHECK: %[[VAL_24:.*]] = fir.convert %[[VAL_2]] : (index) -> i64 +// CHECK: %[[VAL_25:.*]] = fir.call @_FortranAAllocatableSetBounds(%[[VAL_21]], %[[VAL_22]], %[[VAL_23]], %[[VAL_24]]) : (!fir.ref>, i32, i64, i64) -> none +// CHECK: %[[VAL_26:.*]] = arith.constant 1 : index +// CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_5]] : (!fir.ref>>>>) -> !fir.ref> +// CHECK: %[[VAL_28:.*]] = fir.convert %[[VAL_26]] : (index) -> i32 +// CHECK: %[[VAL_29:.*]] = fir.convert %[[VAL_19]] : (index) -> i64 +// CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_3]] : (index) -> i64 +// CHECK: %[[VAL_31:.*]] = fir.call @_FortranAAllocatableSetBounds(%[[VAL_27]], %[[VAL_28]], %[[VAL_29]], %[[VAL_30]]) : (!fir.ref>, i32, i64, i64) -> none +// CHECK: %[[VAL_32:.*]] = fir.address_of(@_QQcl +// CHECK: %[[VAL_33:.*]] = arith.constant {{.*}} : index +// CHECK: %[[VAL_34:.*]] = arith.constant {{.*}} : i32 +// CHECK: %[[VAL_35:.*]] = arith.constant false +// CHECK: %[[VAL_36:.*]] = fir.absent !fir.box +// CHECK: %[[VAL_37:.*]] = fir.convert %[[VAL_5]] : (!fir.ref>>>>) -> !fir.ref> +// CHECK: %[[VAL_38:.*]] = fir.convert %[[VAL_32]] : (!fir.ref>) -> !fir.ref +// CHECK: %[[VAL_39:.*]] = fir.call @_FortranAAllocatableAllocate(%[[VAL_37]], %[[VAL_35]], %[[VAL_36]], %[[VAL_38]], %[[VAL_34]]) : (!fir.ref>, i1, !fir.box, !fir.ref, i32) -> i32 +// CHECK: %[[VAL_40:.*]] = fir.load %[[VAL_14]]#0 : !fir.ref>>>> +// CHECK: %[[VAL_41:.*]] = arith.constant 1 : index +// CHECK: fir.do_loop %[[VAL_42:.*]] = %[[VAL_41]] to %[[VAL_3]] step %[[VAL_41]] unordered { +// CHECK: fir.do_loop %[[VAL_43:.*]] = %[[VAL_41]] to %[[VAL_2]] step %[[VAL_41]] unordered { +// CHECK: %[[VAL_44:.*]] = hlfir.designate %[[VAL_7]]#0 (%[[VAL_43]], %[[VAL_42]]) : (!fir.class>>, index, index) -> !fir.class> +// CHECK: %[[VAL_45:.*]] = arith.constant 0 : index +// CHECK: %[[VAL_46:.*]]:3 = fir.box_dims %[[VAL_40]], %[[VAL_45]] : (!fir.class>>>, index) -> (index, index, index) +// CHECK: %[[VAL_47:.*]] = arith.constant 1 : index +// CHECK: %[[VAL_48:.*]]:3 = fir.box_dims %[[VAL_40]], %[[VAL_47]] : (!fir.class>>>, index) -> (index, index, index) +// CHECK: %[[VAL_49:.*]] = arith.constant 1 : index +// CHECK: %[[VAL_50:.*]] = arith.subi %[[VAL_46]]#0, %[[VAL_49]] : index +// CHECK: %[[VAL_51:.*]] = arith.addi %[[VAL_43]], %[[VAL_50]] : index +// CHECK: %[[VAL_52:.*]] = arith.subi %[[VAL_48]]#0, %[[VAL_49]] : index +// CHECK: %[[VAL_53:.*]] = arith.addi %[[VAL_42]], %[[VAL_52]] : index +// CHECK: %[[VAL_54:.*]] = hlfir.designate %[[VAL_40]] (%[[VAL_51]], %[[VAL_53]]) : (!fir.class>>>, index, index) -> !fir.class> +// CHECK: hlfir.assign %[[VAL_44]] to %[[VAL_54]] temporary_lhs : !fir.class>, !fir.class> +// CHECK: } +// CHECK: } +// CHECK: %[[VAL_55:.*]] = fir.undefined tuple>>>, i1> +// CHECK: %[[VAL_56:.*]] = fir.insert_value %[[VAL_55]], %[[VAL_13]], [1 : index] : (tuple>>>, i1>, i1) -> tuple>>>, i1> +// CHECK: %[[VAL_57:.*]] = fir.insert_value %[[VAL_56]], %[[VAL_40]], [0 : index] : (tuple>>>, i1>, !fir.class>>>) -> tuple>>>, i1> +// CHECK: %[[VAL_58:.*]] = fir.zero_bits !fir.heap>> +// CHECK: %[[VAL_59:.*]] = arith.constant 0 : index +// CHECK: %[[VAL_60:.*]] = fir.shape %[[VAL_59]], %[[VAL_59]] : (index, index) -> !fir.shape<2> +// CHECK: %[[VAL_61:.*]] = fir.embox %[[VAL_58]](%[[VAL_60]]) : (!fir.heap>>, !fir.shape<2>) -> !fir.class>>> +// CHECK: fir.store %[[VAL_61]] to %[[VAL_4]] : !fir.ref>>>> +// CHECK: %[[VAL_62:.*]] = arith.constant true +// CHECK: %[[VAL_63:.*]]:2 = hlfir.declare %[[VAL_4]] {fortran_attrs = #fir.var_attrs, uniq_name = ".tmp.array"} : (!fir.ref>>>>) -> (!fir.ref>>>>, !fir.ref>>>>) +// CHECK: %[[VAL_64:.*]] = arith.constant 2 : i32 +// CHECK: %[[VAL_65:.*]] = fir.convert %[[VAL_4]] : (!fir.ref>>>>) -> !fir.ref> +// CHECK: %[[VAL_66:.*]] = fir.convert %[[VAL_40]] : (!fir.class>>>) -> !fir.box +// CHECK: %[[VAL_67:.*]] = fir.call @_FortranAAllocatableApplyMold(%[[VAL_65]], %[[VAL_66]], %[[VAL_64]]) : (!fir.ref>, !fir.box, i32) -> none +// CHECK: %[[VAL_68:.*]] = arith.constant 1 : index +// CHECK: %[[VAL_69:.*]] = arith.constant 0 : index +// CHECK: %[[VAL_70:.*]] = fir.convert %[[VAL_4]] : (!fir.ref>>>>) -> !fir.ref> +// CHECK: %[[VAL_71:.*]] = fir.convert %[[VAL_69]] : (index) -> i32 +// CHECK: %[[VAL_72:.*]] = fir.convert %[[VAL_68]] : (index) -> i64 +// CHECK: %[[VAL_73:.*]] = fir.convert %[[VAL_2]] : (index) -> i64 +// CHECK: %[[VAL_74:.*]] = fir.call @_FortranAAllocatableSetBounds(%[[VAL_70]], %[[VAL_71]], %[[VAL_72]], %[[VAL_73]]) : (!fir.ref>, i32, i64, i64) -> none +// CHECK: %[[VAL_75:.*]] = arith.constant 1 : index +// CHECK: %[[VAL_76:.*]] = fir.convert %[[VAL_4]] : (!fir.ref>>>>) -> !fir.ref> +// CHECK: %[[VAL_77:.*]] = fir.convert %[[VAL_75]] : (index) -> i32 +// CHECK: %[[VAL_78:.*]] = fir.convert %[[VAL_68]] : (index) -> i64 +// CHECK: %[[VAL_79:.*]] = fir.convert %[[VAL_3]] : (index) -> i64 +// CHECK: %[[VAL_80:.*]] = fir.call @_FortranAAllocatableSetBounds(%[[VAL_76]], %[[VAL_77]], %[[VAL_78]], %[[VAL_79]]) : (!fir.ref>, i32, i64, i64) -> none +// CHECK: %[[VAL_81:.*]] = fir.address_of(@_QQcl +// CHECK: %[[VAL_82:.*]] = arith.constant {{.*}} : index +// CHECK: %[[VAL_83:.*]] = arith.constant {{.*}} : i32 +// CHECK: %[[VAL_84:.*]] = arith.constant false +// CHECK: %[[VAL_85:.*]] = fir.absent !fir.box +// CHECK: %[[VAL_86:.*]] = fir.convert %[[VAL_4]] : (!fir.ref>>>>) -> !fir.ref> +// CHECK: %[[VAL_87:.*]] = fir.convert %[[VAL_81]] : (!fir.ref>) -> !fir.ref +// CHECK: %[[VAL_88:.*]] = fir.call @_FortranAAllocatableAllocate(%[[VAL_86]], %[[VAL_84]], %[[VAL_85]], %[[VAL_87]], %[[VAL_83]]) : (!fir.ref>, i1, !fir.box, !fir.ref, i32) -> i32 +// CHECK: %[[VAL_89:.*]] = fir.load %[[VAL_63]]#0 : !fir.ref>>>> +// CHECK: %[[VAL_90:.*]] = arith.constant 1 : index +// CHECK: fir.do_loop %[[VAL_91:.*]] = %[[VAL_90]] to %[[VAL_3]] step %[[VAL_90]] unordered { +// CHECK: fir.do_loop %[[VAL_92:.*]] = %[[VAL_90]] to %[[VAL_2]] step %[[VAL_90]] unordered { +// CHECK: %[[VAL_93:.*]] = hlfir.designate %[[VAL_40]] (%[[VAL_92]], %[[VAL_91]]) : (!fir.class>>>, index, index) -> !fir.class> +// CHECK: %[[VAL_94:.*]] = arith.constant false +// CHECK: %[[VAL_95:.*]] = fir.undefined tuple>, i1> +// CHECK: %[[VAL_96:.*]] = fir.insert_value %[[VAL_95]], %[[VAL_94]], [1 : index] : (tuple>, i1>, i1) -> tuple>, i1> +// CHECK: %[[VAL_97:.*]] = fir.insert_value %[[VAL_96]], %[[VAL_93]], [0 : index] : (tuple>, i1>, !fir.class>) -> tuple>, i1> +// CHECK: %[[VAL_98:.*]] = arith.constant 0 : index +// CHECK: %[[VAL_99:.*]]:3 = fir.box_dims %[[VAL_89]], %[[VAL_98]] : (!fir.class>>>, index) -> (index, index, index) +// CHECK: %[[VAL_100:.*]] = arith.constant 1 : index +// CHECK: %[[VAL_101:.*]]:3 = fir.box_dims %[[VAL_89]], %[[VAL_100]] : (!fir.class>>>, index) -> (index, index, index) +// CHECK: %[[VAL_102:.*]] = arith.constant 1 : index +// CHECK: %[[VAL_103:.*]] = arith.subi %[[VAL_99]]#0, %[[VAL_102]] : index +// CHECK: %[[VAL_104:.*]] = arith.addi %[[VAL_92]], %[[VAL_103]] : index +// CHECK: %[[VAL_105:.*]] = arith.subi %[[VAL_101]]#0, %[[VAL_102]] : index +// CHECK: %[[VAL_106:.*]] = arith.addi %[[VAL_91]], %[[VAL_105]] : index +// CHECK: %[[VAL_107:.*]] = hlfir.designate %[[VAL_89]] (%[[VAL_104]], %[[VAL_106]]) : (!fir.class>>>, index, index) -> !fir.class> +// CHECK: hlfir.assign %[[VAL_93]] to %[[VAL_107]] temporary_lhs : !fir.class>, !fir.class> +// CHECK: } +// CHECK: } +// CHECK: %[[VAL_108:.*]] = fir.undefined tuple>>>, i1> +// CHECK: %[[VAL_109:.*]] = fir.insert_value %[[VAL_108]], %[[VAL_62]], [1 : index] : (tuple>>>, i1>, i1) -> tuple>>>, i1> +// CHECK: %[[VAL_110:.*]] = fir.insert_value %[[VAL_109]], %[[VAL_89]], [0 : index] : (tuple>>>, i1>, !fir.class>>>) -> tuple>>>, i1> +// CHECK: return +// CHECK: }