[flang-commits] [flang] 131585a - [flang] Use genExprBox for the rhs when calling PointerAssociate for unlimited polymorphic pointer
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Thu Dec 1 02:12:30 PST 2022
Author: Valentin Clement
Date: 2022-12-01T11:12:24+01:00
New Revision: 131585ab0fd0ed43d6fd7325ff75d6fa6e623a4b
URL: https://github.com/llvm/llvm-project/commit/131585ab0fd0ed43d6fd7325ff75d6fa6e623a4b
DIFF: https://github.com/llvm/llvm-project/commit/131585ab0fd0ed43d6fd7325ff75d6fa6e623a4b.diff
LOG: [flang] Use genExprBox for the rhs when calling PointerAssociate for unlimited polymorphic pointer
In D139019 the assumption was made that the rhs was also the MutableBox
but this is not a constraint. Use genExprBox instead. Also the allowed
conversion in D139019 was not correct. Remoed it since it is not needed anymore.
Reviewed By: jeanPerier
Differential Revision: https://reviews.llvm.org/D139081
Added:
Modified:
flang/include/flang/Optimizer/Dialect/FIRType.h
flang/lib/Lower/Bridge.cpp
flang/lib/Optimizer/Dialect/FIROps.cpp
flang/lib/Optimizer/Dialect/FIRType.cpp
flang/test/Lower/polymorphic.f90
Removed:
################################################################################
diff --git a/flang/include/flang/Optimizer/Dialect/FIRType.h b/flang/include/flang/Optimizer/Dialect/FIRType.h
index ae50d08970edd..0928e8522838d 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRType.h
+++ b/flang/include/flang/Optimizer/Dialect/FIRType.h
@@ -280,12 +280,6 @@ bool isAllocatableType(mlir::Type ty);
/// e.g. !fir.box<!fir.type<derived>>
bool isBoxedRecordType(mlir::Type ty);
-/// Return true iff `ty` is a !fir.ref<!fir.box<T>> type.
-bool isRefBoxType(mlir::Type ty);
-
-/// Return true iff `ty` is !fir.box<none> type.
-bool isOpaqueDescType(mlir::Type ty);
-
/// Return true iff `ty` is the type of an polymorphic entity or
/// value.
bool isPolymorphicType(mlir::Type ty);
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index c98d83808d3ef..ec380b244491b 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -2718,7 +2718,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
// course base_addr might need to be updated.
if (lhsType && lhsType->IsUnlimitedPolymorphic()) {
mlir::Value lhs = genExprMutableBox(loc, assign.lhs).getAddr();
- mlir::Value rhs = genExprMutableBox(loc, assign.rhs).getAddr();
+ mlir::Value rhs =
+ fir::getBase(genExprBox(loc, assign.rhs, stmtCtx));
Fortran::lower::genPointerAssociate(*builder, loc, lhs, rhs);
return;
}
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index 0adeb6bc086ce..6eb9be5b7f284 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -938,8 +938,7 @@ mlir::LogicalResult fir::ConvertOp::verify() {
(inType.isa<fir::BoxProcType>() && outType.isa<fir::BoxProcType>()) ||
(fir::isa_complex(inType) && fir::isa_complex(outType)) ||
(fir::isBoxedRecordType(inType) && fir::isPolymorphicType(outType)) ||
- (fir::isPolymorphicType(inType) && fir::isPolymorphicType(outType)) ||
- (fir::isRefBoxType(inType) && fir::isOpaqueDescType(outType)))
+ (fir::isPolymorphicType(inType) && fir::isPolymorphicType(outType)))
return mlir::success();
llvm::errs() << inType << " / " << outType << "\n";
return emitOpError("invalid type conversion");
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index a2906e8a5bc0c..89a806c0474aa 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -274,19 +274,6 @@ bool isBoxedRecordType(mlir::Type ty) {
return false;
}
-bool isRefBoxType(mlir::Type ty) {
- if (auto refTy = ty.dyn_cast<fir::ReferenceType>())
- return refTy.getEleTy().isa<fir::BaseBoxType>();
- return false;
-}
-
-bool isOpaqueDescType(mlir::Type ty) {
- if (auto boxTy = ty.dyn_cast<fir::BoxType>())
- if (boxTy.getEleTy().isa<mlir::NoneType>())
- return true;
- return false;
-}
-
static bool isAssumedType(mlir::Type ty) {
if (auto boxTy = ty.dyn_cast<fir::BoxType>()) {
if (boxTy.getEleTy().isa<mlir::NoneType>())
diff --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90
index 662aca9933aae..a1e4b59145081 100644
--- a/flang/test/Lower/polymorphic.f90
+++ b/flang/test/Lower/polymorphic.f90
@@ -141,9 +141,11 @@ subroutine associate_up_pointer(r)
! CHECK: %[[P:.*]] = fir.alloca !fir.class<!fir.ptr<!fir.array<?xnone>>> {bindc_name = "p", uniq_name = "_QMpolymorphic_testFassociate_up_pointerEp"}
! CHECK: %[[FIELD_RP:.*]] = fir.field_index rp, !fir.type<_QMpolymorphic_testTr1{rp:!fir.box<!fir.ptr<!fir.array<?xf32>>>}>
! CHECK: %[[COORD_RP:.*]] = fir.coordinate_of %[[ARG0]], %[[FIELD_RP]] : (!fir.class<!fir.type<_QMpolymorphic_testTr1{rp:!fir.box<!fir.ptr<!fir.array<?xf32>>>}>>, !fir.field) -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
+! CHECK: %[[LOAD_RP:.*]] = fir.load %[[COORD_RP]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
+! CHECK: %[[REBOX_RP:.*]] = fir.rebox %[[LOAD_RP]](%{{.*}}) : (!fir.box<!fir.ptr<!fir.array<?xf32>>>, !fir.shift<1>) -> !fir.box<!fir.array<?xf32>>
! CHECK: %[[CONV_P:.*]] = fir.convert %[[P]] : (!fir.ref<!fir.class<!fir.ptr<!fir.array<?xnone>>>>) -> !fir.ref<!fir.box<none>>
-! CHECK: %[[CONV_RP:.*]] = fir.convert %[[COORD_RP]] : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>) -> !fir.box<none>
-! CHECK: %{{.*}} = fir.call @_FortranAPointerAssociate(%[[CONV_P]], %[[CONV_RP]]) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>) -> none
+! CHECK: %[[RP_BOX_NONE:.*]] = fir.convert %[[REBOX_RP]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
+! CHECK: %{{.*}} = fir.call @_FortranAPointerAssociate(%[[CONV_P]], %[[RP_BOX_NONE]]) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>) -> none
! CHECK: return
! Test that the fir.dispatch operation is created with the correct pass object
More information about the flang-commits
mailing list