Skip to content

Commit 5a85526

Browse files
committed
[clang] Use enum for LangOptions::SYCLVersion instead of unsigned
`LangOptions::SYCLVersion` can only have two values. This patch introduces an enum that allows us to reduce the member size from 32 bits to 1 bit. Consequently, this also makes marshalling of this option fit into our model for enums: D84674. Reviewed By: bader Differential Revision: https://reviews.llvm.org/D93540
1 parent 70410a2 commit 5a85526

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ LANGOPT(GPUExcludeWrongSideOverloads, 1, 0, "always exclude wrong side overloads
246246

247247
LANGOPT(SYCL , 1, 0, "SYCL")
248248
LANGOPT(SYCLIsDevice , 1, 0, "Generate code for SYCL device")
249-
LANGOPT(SYCLVersion , 32, 0, "Version of the SYCL standard used")
249+
ENUM_LANGOPT(SYCLVersion , SYCLMajorVersion, 1, SYCL_None, "Version of the SYCL standard used")
250250

251251
LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP")
252252

clang/include/clang/Basic/LangOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ class LangOptions : public LangOptionsBase {
125125
MSVC2019 = 1920,
126126
};
127127

128+
enum SYCLMajorVersion {
129+
SYCL_None,
130+
SYCL_2017,
131+
};
132+
128133
/// Clang versions with different platform ABI conformance.
129134
enum class ClangABI {
130135
/// Attempt to be ABI-compatible with code generated by Clang 3.8.x

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,11 +2277,13 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
22772277
// -sycl-std applies to any SYCL source, not only those containing kernels,
22782278
// but also those using the SYCL API
22792279
if (const Arg *A = Args.getLastArg(OPT_sycl_std_EQ)) {
2280-
Opts.SYCLVersion = llvm::StringSwitch<unsigned>(A->getValue())
2281-
.Cases("2017", "1.2.1", "121", "sycl-1.2.1", 2017)
2282-
.Default(0U);
2280+
Opts.setSYCLVersion(
2281+
llvm::StringSwitch<LangOptions::SYCLMajorVersion>(A->getValue())
2282+
.Cases("2017", "1.2.1", "121", "sycl-1.2.1",
2283+
LangOptions::SYCL_2017)
2284+
.Default(LangOptions::SYCL_None));
22832285

2284-
if (Opts.SYCLVersion == 0U) {
2286+
if (Opts.getSYCLVersion() == LangOptions::SYCL_None) {
22852287
// User has passed an invalid value to the flag, this is an error
22862288
Diags.Report(diag::err_drv_invalid_value)
22872289
<< A->getAsString(Args) << A->getValue();

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
476476

477477
if (LangOpts.SYCL) {
478478
// SYCL Version is set to a value when building SYCL applications
479-
if (LangOpts.SYCLVersion == 2017)
479+
if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2017)
480480
Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121");
481481
}
482482

0 commit comments

Comments
 (0)