Index: flang/include/flang/Lower/LoweringOptions.h =================================================================== --- flang/include/flang/Lower/LoweringOptions.h +++ flang/include/flang/Lower/LoweringOptions.h @@ -17,39 +17,31 @@ 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(Name); } \ + LoweringOptions &set##Name(Type Value) { \ + Name = static_cast(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: flang/include/flang/Lower/LoweringOptions.def =================================================================== --- /dev/null +++ flang/include/flang/Lower/LoweringOptions.def @@ -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: flang/lib/Lower/CMakeLists.txt =================================================================== --- flang/lib/Lower/CMakeLists.txt +++ flang/lib/Lower/CMakeLists.txt @@ -17,6 +17,7 @@ IntrinsicCall.cpp IO.cpp IterationSpace.cpp + LoweringOptions.cpp Mangler.cpp OpenACC.cpp OpenMP.cpp Index: flang/lib/Lower/CallInterface.cpp =================================================================== --- flang/lib/Lower/CallInterface.cpp +++ flang/lib/Lower/CallInterface.cpp @@ -829,7 +829,7 @@ 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: flang/lib/Lower/ConvertType.cpp =================================================================== --- flang/lib/Lower/ConvertType.cpp +++ flang/lib/Lower/ConvertType.cpp @@ -234,8 +234,7 @@ 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()) { Index: flang/lib/Lower/LoweringOptions.cpp =================================================================== --- /dev/null +++ flang/lib/Lower/LoweringOptions.cpp @@ -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: flang/unittests/Frontend/CMakeLists.txt =================================================================== --- flang/unittests/Frontend/CMakeLists.txt +++ flang/unittests/Frontend/CMakeLists.txt @@ -12,6 +12,7 @@ clangBasic flangFrontend flangFrontendTool + FortranLower FortranParser FortranSemantics FortranCommon