Skip to content

Commit 6381664

Browse files
committed
Introduce SYCL 2020 mode
Currently, we have support for SYCL 1.2.1 (also known as SYCL 2017). This patch introduces the start of support for SYCL 2020 mode, which is the latest SYCL standard available at (https://www.khronos.org/registry/SYCL/specs/sycl-2020/html/sycl-2020.html). This sets the default SYCL to be 2020 in the driver, and introduces the notion of a "default" version (set to 2020) when cc1 is in SYCL mode but there was no explicit -sycl-std= specified on the command line.
1 parent ba1509d commit 6381664

File tree

9 files changed

+119
-8
lines changed

9 files changed

+119
-8
lines changed

clang/include/clang/Basic/LangOptions.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ LANGOPT(GPUExcludeWrongSideOverloads, 1, 0, "always exclude wrong side overloads
252252

253253
LANGOPT(SYCLIsDevice , 1, 0, "Generate code for SYCL device")
254254
LANGOPT(SYCLIsHost , 1, 0, "SYCL host compilation")
255-
ENUM_LANGOPT(SYCLVersion , SYCLMajorVersion, 1, SYCL_None, "Version of the SYCL standard used")
255+
ENUM_LANGOPT(SYCLVersion , SYCLMajorVersion, 2, SYCL_None, "Version of the SYCL standard used")
256256

257257
LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP")
258258

clang/include/clang/Basic/LangOptions.h

+4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ class LangOptions : public LangOptionsBase {
130130
enum SYCLMajorVersion {
131131
SYCL_None,
132132
SYCL_2017,
133+
SYCL_2020,
134+
// The "default" SYCL version to be used when none is specified on the
135+
// frontend command line.
136+
SYCL_Default = SYCL_2020
133137
};
134138

135139
/// Clang versions with different platform ABI conformance.

clang/include/clang/Driver/Options.td

+2-2
Original file line numberDiff line numberDiff line change
@@ -5691,8 +5691,8 @@ def fsycl_is_host : Flag<["-"], "fsycl-is-host">,
56915691
def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group<sycl_Group>,
56925692
Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
56935693
HelpText<"SYCL language standard to compile for.">,
5694-
Values<"2017,121,1.2.1,sycl-1.2.1">,
5695-
NormalizedValues<["SYCL_2017", "SYCL_2017", "SYCL_2017", "SYCL_2017"]>,
5694+
Values<"2020,2017,121,1.2.1,sycl-1.2.1">,
5695+
NormalizedValues<["SYCL_2020", "SYCL_2017", "SYCL_2017", "SYCL_2017", "SYCL_2017"]>,
56965696
NormalizedValuesScope<"LangOptions">,
56975697
MarshallingInfoEnum<LangOpts<"SYCLVersion">, "SYCL_None">,
56985698
ShouldParseIf<!strconcat(fsycl_is_device.KeyPath, "||", fsycl_is_host.KeyPath)>;

clang/lib/Driver/ToolChains/Clang.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4300,8 +4300,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
43004300
if (Arg *A = Args.getLastArg(options::OPT_sycl_std_EQ)) {
43014301
A->render(Args, CmdArgs);
43024302
} else {
4303-
// Ensure the default version in SYCL mode is 1.2.1 (aka 2017)
4304-
CmdArgs.push_back("-sycl-std=2017");
4303+
// Ensure the default version in SYCL mode is 2020.
4304+
CmdArgs.push_back("-sycl-std=2020");
43054305
}
43064306
}
43074307

clang/lib/Frontend/CompilerInvocation.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -3648,6 +3648,16 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
36483648
}
36493649
}
36503650

3651+
if ((Args.hasArg(OPT_fsycl_is_device) || Args.hasArg(OPT_fsycl_is_host)) &&
3652+
!Args.hasArg(OPT_sycl_std_EQ)) {
3653+
// If the user supplied -fsycl-is-device or -fsycl-is-host, but failed to
3654+
// provide -sycl-std=, we want to default it to whatever the default SYCL
3655+
// version is. I could not find a way to express this with the options
3656+
// tablegen because we still want this value to be SYCL_None when the user
3657+
// is not in device or host mode.
3658+
Opts.setSYCLVersion(LangOptions::SYCL_Default);
3659+
}
3660+
36513661
if (Opts.ObjC) {
36523662
if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) {
36533663
StringRef value = arg->getValue();

clang/lib/Frontend/InitPreprocessor.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
483483
// SYCL Version is set to a value when building SYCL applications
484484
if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2017)
485485
Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121");
486+
else if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2020)
487+
Builder.defineMacro("SYCL_LANGUAGE_VERSION", "202001");
486488
}
487489

488490
// Not "standard" per se, but available even with the -undef flag.

