Skip to content

Commit 7dd0d13

Browse files
kparzyszSterling-Augustine
authored andcommitted
[flang][Frontend] Move LangOptions from Frontend to Common (llvm#110012)
The information in LangOptions is not tied to any frontend code, and could be used by any other component.
1 parent 668caaa commit 7dd0d13

File tree

8 files changed

+29
-29
lines changed

8 files changed

+29
-29
lines changed

flang/include/flang/Frontend/LangOptions.h renamed to flang/include/flang/Common/LangOptions.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#ifndef FORTRAN_FRONTEND_LANGOPTIONS_H
16-
#define FORTRAN_FRONTEND_LANGOPTIONS_H
15+
#ifndef FORTRAN_COMMON_LANGOPTIONS_H
16+
#define FORTRAN_COMMON_LANGOPTIONS_H
1717

1818
#include <string>
1919
#include <vector>
2020

2121
#include "llvm/TargetParser/Triple.h"
2222

23-
namespace Fortran::frontend {
23+
namespace Fortran::common {
2424

2525
/// Bitfields of LangOptions, split out from LangOptions to ensure
2626
/// that this large collection of bitfields is a trivial class type.
@@ -37,12 +37,12 @@ class LangOptionsBase {
3737

3838
#define LANGOPT(Name, Bits, Default) unsigned Name : Bits;
3939
#define ENUM_LANGOPT(Name, Type, Bits, Default)
40-
#include "flang/Frontend/LangOptions.def"
40+
#include "flang/Common/LangOptions.def"
4141

4242
protected:
4343
#define LANGOPT(Name, Bits, Default)
4444
#define ENUM_LANGOPT(Name, Type, Bits, Default) unsigned Name : Bits;
45-
#include "flang/Frontend/LangOptions.def"
45+
#include "flang/Common/LangOptions.def"
4646
};
4747

4848
/// Tracks various options which control the dialect of Fortran that is
@@ -52,10 +52,10 @@ class LangOptions : public LangOptionsBase {
5252
public:
5353
// Define accessors/mutators for code generation options of enumeration type.
5454
#define LANGOPT(Name, Bits, Default)
55-
#define ENUM_LANGOPT(Name, Type, Bits, Default) \
56-
Type get##Name() const { return static_cast<Type>(Name); } \
55+
#define ENUM_LANGOPT(Name, Type, Bits, Default) \
56+
Type get##Name() const { return static_cast<Type>(Name); } \
5757
void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
58-
#include "flang/Frontend/LangOptions.def"
58+
#include "flang/Common/LangOptions.def"
5959

6060
/// Name of the IR file that contains the result of the OpenMP target
6161
/// host code generation.
@@ -67,6 +67,6 @@ class LangOptions : public LangOptionsBase {
6767
LangOptions();
6868
};
6969

70-
} // end namespace Fortran::frontend
70+
} // end namespace Fortran::common
7171

72-
#endif // FORTRAN_FRONTEND_LANGOPTIONS_H
72+
#endif // FORTRAN_COMMON_LANGOPTIONS_H

flang/include/flang/Frontend/CompilerInvocation.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#ifndef FORTRAN_FRONTEND_COMPILERINVOCATION_H
1414
#define FORTRAN_FRONTEND_COMPILERINVOCATION_H
1515

16+
#include "flang/Common/LangOptions.h"
1617
#include "flang/Frontend/CodeGenOptions.h"
1718
#include "flang/Frontend/FrontendOptions.h"
18-
#include "flang/Frontend/LangOptions.h"
1919
#include "flang/Frontend/PreprocessorOptions.h"
2020
#include "flang/Frontend/TargetOptions.h"
2121
#include "flang/Lower/LoweringOptions.h"
@@ -84,7 +84,7 @@ class CompilerInvocation : public CompilerInvocationBase {
8484
Fortran::frontend::CodeGenOptions codeGenOpts;
8585

8686
/// Options controlling language dialect.
87-
Fortran::frontend::LangOptions langOpts;
87+
Fortran::common::LangOptions langOpts;
8888

8989
// The original invocation of the compiler driver.
9090
// This string will be set as the return value from the COMPILER_OPTIONS
@@ -158,8 +158,8 @@ class CompilerInvocation : public CompilerInvocationBase {
158158
CodeGenOptions &getCodeGenOpts() { return codeGenOpts; }
159159
const CodeGenOptions &getCodeGenOpts() const { return codeGenOpts; }
160160

161-
LangOptions &getLangOpts() { return langOpts; }
162-
const LangOptions &getLangOpts() const { return langOpts; }
161+
Fortran::common::LangOptions &getLangOpts() { return langOpts; }
162+
const Fortran::common::LangOptions &getLangOpts() const { return langOpts; }
163163

164164
Fortran::lower::LoweringOptions &getLoweringOpts() { return loweringOpts; }
165165
const Fortran::lower::LoweringOptions &getLoweringOpts() const {

flang/include/flang/Tools/CrossToolHelpers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#ifndef FORTRAN_TOOLS_CROSS_TOOL_HELPERS_H
1414
#define FORTRAN_TOOLS_CROSS_TOOL_HELPERS_H
1515

16+
#include "flang/Common/LangOptions.h"
1617
#include "flang/Common/MathOptionsBase.h"
1718
#include "flang/Frontend/CodeGenOptions.h"
18-
#include "flang/Frontend/LangOptions.h"
1919
#include <cstdint>
2020

2121
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
@@ -145,7 +145,7 @@ struct OffloadModuleOpts {
145145
OMPTargetTriples(OMPTargetTriples.begin(), OMPTargetTriples.end()),
146146
NoGPULib(NoGPULib) {}
147147

148-
OffloadModuleOpts(Fortran::frontend::LangOptions &Opts)
148+
OffloadModuleOpts(Fortran::common::LangOptions &Opts)
149149
: OpenMPTargetDebug(Opts.OpenMPTargetDebug),
150150
OpenMPTeamSubscription(Opts.OpenMPTeamSubscription),
151151
OpenMPThreadSubscription(Opts.OpenMPThreadSubscription),

flang/lib/Common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ add_flang_library(FortranCommon
3939
Fortran-features.cpp
4040
default-kinds.cpp
4141
idioms.cpp
42+
LangOptions.cpp
4243
Version.cpp
4344
${version_inc}
4445

flang/lib/Frontend/LangOptions.cpp renamed to flang/lib/Common/LangOptions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "flang/Frontend/LangOptions.h"
13+
#include "flang/Common/LangOptions.h"
1414
#include <string.h>
1515

16-
namespace Fortran::frontend {
16+
namespace Fortran::common {
1717

1818
LangOptions::LangOptions() {
1919
#define LANGOPT(Name, Bits, Default) Name = Default;
2020
#define ENUM_LANGOPT(Name, Type, Bits, Default) set##Name(Default);
21-
#include "flang/Frontend/LangOptions.def"
21+
#include "flang/Common/LangOptions.def"
2222
}
2323

24-
} // end namespace Fortran::frontend
24+
} // end namespace Fortran::common

flang/lib/Frontend/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ add_flang_library(flangFrontend
88
FrontendAction.cpp
99
FrontendActions.cpp
1010
FrontendOptions.cpp
11-
LangOptions.cpp
1211
TextDiagnosticPrinter.cpp
1312
TextDiagnosticBuffer.cpp
1413
TextDiagnostic.cpp

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,17 +1110,17 @@ static bool parseOpenMPArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
11101110
static bool parseFloatingPointArgs(CompilerInvocation &invoc,
11111111
llvm::opt::ArgList &args,
11121112
clang::DiagnosticsEngine &diags) {
1113-
LangOptions &opts = invoc.getLangOpts();
1113+
Fortran::common::LangOptions &opts = invoc.getLangOpts();
11141114

11151115
if (const llvm::opt::Arg *a =
11161116
args.getLastArg(clang::driver::options::OPT_ffp_contract)) {
11171117
const llvm::StringRef val = a->getValue();
1118-
enum LangOptions::FPModeKind fpContractMode;
1118+
enum Fortran::common::LangOptions::FPModeKind fpContractMode;
11191119

11201120
if (val == "off")
1121-
fpContractMode = LangOptions::FPM_Off;
1121+
fpContractMode = Fortran::common::LangOptions::FPM_Off;
11221122
else if (val == "fast")
1123-
fpContractMode = LangOptions::FPM_Fast;
1123+
fpContractMode = Fortran::common::LangOptions::FPM_Fast;
11241124
else {
11251125
diags.Report(clang::diag::err_drv_unsupported_option_argument)
11261126
<< a->getSpelling() << val;
@@ -1161,7 +1161,7 @@ static bool parseFloatingPointArgs(CompilerInvocation &invoc,
11611161
opts.ReciprocalMath = true;
11621162
opts.ApproxFunc = true;
11631163
opts.NoSignedZeros = true;
1164-
opts.setFPContractMode(LangOptions::FPM_Fast);
1164+
opts.setFPContractMode(Fortran::common::LangOptions::FPM_Fast);
11651165
}
11661166

11671167
return true;
@@ -1194,7 +1194,7 @@ static bool parseVScaleArgs(CompilerInvocation &invoc, llvm::opt::ArgList &args,
11941194
return false;
11951195
}
11961196

1197-
LangOptions &opts = invoc.getLangOpts();
1197+
Fortran::common::LangOptions &opts = invoc.getLangOpts();
11981198
if (vscaleMin) {
11991199
llvm::StringRef argValue = llvm::StringRef(vscaleMin->getValue());
12001200
unsigned vscaleMinVal;
@@ -1556,14 +1556,14 @@ void CompilerInvocation::setLoweringOptions() {
15561556
loweringOpts.setOptimizeTranspose(codegenOpts.OptimizationLevel > 0);
15571557
loweringOpts.setUnderscoring(codegenOpts.Underscoring);
15581558

1559-
const LangOptions &langOptions = getLangOpts();
1559+
const Fortran::common::LangOptions &langOptions = getLangOpts();
15601560
Fortran::common::MathOptionsBase &mathOpts = loweringOpts.getMathOptions();
15611561
// TODO: when LangOptions are finalized, we can represent
15621562
// the math related options using Fortran::commmon::MathOptionsBase,
15631563
// so that we can just copy it into LoweringOptions.
15641564
mathOpts
15651565
.setFPContractEnabled(langOptions.getFPContractMode() ==
1566-
LangOptions::FPM_Fast)
1566+
Fortran::common::LangOptions::FPM_Fast)
15671567
.setNoHonorInfs(langOptions.NoHonorInfs)
15681568
.setNoHonorNaNs(langOptions.NoHonorNaNs)
15691569
.setApproxFunc(langOptions.ApproxFunc)

0 commit comments

Comments
 (0)