[flang] Keep current polymorphic implementation under a flag
authorValentin Clement <clementval@gmail.com>
Wed, 5 Oct 2022 21:04:59 +0000 (23:04 +0200)
committerValentin Clement <clementval@gmail.com>
Wed, 5 Oct 2022 21:05:28 +0000 (23:05 +0200)
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

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

index 5b70e9e..5873656 100644 (file)
@@ -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
index 510cb60..d482859 100644 (file)
@@ -797,6 +797,12 @@ private:
     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());
index 2188f38..1d838df 100644 (file)
@@ -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 =
index bc4f34e..d0354f9 100644 (file)
@@ -1,4 +1,4 @@
-! RUN: bbc -emit-fir %s -o - | FileCheck %s
+! RUN: bbc -polymorphic-type -emit-fir %s -o - | FileCheck %s
 
 ! Tests the different possible type involving polymorphic entities. 
 
index ec778a4..5e84edd 100644 (file)
@@ -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(), "",