[NFC][flang] Lowering options clean-up.
authorSlava Zakharin <szakharin@nvidia.com>
Tue, 1 Nov 2022 22:12:43 +0000 (15:12 -0700)
committerSlava Zakharin <szakharin@nvidia.com>
Thu, 3 Nov 2022 04:10:22 +0000 (21:10 -0700)
This change-set defines the LoweringOptions the same way
other options are defined in Flang.

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

flang/include/flang/Lower/LoweringOptions.def [new file with mode: 0644]
flang/include/flang/Lower/LoweringOptions.h
flang/lib/Lower/CMakeLists.txt
flang/lib/Lower/CallInterface.cpp
flang/lib/Lower/ConvertType.cpp
flang/lib/Lower/LoweringOptions.cpp [new file with mode: 0644]
flang/unittests/Frontend/CMakeLists.txt

diff --git a/flang/include/flang/Lower/LoweringOptions.def b/flang/include/flang/Lower/LoweringOptions.def
new file mode 100644 (file)
index 0000000..2a89308
--- /dev/null
@@ -0,0 +1,35 @@
+//===--- LoweringOptions.def - Lowering options database ---------- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file defines the lowering options. Users of this file must define
+/// LOWERINGOPT macro to make use of this information.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LOWERINGOPT
+#  error Define the LOWERINGOPT macro to handle lowering options
+#endif
+
+#ifndef ENUM_LOWERINGOPT
+#  define ENUM_LOWERINGOPT(Name, Type, Bits, Default) \
+LOWERINGOPT(Name, Bits, Default)
+#endif
+
+/// If true, lower transpose without a runtime call.
+ENUM_LOWERINGOPT(OptimizeTranspose, unsigned, 1, 1)
+
+/// If true, enable polymorphic type lowering feature. Off by default.
+ENUM_LOWERINGOPT(PolymorphicTypeImpl, unsigned, 1, 0)
+
+/// If true, lower to High level FIR before lowering to FIR.
+/// Off by default until fully ready.
+ENUM_LOWERINGOPT(LowerToHighLevelFIR, unsigned, 1, 0)
+
+#undef LOWERINGOPT
+#undef ENUM_LOWERINGOPT
index d882ff0..dd297e4 100644 (file)
 
 namespace Fortran::lower {
 
-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;
+class LoweringOptionsBase {
+public:
+#define LOWERINGOPT(Name, Bits, Default) unsigned Name : Bits;
+#define ENUM_LOWERINGOPT(Name, Type, Bits, Default)
+#include "flang/Lower/LoweringOptions.def"
+
+protected:
+#define LOWERINGOPT(Name, Bits, Default)
+#define ENUM_LOWERINGOPT(Name, Type, Bits, Default) unsigned Name : Bits;
+#include "flang/Lower/LoweringOptions.def"
+};
 
-  /// If true, lower to High level FIR before lowering to FIR.
-  /// Off by default until fully ready.
-  unsigned lowerToHighLevelFIR : 1;
+class LoweringOptions : public LoweringOptionsBase {
 
 public:
-  LoweringOptions()
-      : optimizeTranspose(true), polymorphicTypeImpl(false),
-        lowerToHighLevelFIR(false) {}
-
-  bool getOptimizeTranspose() const { return optimizeTranspose; }
-  LoweringOptions &setOptimizeTranspose(bool v) {
-    optimizeTranspose = v;
-    return *this;
+#define LOWERINGOPT(Name, Bits, Default)
+#define ENUM_LOWERINGOPT(Name, Type, Bits, Default)                            \
+  Type get##Name() const { return static_cast<Type>(Name); }                   \
+  LoweringOptions &set##Name(Type Value) {                                     \
+    Name = static_cast<unsigned>(Value);                                       \
+    return *this;                                                              \
   }
+#include "flang/Lower/LoweringOptions.def"
 
-  bool isPolymorphicTypeImplEnabled() const { return polymorphicTypeImpl; }
-  LoweringOptions &setPolymorphicTypeImpl(bool v) {
-    polymorphicTypeImpl = v;
-    return *this;
-  }
-
-  bool getLowerToHighLevelFIR() const { return lowerToHighLevelFIR; }
-  LoweringOptions &setLowerToHighLevelFIR(bool v) {
-    lowerToHighLevelFIR = v;
-    return *this;
-  }
+  LoweringOptions();
 };
 
 } // namespace Fortran::lower
index cfc2e28..183bf64 100644 (file)
@@ -17,6 +17,7 @@ add_flang_library(FortranLower
   IntrinsicCall.cpp
   IO.cpp
   IterationSpace.cpp
+  LoweringOptions.cpp
   Mangler.cpp
   OpenACC.cpp
   OpenMP.cpp
index 190c561..20258f3 100644 (file)
@@ -829,7 +829,7 @@ private:
     if (cat == Fortran::common::TypeCategory::Derived) {
       // TODO is kept under experimental flag until feature is complete.
       if (dynamicType.IsPolymorphic() &&
-          !getConverter().getLoweringOptions().isPolymorphicTypeImplEnabled())
+          !getConverter().getLoweringOptions().getPolymorphicTypeImpl())
         TODO(interface.converter.getCurrentLocation(),
              "support for polymorphic types");
 
index 1d838df..e9a2e33 100644 (file)
@@ -234,8 +234,7 @@ struct TypeBuilder {
         translateLenParameters(params, tySpec->category(), ultimate);
         ty = genFIRType(context, tySpec->category(), kind, params);
       } else if (type->IsPolymorphic() &&
-                 !converter.getLoweringOptions()
-                      .isPolymorphicTypeImplEnabled()) {
+                 !converter.getLoweringOptions().getPolymorphicTypeImpl()) {
         // TODO is kept under experimental flag until feature is complete.
         TODO(loc, "support for polymorphic types");
       } else if (type->IsUnlimitedPolymorphic()) {
diff --git a/flang/lib/Lower/LoweringOptions.cpp b/flang/lib/Lower/LoweringOptions.cpp
new file mode 100644 (file)
index 0000000..22247fa
--- /dev/null
@@ -0,0 +1,23 @@
+//===--- LoweringOptions.cpp ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang/Lower/LoweringOptions.h"
+
+namespace Fortran::lower {
+
+LoweringOptions::LoweringOptions() {
+#define LOWERINGOPT(Name, Bits, Default) Name = Default;
+#define ENUM_LOWERINGOPT(Name, Type, Bits, Default) set##Name(Default);
+#include "flang/Lower/LoweringOptions.def"
+}
+
+} // namespace Fortran::lower
index 739412c..0a05b3f 100644 (file)
@@ -12,6 +12,7 @@ target_link_libraries(FlangFrontendTests
   clangBasic
   flangFrontend
   flangFrontendTool
+  FortranLower
   FortranParser
   FortranSemantics
   FortranCommon