[flang-commits] [flang] 1e413b9 - [flang][NFC] Centralize fir.class addition in ConvertType

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Wed Feb 8 01:29:06 PST 2023


Author: Valentin Clement
Date: 2023-02-08T10:28:58+01:00
New Revision: 1e413b905545e738393a8c45acb79017d49927c4

URL: https://github.com/llvm/llvm-project/commit/1e413b905545e738393a8c45acb79017d49927c4
DIFF: https://github.com/llvm/llvm-project/commit/1e413b905545e738393a8c45acb79017d49927c4.diff

LOG: [flang][NFC] Centralize fir.class addition in ConvertType

fir.class type is always needed for polymorphic and unlimited
polymorphic entities. Wrapping the element type with a fir.class
type was done in ConvertType for some case and else where in the
code for other. Centralize this in ConvertType when converting
from expr or symbol.

Reviewed By: jeanPerier

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

Added: 
    

Modified: 
    flang/lib/Lower/ConvertType.cpp
    flang/lib/Lower/HostAssociations.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/ConvertType.cpp b/flang/lib/Lower/ConvertType.cpp
index e8d688a042d66..4fab5a5a493c6 100644
--- a/flang/lib/Lower/ConvertType.cpp
+++ b/flang/lib/Lower/ConvertType.cpp
@@ -143,6 +143,9 @@ struct TypeBuilderImpl {
     Fortran::common::TypeCategory category = dynamicType->category();
 
     mlir::Type baseType;
+    bool isPolymorphic = (dynamicType->IsPolymorphic() ||
+                          dynamicType->IsUnlimitedPolymorphic()) &&
+                         !dynamicType->IsAssumedType();
     if (dynamicType->IsUnlimitedPolymorphic()) {
       baseType = mlir::NoneType::get(context);
     } else if (category == Fortran::common::TypeCategory::Derived) {
@@ -167,8 +170,14 @@ struct TypeBuilderImpl {
       for (int dim = 0; dim < rank; ++dim)
         shape.emplace_back(fir::SequenceType::getUnknownExtent());
     }
-    if (!shape.empty())
+
+    if (!shape.empty()) {
+      if (isPolymorphic)
+        return fir::ClassType::get(fir::SequenceType::get(shape, baseType));
       return fir::SequenceType::get(shape, baseType);
+    }
+    if (isPolymorphic)
+      return fir::ClassType::get(baseType);
     return baseType;
   }
 
@@ -256,6 +265,9 @@ struct TypeBuilderImpl {
     } else {
       fir::emitFatalError(loc, "symbol must have a type");
     }
+    bool isPolymorphic = (Fortran::semantics::IsPolymorphic(symbol) ||
+                          Fortran::semantics::IsUnlimitedPolymorphic(symbol)) &&
+                         !Fortran::semantics::IsAssumedType(symbol);
     if (ultimate.IsObjectArray()) {
       auto shapeExpr = Fortran::evaluate::GetShapeHelper{
           converter.getFoldingContext()}(ultimate);
@@ -266,11 +278,10 @@ struct TypeBuilderImpl {
       ty = fir::SequenceType::get(shape, ty);
     }
     if (Fortran::semantics::IsPointer(symbol))
-      return fir::wrapInClassOrBoxType(
-          fir::PointerType::get(ty), Fortran::semantics::IsPolymorphic(symbol));
+      return fir::wrapInClassOrBoxType(fir::PointerType::get(ty),
+                                       isPolymorphic);
     if (Fortran::semantics::IsAllocatable(symbol))
-      return fir::wrapInClassOrBoxType(
-          fir::HeapType::get(ty), Fortran::semantics::IsPolymorphic(symbol));
+      return fir::wrapInClassOrBoxType(fir::HeapType::get(ty), isPolymorphic);
     // isPtr and isAlloc are variable that were promoted to be on the
     // heap or to be pointers, but they do not have Fortran allocatable
     // or pointer semantics, so do not use box for them.
@@ -278,6 +289,8 @@ struct TypeBuilderImpl {
       return fir::PointerType::get(ty);
     if (isAlloc)
       return fir::HeapType::get(ty);
+    if (isPolymorphic)
+      return fir::ClassType::get(ty);
     return ty;
   }
 

diff  --git a/flang/lib/Lower/HostAssociations.cpp b/flang/lib/Lower/HostAssociations.cpp
index b6c8ee00a4d27..4d8a120172eff 100644
--- a/flang/lib/Lower/HostAssociations.cpp
+++ b/flang/lib/Lower/HostAssociations.cpp
@@ -253,7 +253,7 @@ class CapturedPolymorphic : public CapturedSymbols<CapturedPolymorphic> {
 public:
   static mlir::Type getType(Fortran::lower::AbstractConverter &converter,
                             const Fortran::semantics::Symbol &sym) {
-    return fir::ClassType::get(converter.genType(sym));
+    return converter.genType(sym);
   }
   static void instantiateHostTuple(const InstantiateHostTuple &args,
                                    Fortran::lower::AbstractConverter &converter,


        


More information about the flang-commits mailing list