clang/test/Driver/sycl.c

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// RUN: %clang -### -fsycl -sycl-std=1.2.1 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
44
// RUN: %clang -### -fsycl -sycl-std=121 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
55
// RUN: %clang -### -fsycl -sycl-std=2017 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
6+
// RUN: %clang -### -fsycl -sycl-std=2020 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
67
// RUN: %clang -### -fsycl -sycl-std=sycl-1.2.1 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
78
// RUN: %clang -### -fno-sycl -fsycl %s 2>&1 | FileCheck %s --check-prefix=ENABLED
89
// RUN: %clang -### -sycl-std=2017 %s 2>&1 | FileCheck %s --check-prefix=DISABLED
@@ -18,3 +19,9 @@
1819
// ENABLED-SAME: "-sycl-std={{[-.sycl0-9]+}}"
1920
// DISABLED-NOT: "-fsycl-is-device"
2021
// DISABLED-NOT: "-sycl-std="
22+
23+
// RUN: %clang -### -fsycl %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
24+
// RUN: %clangxx -### -fsycl %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
25+
// RUN: %clang_cl -### -fsycl %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
26+
27+
// DEFAULT: "-sycl-std=2020"
+4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
// RUN: %clang_cc1 %s -E -dM | FileCheck %s
22
// RUN: %clang_cc1 %s -fsycl-is-device -sycl-std=2017 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD %s
33
// RUN: %clang_cc1 %s -fsycl-is-host -sycl-std=2017 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD %s
4+
// RUN: %clang_cc1 %s -fsycl-is-host -sycl-std=2020 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD-2020 %s
5+
// RUN: %clang_cc1 %s -fsycl-is-host -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD-2020 %s
46
// RUN: %clang_cc1 %s -fsycl-is-device -sycl-std=1.2.1 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD %s
7+
// RUN: %clang_cc1 %s -fsycl-is-device -sycl-std=2020 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD-2020 %s
58
// RUN: %clang_cc1 %s -fsycl-is-device -E -dM | FileCheck --check-prefixes=CHECK-SYCL %s
69

710
// CHECK-NOT:#define __SYCL_DEVICE_ONLY__ 1
811
// CHECK-NOT:#define CL_SYCL_LANGUAGE_VERSION 121
912
// CHECK-SYCL-STD:#define CL_SYCL_LANGUAGE_VERSION 121
13+
// CHECK-SYCL-STD-2020:#define SYCL_LANGUAGE_VERSION 202001
1014
// CHECK-SYCL:#define __SYCL_DEVICE_ONLY__ 1

clang/unittests/Frontend/CompilerInvocationTest.cpp

+87-3
Original file line numberDiff line numberDiff line change
@@ -566,18 +566,102 @@ TEST_F(CommandLineTest, ConditionalParsingIfFalseFlagPresent) {
566566
ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
567567
}
568568

569-
TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagNotPresent) {
569+
TEST_F(CommandLineTest, ConditionalParsingIfNonsenseSyclStdArg) {
570+
const char *Args[] = {"-fsycl-is-device", "-sycl-std=garbage"};
571+
572+
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
573+
574+
ASSERT_TRUE(Diags->hasErrorOccurred());
575+
ASSERT_TRUE(Invocation.getLangOpts()->SYCLIsDevice);
576+
ASSERT_FALSE(Invocation.getLangOpts()->SYCLIsHost);
577+
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_None);
578+
579+
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
580+
581+
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl-is-device")));
582+
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl-is-host"))));
583+
ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
584+
}
585+
586+
TEST_F(CommandLineTest, ConditionalParsingIfOddSyclStdArg1) {
587+
const char *Args[] = {"-fsycl-is-device", "-sycl-std=121"};
588+
589+
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
590+
591+
ASSERT_FALSE(Diags->hasErrorOccurred());
592+
ASSERT_TRUE(Invocation.getLangOpts()->SYCLIsDevice);
593+
ASSERT_FALSE(Invocation.getLangOpts()->SYCLIsHost);
594+
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_2017);
595+
596+
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
597+
598+
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl-is-device")));
599+
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl-is-host"))));
600+
ASSERT_THAT(GeneratedArgs, Contains(HasSubstr("-sycl-std=2017")));
601+
}
602+
603+
TEST_F(CommandLineTest, ConditionalParsingIfOddSyclStdArg2) {
604+
const char *Args[] = {"-fsycl-is-device", "-sycl-std=1.2.1"};
605+
606+
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
607+
608+
ASSERT_FALSE(Diags->hasErrorOccurred());
609+
ASSERT_TRUE(Invocation.getLangOpts()->SYCLIsDevice);
610+
ASSERT_FALSE(Invocation.getLangOpts()->SYCLIsHost);
611+
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_2017);
612+
613+
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
614+
615+
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl-is-device")));
616+
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl-is-host"))));
617+
ASSERT_THAT(GeneratedArgs, Contains(HasSubstr("-sycl-std=2017")));
618+
}
619+
620+
TEST_F(CommandLineTest, ConditionalParsingIfOddSyclStdArg3) {
621+
const char *Args[] = {"-fsycl-is-device", "-sycl-std=sycl-1.2.1"};
622+
623+
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
624+
625+
ASSERT_FALSE(Diags->hasErrorOccurred());
626+
ASSERT_TRUE(Invocation.getLangOpts()->SYCLIsDevice);
627+
ASSERT_FALSE(Invocation.getLangOpts()->SYCLIsHost);
628+
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_2017);
629+
630+
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
631+
632+
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl-is-device")));
633+
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl-is-host"))));
634+
ASSERT_THAT(GeneratedArgs, Contains(HasSubstr("-sycl-std=2017")));
635+
}
636+
637+
TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagNotPresentHost) {
570638
const char *Args[] = {"-fsycl-is-host"};
571639

572640
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
573641

574642
ASSERT_FALSE(Diags->hasErrorOccurred());
575-
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_None);
643+
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(),
644+
LangOptions::SYCL_Default);
576645

577646
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
578647

579648
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl-is-host")));
580-
ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
649+
ASSERT_THAT(GeneratedArgs, Contains(HasSubstr("-sycl-std=")));
650+
}
651+
652+
TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagNotPresentDevice) {
653+
const char *Args[] = {"-fsycl-is-device"};
654+
655+
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
656+
657+
ASSERT_FALSE(Diags->hasErrorOccurred());
658+
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(),
659+
LangOptions::SYCL_Default);
660+
661+
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
662+
663+
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl-is-device")));
664+
ASSERT_THAT(GeneratedArgs, Contains(HasSubstr("-sycl-std=")));
581665
}
582666

583667
TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagPresent) {

0 commit comments

Comments
 (0)