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.
This commit is contained in:
Aaron Ballman 2021-05-18 10:32:22 -04:00
parent ba1509da7b
commit 6381664580
9 changed files with 119 additions and 8 deletions

View File

@ -252,7 +252,7 @@ LANGOPT(GPUExcludeWrongSideOverloads, 1, 0, "always exclude wrong side overloads
LANGOPT(SYCLIsDevice , 1, 0, "Generate code for SYCL device")
LANGOPT(SYCLIsHost , 1, 0, "SYCL host compilation")
ENUM_LANGOPT(SYCLVersion , SYCLMajorVersion, 1, SYCL_None, "Version of the SYCL standard used")
ENUM_LANGOPT(SYCLVersion , SYCLMajorVersion, 2, SYCL_None, "Version of the SYCL standard used")
LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP")

View File

@ -130,6 +130,10 @@ public:
enum SYCLMajorVersion {
SYCL_None,
SYCL_2017,
SYCL_2020,
// The "default" SYCL version to be used when none is specified on the
// frontend command line.
SYCL_Default = SYCL_2020
};
/// Clang versions with different platform ABI conformance.

View File

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

View File

@ -4300,8 +4300,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (Arg *A = Args.getLastArg(options::OPT_sycl_std_EQ)) {
A->render(Args, CmdArgs);
} else {
// Ensure the default version in SYCL mode is 1.2.1 (aka 2017)
CmdArgs.push_back("-sycl-std=2017");
// Ensure the default version in SYCL mode is 2020.
CmdArgs.push_back("-sycl-std=2020");
}
}

View File

@ -3648,6 +3648,16 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
}
}
if ((Args.hasArg(OPT_fsycl_is_device) || Args.hasArg(OPT_fsycl_is_host)) &&
!Args.hasArg(OPT_sycl_std_EQ)) {
// If the user supplied -fsycl-is-device or -fsycl-is-host, but failed to
// provide -sycl-std=, we want to default it to whatever the default SYCL
// version is. I could not find a way to express this with the options
// tablegen because we still want this value to be SYCL_None when the user
// is not in device or host mode.
Opts.setSYCLVersion(LangOptions::SYCL_Default);
}
if (Opts.ObjC) {
if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) {
StringRef value = arg->getValue();

View File

@ -483,6 +483,8 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
// SYCL Version is set to a value when building SYCL applications
if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2017)
Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121");
else if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2020)
Builder.defineMacro("SYCL_LANGUAGE_VERSION", "202001");
}
// Not "standard" per se, but available even with the -undef flag.

View File

@ -3,6 +3,7 @@
// RUN: %clang -### -fsycl -sycl-std=1.2.1 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
// RUN: %clang -### -fsycl -sycl-std=121 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
// RUN: %clang -### -fsycl -sycl-std=2017 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
// RUN: %clang -### -fsycl -sycl-std=2020 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
// RUN: %clang -### -fsycl -sycl-std=sycl-1.2.1 %s 2>&1 | FileCheck %s --check-prefix=ENABLED
// RUN: %clang -### -fno-sycl -fsycl %s 2>&1 | FileCheck %s --check-prefix=ENABLED
// RUN: %clang -### -sycl-std=2017 %s 2>&1 | FileCheck %s --check-prefix=DISABLED
@ -18,3 +19,9 @@
// ENABLED-SAME: "-sycl-std={{[-.sycl0-9]+}}"
// DISABLED-NOT: "-fsycl-is-device"
// DISABLED-NOT: "-sycl-std="
// RUN: %clang -### -fsycl %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
// RUN: %clangxx -### -fsycl %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
// RUN: %clang_cl -### -fsycl %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
// DEFAULT: "-sycl-std=2020"

View File

