Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ def err_drv_amdgpu_ieee_without_no_honor_nans : Error<
"invalid argument '-mno-amdgpu-ieee' only allowed with relaxed NaN handling">;
def err_drv_argument_not_allowed_with : Error<
"invalid argument '%0' not allowed with '%1'">;
def warn_drv_argument_not_allowed_with : Warning<
"invalid argument '%0' not allowed with '%1'">,
InGroup<OptionIgnored>;
def err_drv_cannot_open_randomize_layout_seed_file : Error<
"cannot read randomize layout seed file '%0'">;
def err_drv_invalid_version_number : Error<
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -9218,6 +9218,12 @@ def : CLFlag<"Qscatter-">, Alias<mno_scatter>,

def _SLASH_arch : CLCompileJoined<"arch:">,
HelpText<"Set architecture for code generation">;
def _SLASH_vlen : CLFlag<"vlen">,
HelpText<"Set default vector length for autovectorization and other optimizations">;
def _SLASH_vlen_EQ_256 : CLFlag<"vlen=256">,
HelpText<"Set vector length of 256 bits for autovectorization and other optimizations">;
def _SLASH_vlen_EQ_512 : CLFlag<"vlen=512">,
HelpText<"Set vector length of 512 bits for autovectorization and other optimizations">;

def _SLASH_M_Group : OptionGroup<"</M group>">, Group<cl_compile_Group>;
def _SLASH_volatile_Group : OptionGroup<"</volatile group>">,
Expand Down
24 changes: 24 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8266,6 +8266,30 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
<< "/kernel";
}

if (const Arg *A = Args.getLastArg(options::OPT__SLASH_vlen,
options::OPT__SLASH_vlen_EQ_256,
options::OPT__SLASH_vlen_EQ_512)) {
llvm::Triple::ArchType AT = getToolChain().getArch();
StringRef Default = AT == llvm::Triple::x86 ? "IA32" : "SSE2";
StringRef Arch = Args.getLastArgValue(options::OPT__SLASH_arch, Default);

if (A->getOption().matches(options::OPT__SLASH_vlen_EQ_512)) {
if (Arch == "AVX512F" || Arch == "AVX512")
CmdArgs.push_back("-mprefer-vector-width=512");
else
D.Diag(diag::warn_drv_argument_not_allowed_with)
<< "/vlen=512" << std::string("/arch:").append(Arch);
}

if (A->getOption().matches(options::OPT__SLASH_vlen_EQ_256)) {
if (Arch == "AVX512F" || Arch == "AVX512")
CmdArgs.push_back("-mprefer-vector-width=256");
else if (Arch != "AVX" && Arch != "AVX2")
D.Diag(diag::warn_drv_argument_not_allowed_with)
<< "/vlen=256" << std::string("/arch:").append(Arch);
}
}

Arg *MostGeneralArg = Args.getLastArg(options::OPT__SLASH_vmg);
Arg *BestCaseArg = Args.getLastArg(options::OPT__SLASH_vmb);
if (MostGeneralArg && BestCaseArg)
Expand Down
22 changes: 22 additions & 0 deletions clang/test/Driver/cl-x86-flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,28 @@
// tune: "-target-cpu" "sandybridge"
// tune-SAME: "-tune-cpu" "haswell"

// RUN: %clang_cl -m64 -arch:AVX512 -vlen=512 --target=x86_64-pc-windows -### -- 2>&1 %s | FileCheck -check-prefix=vlen512 %s
// vlen512: "-mprefer-vector-width=512"

// RUN: %clang_cl -m64 -arch:AVX512 -vlen=256 --target=x86_64-pc-windows -### -- 2>&1 %s | FileCheck -check-prefix=vlen256 %s
// vlen256: "-mprefer-vector-width=256"

// RUN: %clang_cl -m64 -arch:AVX512 -vlen=512 -vlen --target=x86_64-pc-windows -### -- 2>&1 %s | FileCheck -check-prefix=novlen %s
// novlen-NOT: -mprefer-vector-width

// RUN: %clang_cl -m64 -arch:AVX2 -vlen=512 --target=x86_64-pc-windows -### -- 2>&1 %s | FileCheck -check-prefix=avx2vlen512 %s
// avx2vlen512: invalid argument '/vlen=512' not allowed with '/arch:AVX2'

// RUN: %clang_cl -m64 -arch:AVX2 -vlen=256 --target=x86_64-pc-windows -### -- 2>&1 %s | FileCheck -check-prefix=avx2vlen256 %s
// avx2vlen256-NOT: invalid argument

// RUN: %clang_cl -m32 -arch:SSE2 -vlen=256 --target=i386-pc-windows -### -- 2>&1 %s | FileCheck -check-prefix=sse2vlen256 %s
// RUN: %clang_cl -m64 -vlen=256 --target=x86_64-pc-windows -### -- 2>&1 %s | FileCheck -check-prefix=sse2vlen256 %s
// sse2vlen256: invalid argument '/vlen=256' not allowed with '/arch:SSE2'

// RUN: %clang_cl -m32 -vlen=256 --target=i386-pc-windows -### -- 2>&1 %s | FileCheck -check-prefix=ia32vlen256 %s
// ia32vlen256: invalid argument '/vlen=256' not allowed with '/arch:IA32'

void f(void) {
}

Expand Down
Loading