[flang-commits] [flang] 91dd872 - [flang] Keep current polymorphic implementation under a flag

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Wed Oct 5 14:05:38 PDT 2022


Author: Valentin Clement
Date: 2022-10-05T23:05:28+02:00
New Revision: 91dd872ea6cff9bf6d83285b9c36dba40d86d0dd

URL: https://github.com/llvm/llvm-project/commit/91dd872ea6cff9bf6d83285b9c36dba40d86d0dd
DIFF: https://github.com/llvm/llvm-project/commit/91dd872ea6cff9bf6d83285b9c36dba40d86d0dd.diff

LOG: [flang] Keep current polymorphic implementation under a flag

It is useful for couple of test suite like NAG to keep failing
with a TODO until the polymorphic entities is implemented  all the
way done to codegen.

This pass adds a flag to LoweringOptions for experimental development.
This flag is off by default and can be enable in `bbc` with `-polymorphic-type`.
Options can be added in the driver and tco when needed.

Reviewed By: PeteSteinfeld

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

Added: 
    

Modified: 
    flang/include/flang/Lower/LoweringOptions.h
    flang/lib/Lower/CallInterface.cpp
    flang/lib/Lower/ConvertType.cpp
    flang/test/Lower/polymorphic-types.f90
    flang/tools/bbc/bbc.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Lower/LoweringOptions.h b/flang/include/flang/Lower/LoweringOptions.h
index 5b70e9eabc18a..58736568362db 100644
--- a/flang/include/flang/Lower/LoweringOptions.h
+++ b/flang/include/flang/Lower/LoweringOptions.h
@@ -21,14 +21,23 @@ class LoweringOptions {
   /// If true, lower transpose without a runtime call.
   unsigned optimizeTranspose : 1;
 
+  /// If true, enable polymorphic type lowering feature. Off by default.
+  unsigned polymorphicTypeImpl : 1;
+
 public:
-  LoweringOptions() : optimizeTranspose(true) {}
+  LoweringOptions() : optimizeTranspose(true), polymorphicTypeImpl(false) {}
 
   bool getOptimizeTranspose() const { return optimizeTranspose; }
   LoweringOptions &setOptimizeTranspose(bool v) {
     optimizeTranspose = v;
     return *this;
   }
+
+  bool isPolymorphicTypeImplEnabled() const { return polymorphicTypeImpl; }
+  LoweringOptions &setPolymorphicTypeImpl(bool v) {
+    polymorphicTypeImpl = v;
+    return *this;
+  }
 };
 
 } // namespace Fortran::lower

diff  --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp
index 510cb6081ff7d..d48285993bb31 100644
--- a/flang/lib/Lower/CallInterface.cpp
+++ b/flang/lib/Lower/CallInterface.cpp
@@ -797,6 +797,12 @@ class Fortran::lower::CallInterfaceImpl {
     Fortran::common::TypeCategory cat = dynamicType.category();
     // DERIVED
     if (cat == Fortran::common::TypeCategory::Derived) {
+      // TODO is kept under experimental flag until feature is complete.
+      if (dynamicType.IsPolymorphic() &&
+          !getConverter().getLoweringOptions().isPolymorphicTypeImplEnabled())
+        TODO(interface.converter.getCurrentLocation(),
+             "support for polymorphic types");
+
       if (dynamicType.IsUnlimitedPolymorphic())
         return mlir::NoneType::get(&mlirContext);
       return getConverter().genType(dynamicType.GetDerivedTypeSpec());

diff  --git a/flang/lib/Lower/ConvertType.cpp b/flang/lib/Lower/ConvertType.cpp
index 2188f38afd6d5..1d838df2022a9 100644
--- a/flang/lib/Lower/ConvertType.cpp
+++ b/flang/lib/Lower/ConvertType.cpp
@@ -233,6 +233,11 @@ struct TypeBuilder {
         llvm::SmallVector<Fortran::lower::LenParameterTy> params;
         translateLenParameters(params, tySpec->category(), ultimate);
         ty = genFIRType(context, tySpec->category(), kind, params);
+      } else if (type->IsPolymorphic() &&
+                 !converter.getLoweringOptions()
+                      .isPolymorphicTypeImplEnabled()) {
+        // TODO is kept under experimental flag until feature is complete.
+        TODO(loc, "support for polymorphic types");
       } else if (type->IsUnlimitedPolymorphic()) {
         ty = mlir::NoneType::get(context);
       } else if (const Fortran::semantics::DerivedTypeSpec *tySpec =

diff  --git a/flang/test/Lower/polymorphic-types.f90 b/flang/test/Lower/polymorphic-types.f90
index bc4f34e300703..d0354f95ca4a5 100644
--- a/flang/test/Lower/polymorphic-types.f90
+++ b/flang/test/Lower/polymorphic-types.f90
@@ -1,4 +1,4 @@
-! RUN: bbc -emit-fir %s -o - | FileCheck %s
+! RUN: bbc -polymorphic-type -emit-fir %s -o - | FileCheck %s
 
 ! Tests the 
diff erent possible type involving polymorphic entities. 
 

diff  --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp
index ec778a423a6de..5e84edddb1b6f 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -126,6 +126,11 @@ static llvm::cl::opt<bool> enableOpenACC("fopenacc",
                                          llvm::cl::desc("enable openacc"),
                                          llvm::cl::init(false));
 
+static llvm::cl::opt<bool> enablePolymorphic(
+    "polymorphic-type",
+    llvm::cl::desc("enable polymorphic type lowering (experimental)"),
+    llvm::cl::init(false));
+
 #define FLANG_EXCLUDE_CODEGEN
 #include "flang/Tools/CLOptions.inc"
 
@@ -221,6 +226,7 @@ static mlir::LogicalResult convertFortranSourceToMLIR(
       &ctx, llvm::ArrayRef<fir::KindTy>{fir::fromDefaultKinds(defKinds)});
   // Use default lowering options for bbc.
   Fortran::lower::LoweringOptions loweringOptions{};
+  loweringOptions.setPolymorphicTypeImpl(enablePolymorphic);
   auto burnside = Fortran::lower::LoweringBridge::create(
       ctx, semanticsContext, defKinds, semanticsContext.intrinsics(),
       semanticsContext.targetCharacteristics(), parsing.allCooked(), "",


        


More information about the flang-commits mailing list