@ -1,10 +1,14 @@
// RUN: %clang_cc1 %s -E -dM | FileCheck %s
// RUN: %clang_cc1 %s -fsycl-is-device -sycl-std=2017 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD %s
// RUN: %clang_cc1 %s -fsycl-is-host -sycl-std=2017 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD %s
// RUN: %clang_cc1 %s -fsycl-is-host -sycl-std=2020 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD-2020 %s
// RUN: %clang_cc1 %s -fsycl-is-host -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD-2020 %s
// RUN: %clang_cc1 %s -fsycl-is-device -sycl-std=1.2.1 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD %s
// RUN: %clang_cc1 %s -fsycl-is-device -sycl-std=2020 -E -dM | FileCheck --check-prefix=CHECK-SYCL-STD-2020 %s
// RUN: %clang_cc1 %s -fsycl-is-device -E -dM | FileCheck --check-prefixes=CHECK-SYCL %s
// CHECK-NOT:#define __SYCL_DEVICE_ONLY__ 1
// CHECK-NOT:#define CL_SYCL_LANGUAGE_VERSION 121
// CHECK-SYCL-STD:#define CL_SYCL_LANGUAGE_VERSION 121
// CHECK-SYCL-STD-2020:#define SYCL_LANGUAGE_VERSION 202001
// CHECK-SYCL:#define __SYCL_DEVICE_ONLY__ 1

View File

@ -566,18 +566,102 @@ TEST_F(CommandLineTest, ConditionalParsingIfFalseFlagPresent) {
ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
}
TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagNotPresent) {
TEST_F(CommandLineTest, ConditionalParsingIfNonsenseSyclStdArg) {
const char *Args[] = {"-fsycl-is-device", "-sycl-std=garbage"};
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
ASSERT_TRUE(Diags->hasErrorOccurred());
ASSERT_TRUE(Invocation.getLangOpts()->SYCLIsDevice);
ASSERT_FALSE(Invocation.getLangOpts()->SYCLIsHost);
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_None);
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl-is-device")));
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl-is-host"))));
ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
}
TEST_F(CommandLineTest, ConditionalParsingIfOddSyclStdArg1) {
const char *Args[] = {"-fsycl-is-device", "-sycl-std=121"};
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
ASSERT_FALSE(Diags->hasErrorOccurred());
ASSERT_TRUE(Invocation.getLangOpts()->SYCLIsDevice);
ASSERT_FALSE(Invocation.getLangOpts()->SYCLIsHost);
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_2017);
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl-is-device")));
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl-is-host"))));
ASSERT_THAT(GeneratedArgs, Contains(HasSubstr("-sycl-std=2017")));
}
TEST_F(CommandLineTest, ConditionalParsingIfOddSyclStdArg2) {
const char *Args[] = {"-fsycl-is-device", "-sycl-std=1.2.1"};
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
ASSERT_FALSE(Diags->hasErrorOccurred());
ASSERT_TRUE(Invocation.getLangOpts()->SYCLIsDevice);
ASSERT_FALSE(Invocation.getLangOpts()->SYCLIsHost);
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_2017);
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl-is-device")));
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl-is-host"))));
ASSERT_THAT(GeneratedArgs, Contains(HasSubstr("-sycl-std=2017")));
}
TEST_F(CommandLineTest, ConditionalParsingIfOddSyclStdArg3) {
const char *Args[] = {"-fsycl-is-device", "-sycl-std=sycl-1.2.1"};
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
ASSERT_FALSE(Diags->hasErrorOccurred());
ASSERT_TRUE(Invocation.getLangOpts()->SYCLIsDevice);
ASSERT_FALSE(Invocation.getLangOpts()->SYCLIsHost);
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_2017);
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl-is-device")));
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl-is-host"))));
ASSERT_THAT(GeneratedArgs, Contains(HasSubstr("-sycl-std=2017")));
}
TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagNotPresentHost) {
const char *Args[] = {"-fsycl-is-host"};
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
ASSERT_FALSE(Diags->hasErrorOccurred());
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_None);
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(),
LangOptions::SYCL_Default);
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl-is-host")));
ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
ASSERT_THAT(GeneratedArgs, Contains(HasSubstr("-sycl-std=")));
}
TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagNotPresentDevice) {
const char *Args[] = {"-fsycl-is-device"};
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
ASSERT_FALSE(Diags->hasErrorOccurred());
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(),
LangOptions::SYCL_Default);
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl-is-device")));
ASSERT_THAT(GeneratedArgs, Contains(HasSubstr("-sycl-std=")));
}
TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagPresent) {