[flang-commits] [flang] 13cde11 - [flang] Support fir.class in scalar user defined assignment lowering
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Tue Dec 6 13:02:34 PST 2022
Author: Valentin Clement
Date: 2022-12-06T22:02:25+01:00
New Revision: 13cde1129e4b16fb56940402a39212ff86c6cac8
URL: https://github.com/llvm/llvm-project/commit/13cde1129e4b16fb56940402a39212ff86c6cac8
DIFF: https://github.com/llvm/llvm-project/commit/13cde1129e4b16fb56940402a39212ff86c6cac8.diff
LOG: [flang] Support fir.class in scalar user defined assignment lowering
Support fir.class in genScalarUserDefinedAssignmentCall so
emboxing is done correctly.
Reviewed By: jeanPerier, PeteSteinfeld
Differential Revision: https://reviews.llvm.org/D139435
Added:
Modified:
flang/lib/Lower/ConvertExpr.cpp
flang/test/Lower/polymorphic.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index 3ecb217a717c4..25696c8f392b5 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -2970,8 +2970,9 @@ static void genScalarUserDefinedAssignmentCall(fir::FirOpBuilder &builder,
return fir::factory::CharacterExprHelper{builder, loc}.createEmbox(
*charBox);
}
- if (argType.isa<fir::BoxType>()) {
- mlir::Value box = builder.createBox(loc, value);
+ if (argType.isa<fir::BaseBoxType>()) {
+ mlir::Value box =
+ builder.createBox(loc, value, argType.isa<fir::ClassType>());
return builder.createConvert(loc, argType, box);
}
// Simple pass by address.
diff --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90
index 3ac805556dee1..ce8eff0b1a7ab 100644
--- a/flang/test/Lower/polymorphic.f90
+++ b/flang/test/Lower/polymorphic.f90
@@ -8,6 +8,8 @@ module polymorphic_test
integer :: b
contains
procedure :: print
+ procedure :: assign_p1_int
+ generic :: assignment(=) => assign_p1_int
end type
type, extends(p1) :: p2
@@ -30,6 +32,13 @@ module polymorphic_test
contains
+ elemental subroutine assign_p1_int(lhs, rhs)
+ class(p1), intent(inout) :: lhs
+ integer, intent(in) :: rhs
+ lhs%a = rhs
+ lhs%b = rhs
+ End Subroutine
+
! Test correct access to polymorphic entity component.
subroutine component_access(p)
class(p1) :: p
@@ -375,4 +384,33 @@ subroutine pointer_assign_remap()
! CHECK: %[[ARG2:.*]] = fir.convert %[[BOXED_BOUND_ARRAY]] : (!fir.box<!fir.array<2xi64>>) -> !fir.box<none>
! CHECK: %{{.*}} = fir.call @_FortranAPointerAssociateRemapping(%[[ARG0]], %[[ARG1]], %[[ARG2]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.box<none>, !fir.ref<i8>, i32) -> none
+ subroutine test_elemental_assign()
+ type(p1) :: pa(3)
+ pa = [ 1, 2, 3 ]
+ end subroutine
+
+! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_elemental_assign() {
+! CHECK: %[[INT:.*]] = fir.alloca i32
+! CHECK: %[[C3_0:.*]] = arith.constant 3 : index
+! CHECK: %[[PA:.*]] = fir.alloca !fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {bindc_name = "pa", uniq_name = "_QMpolymorphic_testFtest_elemental_assignEpa"}
+! CHECK: %[[SHAPE:.*]] = fir.shape %[[C3_0]] : (index) -> !fir.shape<1>
+! CHECK: %[[LOAD_PA:.*]] = fir.array_load %[[PA]](%[[SHAPE]]) : (!fir.ref<!fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, !fir.shape<1>) -> !fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>
+! CHECK: %[[ADDR_INT:.*]] = fir.address_of(@_QQro.3xi4.{{.*}}) : !fir.ref<!fir.array<3xi32>>
+! CHECK: %[[C3:.*]] = arith.constant 3 : index
+! CHECK: %[[SHAPE:.*]] = fir.shape %[[C3]] : (index) -> !fir.shape<1>
+! CHECK: %[[LOAD_INT_ARRAY:.*]] = fir.array_load %[[ADDR_INT]](%[[SHAPE]]) : (!fir.ref<!fir.array<3xi32>>, !fir.shape<1>) -> !fir.array<3xi32>
+! CHECK: %[[C1:.*]] = arith.constant 1 : index
+! CHECK: %[[C0:.*]] = arith.constant 0 : index
+! CHECK: %[[UB:.*]] = arith.subi %[[C3_0]], %[[C1]] : index
+! CHECK: %[[DO_RES:.*]] = fir.do_loop %[[ARG0:.*]] = %[[C0]] to %[[UB]] step %[[C1]] unordered iter_args(%[[ARG1:.*]] = %[[LOAD_PA]]) -> (!fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) {
+! CHECK: %[[FETCH_INT:.*]] = fir.array_fetch %[[LOAD_INT_ARRAY]], %[[ARG0]] : (!fir.array<3xi32>, index) -> i32
+! CHECK: %[[ARRAY_MOD:.*]]:2 = fir.array_modify %[[ARG1]], %[[ARG0]] : (!fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, index) -> (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>)
+! CHECK: %[[EMBOXED:.*]] = fir.embox %10#0 : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>
+! CHECK: fir.store %[[FETCH_INT]] to %[[INT]] : !fir.ref<i32>
+! CHECK: fir.call @_QMpolymorphic_testPassign_p1_int(%[[EMBOXED]], %[[INT]]) fastmath<contract> : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.ref<i32>) -> ()
+! CHECK: fir.result %[[ARRAY_MOD]]#1 : !fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>
+! CHECK: }
+! CHECK: fir.array_merge_store %[[LOAD_PA]], %[[DO_RES]] to %[[PA]] : !fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.ref<!fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>
+! CHECK: return
+
end module
More information about the flang-commits
mailing list