From cc84705a241ca492c80a9dc6027b87ac8a6dad5b Mon Sep 17 00:00:00 2001 From: Slava Zakharin Date: Mon, 15 May 2023 09:02:14 -0700 Subject: [flang][hlfir] Fixed copy-in for polymorphic arguments. Reviewed By: jeanPerier Differential Revision: https://reviews.llvm.org/D150502 --- .../Optimizer/HLFIR/Transforms/ConvertToFIR.cpp | 10 +++---- flang/test/HLFIR/copy-in-out-codegen.fir | 33 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) (limited to 'flang') diff --git a/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp index 0225ac3631b9..ab1f7417531b 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp @@ -42,13 +42,11 @@ static mlir::Value genAllocatableTempFromSourceBox(mlir::Location loc, // the RHS. // This has the huge benefit of dealing with all cases, including // polymorphic entities. - mlir::Type fromHeapType = fir::HeapType::get( - fir::unwrapRefType(sourceBox.getType().cast().getEleTy())); + mlir::Type fromHeapType = fir::HeapType::get(fir::unwrapRefType( + sourceBox.getType().cast().getEleTy())); mlir::Type fromBoxHeapType = fir::BoxType::get(fromHeapType); - auto fromMutableBox = builder.createTemporary(loc, fromBoxHeapType); - mlir::Value unallocatedBox = - fir::factory::createUnallocatedBox(builder, loc, fromBoxHeapType, {}); - builder.create(loc, unallocatedBox, fromMutableBox); + mlir::Value fromMutableBox = + fir::factory::genNullBoxStorage(builder, loc, fromBoxHeapType); fir::runtime::genAssign(builder, loc, fromMutableBox, sourceBox); mlir::Value copy = builder.create(loc, fromMutableBox); return copy; diff --git a/flang/test/HLFIR/copy-in-out-codegen.fir b/flang/test/HLFIR/copy-in-out-codegen.fir index b6c7a3c1f378..71962d90f013 100644 --- a/flang/test/HLFIR/copy-in-out-codegen.fir +++ b/flang/test/HLFIR/copy-in-out-codegen.fir @@ -94,3 +94,36 @@ func.func @test_copy_out_copy_back(%box: !fir.box>, %temp: !fi // CHECK: %[[VAL_11:.*]] = fir.box_addr %[[VAL_1]] : (!fir.box>) -> !fir.heap> // CHECK: fir.freemem %[[VAL_11]] : !fir.heap> // CHECK: } + +func.func @test_copy_in_poly(%poly : !fir.class>>) { + %0:2 = hlfir.copy_in %poly : (!fir.class>>) -> (!fir.class>>, i1) + return +} +// CHECK-LABEL: func.func @test_copy_in_poly( +// CHECK-SAME: %[[VAL_0:.*]]: !fir.class>>) { +// CHECK: %[[VAL_1:.*]] = fir.alloca !fir.box>>> +// CHECK: %[[VAL_2:.*]] = fir.convert %[[VAL_0]] : (!fir.class>>) -> !fir.box +// CHECK: %[[VAL_3:.*]] = fir.call @_FortranAIsContiguous(%[[VAL_2]]) : (!fir.box) -> i1 +// CHECK: %[[VAL_4:.*]] = fir.if %[[VAL_3]] -> (!fir.class>>) { +// CHECK: fir.result %[[VAL_0]] : !fir.class>> +// CHECK: } else { +// CHECK: %[[VAL_5:.*]] = fir.zero_bits !fir.heap>> +// CHECK: %[[VAL_6:.*]] = arith.constant 0 : index +// CHECK: %[[VAL_7:.*]] = fir.shape %[[VAL_6]] : (index) -> !fir.shape<1> +// CHECK: %[[VAL_8:.*]] = fir.embox %[[VAL_5]](%[[VAL_7]]) : (!fir.heap>>, !fir.shape<1>) -> !fir.box>>> +// CHECK: fir.store %[[VAL_8]] to %[[VAL_1]] : !fir.ref>>>> +// CHECK: %[[VAL_9:.*]] = fir.address_of(@_QQcl.{{.*}}) : !fir.ref> +// CHECK: %[[VAL_10:.*]] = arith.constant {{.*}} : index +// CHECK: %[[VAL_11:.*]] = arith.constant {{.*}} : i32 +// CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_1]] : (!fir.ref>>>>) -> !fir.ref> +// CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_0]] : (!fir.class>>) -> !fir.box +// CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_9]] : (!fir.ref>) -> !fir.ref +// CHECK: %[[VAL_15:.*]] = fir.call @_FortranAAssign(%[[VAL_12]], %[[VAL_13]], %[[VAL_14]], %[[VAL_11]]) : (!fir.ref>, !fir.box, !fir.ref, i32) -> none +// CHECK: %[[VAL_16:.*]] = fir.load %[[VAL_1]] : !fir.ref>>>> +// CHECK: %[[VAL_17:.*]] = fir.rebox %[[VAL_16]] : (!fir.box>>>) -> !fir.class>> +// CHECK: fir.result %[[VAL_17]] : !fir.class>> +// CHECK: } +// CHECK: %[[VAL_18:.*]] = arith.constant false +// CHECK: %[[VAL_19:.*]] = arith.cmpi eq, %[[VAL_3]], %[[VAL_18]] : i1 +// CHECK: return +// CHECK: } -- cgit v1.2.1