[flang-commits] [flang] [flang][Frontend] Move LangOptions from Frontend to Common (PR #110012)
Krzysztof Parzyszek via flang-commits
flang-commits at lists.llvm.org
Wed Sep 25 09:54:25 PDT 2024
https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/110012
>From 027a0602fc3fc547ba89dd71b2c59304119f3bb5 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Tue, 24 Sep 2024 11:09:06 -0500
Subject: [PATCH 1/2] [flang][Frontend] Move LangOptions from Frontend to
Common
The information in LangOptions is not tied to any frontend code,
and could be used by any other component.
---
.../flang/{Frontend => Common}/LangOptions.def | 0
.../flang/{Frontend => Common}/LangOptions.h | 16 ++++++++--------
.../include/flang/Frontend/CompilerInvocation.h | 8 ++++----
flang/include/flang/Tools/CrossToolHelpers.h | 4 ++--
flang/lib/Common/CMakeLists.txt | 1 +
flang/lib/{Frontend => Common}/LangOptions.cpp | 8 ++++----
flang/lib/Frontend/CMakeLists.txt | 1 -
flang/lib/Frontend/CompilerInvocation.cpp | 16 ++++++++--------
8 files changed, 27 insertions(+), 27 deletions(-)
rename flang/include/flang/{Frontend => Common}/LangOptions.def (100%)
rename flang/include/flang/{Frontend => Common}/LangOptions.h (86%)
rename flang/lib/{Frontend => Common}/LangOptions.cpp (82%)
diff --git a/flang/include/flang/Frontend/LangOptions.def b/flang/include/flang/Common/LangOptions.def
similarity index 100%
rename from flang/include/flang/Frontend/LangOptions.def
rename to flang/include/flang/Common/LangOptions.def
diff --git a/flang/include/flang/Frontend/LangOptions.h b/flang/include/flang/Common/LangOptions.h
similarity index 86%
rename from flang/include/flang/Frontend/LangOptions.h
rename to flang/include/flang/Common/LangOptions.h
index 57d86d46df5ab1..c75229ae7f7c2a 100644
--- a/flang/include/flang/Frontend/LangOptions.h
+++ b/flang/include/flang/Common/LangOptions.h
@@ -12,15 +12,15 @@
//
//===----------------------------------------------------------------------===//
-#ifndef FORTRAN_FRONTEND_LANGOPTIONS_H
-#define FORTRAN_FRONTEND_LANGOPTIONS_H
+#ifndef FORTRAN_COMMON_LANGOPTIONS_H
+#define FORTRAN_COMMON_LANGOPTIONS_H
#include <string>
#include <vector>
#include "llvm/TargetParser/Triple.h"
-namespace Fortran::frontend {
+namespace Fortran::common {
/// Bitfields of LangOptions, split out from LangOptions to ensure
/// that this large collection of bitfields is a trivial class type.
@@ -37,12 +37,12 @@ class LangOptionsBase {
#define LANGOPT(Name, Bits, Default) unsigned Name : Bits;
#define ENUM_LANGOPT(Name, Type, Bits, Default)
-#include "flang/Frontend/LangOptions.def"
+#include "flang/Common/LangOptions.def"
protected:
#define LANGOPT(Name, Bits, Default)
#define ENUM_LANGOPT(Name, Type, Bits, Default) unsigned Name : Bits;
-#include "flang/Frontend/LangOptions.def"
+#include "flang/Common/LangOptions.def"
};
/// Tracks various options which control the dialect of Fortran that is
@@ -55,7 +55,7 @@ class LangOptions : public LangOptionsBase {
#define ENUM_LANGOPT(Name, Type, Bits, Default) \
Type get##Name() const { return static_cast<Type>(Name); } \
void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
-#include "flang/Frontend/LangOptions.def"
+#include "flang/Common/LangOptions.def"
/// Name of the IR file that contains the result of the OpenMP target
/// host code generation.
@@ -67,6 +67,6 @@ class LangOptions : public LangOptionsBase {
LangOptions();
};
-} // end namespace Fortran::frontend
+} // end namespace Fortran::common
-#endif // FORTRAN_FRONTEND_LANGOPTIONS_H
+#endif // FORTRAN_COMMON_LANGOPTIONS_H
diff --git a/flang/include/flang/Frontend/CompilerInvocation.h b/flang/include/flang/Frontend/CompilerInvocation.h
index d1646f585cf850..50d908d0832024 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -13,9 +13,9 @@
#ifndef FORTRAN_FRONTEND_COMPILERINVOCATION_H
#define FORTRAN_FRONTEND_COMPILERINVOCATION_H
+#include "flang/Common/LangOptions.h"
#include "flang/Frontend/CodeGenOptions.h"
#include "flang/Frontend/FrontendOptions.h"
-#include "flang/Frontend/LangOptions.h"
#include "flang/Frontend/PreprocessorOptions.h"
#include "flang/Frontend/TargetOptions.h"
#include "flang/Lower/LoweringOptions.h"
@@ -84,7 +84,7 @@ class CompilerInvocation : public CompilerInvocationBase {
Fortran::frontend::CodeGenOptions codeGenOpts;
/// Options controlling language dialect.
- Fortran::frontend::LangOptions langOpts;
+ Fortran::common::LangOptions langOpts;
// The original invocation of the compiler driver.
// This string will be set as the return value from the COMPILER_OPTIONS
@@ -158,8 +158,8 @@ class CompilerInvocation : public CompilerInvocationBase {
CodeGenOptions &getCodeGenOpts() { return codeGenOpts; }
const CodeGenOptions &getCodeGenOpts() const { return codeGenOpts; }
- LangOptions &getLangOpts() { return langOpts; }
- const LangOptions &getLangOpts() const { return langOpts; }
+ Fortran::common::LangOptions &getLangOpts() { return langOpts; }
+ const Fortran::common::LangOptions &getLangOpts() const { return langOpts; }
Fortran::lower::LoweringOptions &getLoweringOpts() { return loweringOpts; }
const Fortran::lower::LoweringOptions &getLoweringOpts() const {
diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h
index 75fd783af237d0..3e703de545950c 100644
--- a/flang/include/flang/Tools/CrossToolHelpers.h
+++ b/flang/include/flang/Tools/CrossToolHelpers.h
@@ -13,9 +13,9 @@
#ifndef FORTRAN_TOOLS_CROSS_TOOL_HELPERS_H
#define FORTRAN_TOOLS_CROSS_TOOL_HELPERS_H
+#include "flang/Common/LangOptions.h"
#include "flang/Common/MathOptionsBase.h"
#include "flang/Frontend/CodeGenOptions.h"
-#include "flang/Frontend/LangOptions.h"
#include <cstdint>
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
@@ -145,7 +145,7 @@ struct OffloadModuleOpts {
OMPTargetTriples(OMPTargetTriples.begin(), OMPTargetTriples.end()),
NoGPULib(NoGPULib) {}
- OffloadModuleOpts(Fortran::frontend::LangOptions &Opts)
+ OffloadModuleOpts(Fortran::common::LangOptions &Opts)
: OpenMPTargetDebug(Opts.OpenMPTargetDebug),
OpenMPTeamSubscription(Opts.OpenMPTeamSubscription),
OpenMPThreadSubscription(Opts.OpenMPThreadSubscription),
diff --git a/flang/lib/Common/CMakeLists.txt b/flang/lib/Common/CMakeLists.txt
index c6f818ad27cd19..54eb1de8614d50 100644
--- a/flang/lib/Common/CMakeLists.txt
+++ b/flang/lib/Common/CMakeLists.txt
@@ -40,6 +40,7 @@ add_flang_library(FortranCommon
Fortran-features.cpp
default-kinds.cpp
idioms.cpp
+ LangOptions.cpp
Version.cpp
${version_inc}
diff --git a/flang/lib/Frontend/LangOptions.cpp b/flang/lib/Common/LangOptions.cpp
similarity index 82%
rename from flang/lib/Frontend/LangOptions.cpp
rename to flang/lib/Common/LangOptions.cpp
index a08cb363384c6f..415c715156e7bf 100644
--- a/flang/lib/Frontend/LangOptions.cpp
+++ b/flang/lib/Common/LangOptions.cpp
@@ -10,15 +10,15 @@
//
//===----------------------------------------------------------------------===//
-#include "flang/Frontend/LangOptions.h"
+#include "flang/Common/LangOptions.h"
#include <string.h>
-namespace Fortran::frontend {
+namespace Fortran::common {
LangOptions::LangOptions() {
#define LANGOPT(Name, Bits, Default) Name = Default;
#define ENUM_LANGOPT(Name, Type, Bits, Default) set##Name(Default);
-#include "flang/Frontend/LangOptions.def"
+#include "flang/Common/LangOptions.def"
}
-} // end namespace Fortran::frontend
+} // end namespace Fortran::common
diff --git a/flang/lib/Frontend/CMakeLists.txt b/flang/lib/Frontend/CMakeLists.txt
index ecdcc73d61ec1f..875481a567ac92 100644
--- a/flang/lib/Frontend/CMakeLists.txt
+++ b/flang/lib/Frontend/CMakeLists.txt
@@ -8,7 +8,6 @@ add_flang_library(flangFrontend
FrontendAction.cpp
FrontendActions.cpp
FrontendOptions.cpp
- LangOptions.cpp
TextDiagnosticPrinter.cpp
TextDiagnosticBuffer.cpp
TextDiagnostic.cpp
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 90c327546198b5..52ca9f61c56f74 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -1110,17 +1110,17 @@ static bool parseOpenMPArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
static bool parseFloatingPointArgs(CompilerInvocation &invoc,
llvm::opt::ArgList &args,
clang::DiagnosticsEngine &diags) {
- LangOptions &opts = invoc.getLangOpts();
+ Fortran::common::LangOptions &opts = invoc.getLangOpts();
if (const llvm::opt::Arg *a =
args.getLastArg(clang::driver::options::OPT_ffp_contract)) {
const llvm::StringRef val = a->getValue();
- enum LangOptions::FPModeKind fpContractMode;
+ enum Fortran::common::LangOptions::FPModeKind fpContractMode;
if (val == "off")
- fpContractMode = LangOptions::FPM_Off;
+ fpContractMode = Fortran::common::LangOptions::FPM_Off;
else if (val == "fast")
- fpContractMode = LangOptions::FPM_Fast;
+ fpContractMode = Fortran::common::LangOptions::FPM_Fast;
else {
diags.Report(clang::diag::err_drv_unsupported_option_argument)
<< a->getSpelling() << val;
@@ -1161,7 +1161,7 @@ static bool parseFloatingPointArgs(CompilerInvocation &invoc,
opts.ReciprocalMath = true;
opts.ApproxFunc = true;
opts.NoSignedZeros = true;
- opts.setFPContractMode(LangOptions::FPM_Fast);
+ opts.setFPContractMode(Fortran::common::LangOptions::FPM_Fast);
}
return true;
@@ -1194,7 +1194,7 @@ static bool parseVScaleArgs(CompilerInvocation &invoc, llvm::opt::ArgList &args,
return false;
}
- LangOptions &opts = invoc.getLangOpts();
+ Fortran::common::LangOptions &opts = invoc.getLangOpts();
if (vscaleMin) {
llvm::StringRef argValue = llvm::StringRef(vscaleMin->getValue());
unsigned vscaleMinVal;
@@ -1556,14 +1556,14 @@ void CompilerInvocation::setLoweringOptions() {
loweringOpts.setOptimizeTranspose(codegenOpts.OptimizationLevel > 0);
loweringOpts.setUnderscoring(codegenOpts.Underscoring);
- const LangOptions &langOptions = getLangOpts();
+ const Fortran::common::LangOptions &langOptions = getLangOpts();
Fortran::common::MathOptionsBase &mathOpts = loweringOpts.getMathOptions();
// TODO: when LangOptions are finalized, we can represent
// the math related options using Fortran::commmon::MathOptionsBase,
// so that we can just copy it into LoweringOptions.
mathOpts
.setFPContractEnabled(langOptions.getFPContractMode() ==
- LangOptions::FPM_Fast)
+ Fortran::common::LangOptions::FPM_Fast)
.setNoHonorInfs(langOptions.NoHonorInfs)
.setNoHonorNaNs(langOptions.NoHonorNaNs)
.setApproxFunc(langOptions.ApproxFunc)
>From 9ef3cf4bb1d146549b8a1a4d9dfe4bae07aafd84 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Wed, 25 Sep 2024 11:53:43 -0500
Subject: [PATCH 2/2] clang-format
---
flang/include/flang/Common/LangOptions.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/flang/include/flang/Common/LangOptions.h b/flang/include/flang/Common/LangOptions.h
index c75229ae7f7c2a..52a45047deb0e2 100644
--- a/flang/include/flang/Common/LangOptions.h
+++ b/flang/include/flang/Common/LangOptions.h
@@ -52,8 +52,8 @@ class LangOptions : public LangOptionsBase {
public:
// Define accessors/mutators for code generation options of enumeration type.
#define LANGOPT(Name, Bits, Default)
-#define ENUM_LANGOPT(Name, Type, Bits, Default) \
- Type get##Name() const { return static_cast<Type>(Name); } \
+#define ENUM_LANGOPT(Name, Type, Bits, Default) \
+ Type get##Name() const { return static_cast<Type>(Name); } \
void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
#include "flang/Common/LangOptions.def"
More information about the flang-commits
mailing list