[flang-commits] [flang] 623c896 - [flang] Support polymorphic inputs for TRANSFER intrinsic

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Thu Feb 9 11:17:38 PST 2023


Author: Valentin Clement
Date: 2023-02-09T20:17:31+01:00
New Revision: 623c896aafdf0e7c155f40a18b8aad0bfb663d7c

URL: https://github.com/llvm/llvm-project/commit/623c896aafdf0e7c155f40a18b8aad0bfb663d7c
DIFF: https://github.com/llvm/llvm-project/commit/623c896aafdf0e7c155f40a18b8aad0bfb663d7c.diff

LOG: [flang] Support polymorphic inputs for TRANSFER intrinsic

Result must carry the polymorphic type information from the mold.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D143651

Added: 
    

Modified: 
    flang/lib/Optimizer/Builder/IntrinsicCall.cpp
    flang/test/Lower/polymorphic-temp.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 16dced798296..cc01e49854a2 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -4930,7 +4930,8 @@ IntrinsicLibrary::genTransfer(mlir::Type resultType,
                         ? resultType
                         : builder.getVarLenSeqTy(resultType, 1);
   fir::MutableBoxValue resultMutableBox =
-      fir::factory::createTempMutableBox(builder, loc, type);
+      fir::factory::createTempMutableBox(builder, loc, type, {},
+      fir::isPolymorphicType(mold.getType()) ? mold : mlir::Value{});
 
   if (moldRank == 0 && absentSize) {
     // This result is a scalar in this case.

diff  --git a/flang/test/Lower/polymorphic-temp.f90 b/flang/test/Lower/polymorphic-temp.f90
index 71ea39711876..7858c9563fc1 100644
--- a/flang/test/Lower/polymorphic-temp.f90
+++ b/flang/test/Lower/polymorphic-temp.f90
@@ -80,14 +80,14 @@ subroutine test_temp_from_intrinsic_reshape(i)
 ! CHECK: %[[RES_BOX_NONE:.*]] = fir.convert %[[LOAD_RES]] : (!fir.class<!fir.heap<!fir.array<?x?xnone>>>) -> !fir.box<none>
 ! CHECK: %{{.*}} = fir.call @_FortranAAllocatableApplyMold(%[[A_BOX_NONE]], %[[RES_BOX_NONE]], %[[RANK]]) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>, i32) -> none
 
-  subroutine check_pack(r)
+  subroutine check(r)
     class(p1) :: r(:)
   end subroutine
 
   subroutine test_temp_from_intrinsic_pack(i, mask)
     class(p1), intent(in) :: i(20, 20)
     logical, intent(in) :: mask(20, 20)
-    call check_pack(pack(i, mask))
+    call check(pack(i, mask))
   end subroutine
 
 ! CHECK-LABEL: func.func @_QMpoly_tmpPtest_temp_from_intrinsic_pack(
@@ -163,4 +163,18 @@ subroutine test_temp_from_intrinsic_eoshift(a, shift, b)
 ! CHECK: %[[BOUNDARY_NONE:.*]] = fir.convert %[[BOUNDARY]] : (!fir.class<!fir.type<_QMpoly_tmpTp1{a:i32}>>) -> !fir.box<none>
 ! CHECK: %{{.*}} = fir.call @_FortranAEoshiftVector(%[[RES_BOX_NONE]], %[[ARRAY_NONE]], %[[SHIFT_I64]], %[[BOUNDARY_NONE]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>, i64, !fir.box<none>, !fir.ref<i8>, i32) -> none
 
+  subroutine test_temp_from_intrinsic_transfer(source, mold)
+    class(p1), intent(in) :: source(:)
+    class(p1), intent(in) :: mold(:)
+    call check(transfer(source, mold))
+  end subroutine
+
+! CHECK-LABEL: func.func @_QMpoly_tmpPtest_temp_from_intrinsic_transfer(
+! CHECK-SAME: %[[SOURCE:.*]]: !fir.class<!fir.array<?x!fir.type<_QMpoly_tmpTp1{a:i32}>>> {fir.bindc_name = "source"}, %[[MOLD:.*]]: !fir.class<!fir.array<?x!fir.type<_QMpoly_tmpTp1{a:i32}>>> {fir.bindc_name = "mold"}) {
+! CHECK: %[[TMP_RES:.*]] = fir.alloca !fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpoly_tmpTp1{a:i32}>>>>
+! CHECK: %[[RES_BOX_NONE:.*]] = fir.convert %[[TMP_RES]] : (!fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpoly_tmpTp1{a:i32}>>>>>) -> !fir.ref<!fir.box<none>>
+! CHECK: %[[SOURCE_NONE:.*]] = fir.convert %[[SOURCE]] : (!fir.class<!fir.array<?x!fir.type<_QMpoly_tmpTp1{a:i32}>>>) -> !fir.box<none>
+! CHECK: %[[MOLD_NONE:.*]] = fir.convert %[[MOLD]] : (!fir.class<!fir.array<?x!fir.type<_QMpoly_tmpTp1{a:i32}>>>) -> !fir.box<none>
+! CHECK: %{{.*}} = fir.call @_FortranATransfer(%[[RES_BOX_NONE]], %[[SOURCE_NONE]], %[[MOLD_NONE]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.box<none>, !fir.ref<i8>, i32) -> none
+
 end module


        


More information about the flang-commits mailing list