Author: Aaron Ballman Date: 2021-05-18T10:34:14-04:00 New Revision: 6381664580080f015bc0c2ec647853f697cf744a
URL: https://github.com/llvm/llvm-project/commit/6381664580080f015bc0c2ec647853f697cf744a DIFF: https://github.com/llvm/llvm-project/commit/6381664580080f015bc0c2ec647853f697cf744a.diff LOG: 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. Added: Modified: clang/include/clang/Basic/LangOptions.def clang/include/clang/Basic/LangOptions.h clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Frontend/InitPreprocessor.cpp clang/test/Driver/sycl.c clang/test/Preprocessor/sycl-macro.cpp clang/unittests/Frontend/CompilerInvocationTest.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 31a42e83fd0e4..20c03987bd027 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -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") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 524b79b138140..454c101b21425 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -130,6 +130,10 @@ class LangOptions : public LangOptionsBase { 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 diff erent platform ABI conformance. diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 67d9a2bbc328c..09de6b5a50d00 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -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)>; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 63ca39ee4e934..afc119263db96 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -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"); } } diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 9cb859f233238..809492a36d3fa 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -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(); diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 163c77b04c139..8e63046f4ab22 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -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. diff --git a/clang/test/Driver/sycl.c b/clang/test/Driver/sycl.c index 4a39fef06b6dc..af3af91cc062a 100644 --- a/clang/test/Driver/sycl.c +++ b/clang/test/Driver/sycl.c @@ -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" diff --git a/clang/test/Preprocessor/sycl-macro.cpp b/clang/test/Preprocessor/sycl-macro.cpp index d1d830210529c..eecddaa09d1c3 100644 --- a/clang/test/Preprocessor/sycl-macro.cpp +++ b/clang/test/Preprocessor/sycl-macro.cpp @@ -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 diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp index 0baf17f123acc..9bcbf1fe6001d 100644 --- a/clang/unittests/Frontend/CompilerInvocationTest.cpp +++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp @@ -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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits