Skip to content

Commit

Permalink
[flang][Frontend] Move LangOptions from Frontend to Common
Browse files Browse the repository at this point in the history
  • Loading branch information
kparzysz committed Sep 25, 2024
1 parent 6d8995a commit cd9f0e1
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
8 changes: 4 additions & 4 deletions flang/include/flang/Frontend/CompilerInvocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions flang/include/flang/Tools/CrossToolHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ add_flang_library(FortranCommon
Fortran-features.cpp
default-kinds.cpp
idioms.cpp
LangOptions.cpp
Version.cpp
${version_inc}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion flang/lib/Frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ add_flang_library(flangFrontend
FrontendAction.cpp
FrontendActions.cpp
FrontendOptions.cpp
LangOptions.cpp
TextDiagnosticPrinter.cpp
TextDiagnosticBuffer.cpp
TextDiagnostic.cpp
Expand Down
16 changes: 8 additions & 8 deletions flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,17 +1138,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;
Expand Down Expand Up @@ -1189,7 +1189,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;
Expand Down Expand Up @@ -1222,7 +1222,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;
Expand Down Expand Up @@ -1584,14 +1584,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)
Expand Down

0 comments on commit cd9f0e1

Please sign in to comment.