Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCL] Update the way we handle -sycl-std= based on community review feedback #3371

Merged
merged 2 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -4295,10 +4295,6 @@ def fsycl : Flag<["-"], "fsycl">, Flags<[NoXarchOption, CoreOption]>, Group<sycl
HelpText<"Enables SYCL kernels compilation for device">;
def fno_sycl : Flag<["-"], "fno-sycl">, Flags<[NoXarchOption, CoreOption]>, Group<sycl_Group>,
HelpText<"Disables SYCL kernels compilation for device">;
def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group<sycl_Group>, Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
HelpText<"SYCL language standard to compile for.">, Values<"2020,2017,121,1.2.1,sycl-1.2.1">,
NormalizedValues<["SYCL_2020", "SYCL_2017", "SYCL_2017", "SYCL_2017", "SYCL_2017"]>, NormalizedValuesScope<"LangOptions">,
MarshallingInfoString<LangOpts<"SYCLVersion">, "SYCL_None">, AutoNormalizeEnum;
defm sycl_esimd: BoolFOption<"sycl-explicit-simd",
LangOpts<"SYCLExplicitSIMD">, DefaultFalse,
PosFlag<SetTrue, [CC1Option], "Enable">, NegFlag<SetFalse, [], "Disable">,
Expand Down Expand Up @@ -5520,6 +5516,15 @@ def fsycl_is_device : Flag<["-"], "fsycl-is-device">,
def fsycl_is_host : Flag<["-"], "fsycl-is-host">,
HelpText<"SYCL host compilation">,
MarshallingInfoFlag<LangOpts<"SYCLIsHost">>;
def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group<sycl_Group>,
Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
HelpText<"SYCL language standard to compile for.">,
Values<"2020,2017,121,1.2.1,sycl-1.2.1">,
NormalizedValues<["SYCL_2020", "SYCL_2017", "SYCL_2017", "SYCL_2017", "SYCL_2017"]>,
NormalizedValuesScope<"LangOptions">,
MarshallingInfoString<LangOpts<"SYCLVersion">, "SYCL_None">,
AutoNormalizeEnum,
ShouldParseIf<!strconcat(fsycl_is_device.KeyPath, "||", fsycl_is_host.KeyPath)>;
def fsycl_int_header : Separate<["-"], "fsycl-int-header">,
HelpText<"Generate SYCL integration header into this file.">,
MarshallingInfoString<LangOpts<"SYCLIntHeader">>;
Expand Down
22 changes: 8 additions & 14 deletions clang/unittests/Frontend/CompilerInvocationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,46 +531,40 @@ TEST_F(CommandLineTest, ConditionalParsingIfFalseFlagPresent) {
ASSERT_FALSE(Diags->hasErrorOccurred());
ASSERT_FALSE(Invocation.getLangOpts()->SYCLIsDevice);
ASSERT_FALSE(Invocation.getLangOpts()->SYCLIsHost);
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_2017);
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_None);

Invocation.generateCC1CommandLine(GeneratedArgs, *this);

ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl-is-device"))));
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl-is-host"))));

// FIXME: generateCC1CommandLine is only used by the unit test system and
// cannot handle this case. It passes along the -sycl-std because the option
// definition does not specify that it relies on -fsycl any longer (because
// there is no syntax I could find that would allow it). However, the option
// is handled properly on a real invocation. See: Clang::ConstructJob().
ASSERT_THAT(GeneratedArgs, Contains(HasSubstr("-sycl-std=")));
ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
}

TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagNotPresent) {
const char *Args[] = {"-fsycl"};
const char *Args[] = {"-fsycl-is-host"};

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

ASSERT_TRUE(Diags->hasErrorOccurred());
ASSERT_FALSE(Diags->hasErrorOccurred());
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_None);

Invocation.generateCC1CommandLine(GeneratedArgs, *this);

ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl"))));
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl-is-host")));
ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
}

TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagPresent) {
const char *Args[] = {"-fsycl", "-sycl-std=2017"};
const char *Args[] = {"-fsycl-is-device", "-sycl-std=2017"};

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

ASSERT_TRUE(Diags->hasErrorOccurred());
ASSERT_FALSE(Diags->hasErrorOccurred());
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_2017);

Invocation.generateCC1CommandLine(GeneratedArgs, *this);

ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl"))));
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl-is-device")));
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-sycl-std=2017")));
}

Expand Down