Skip to content

Commit ad7488a

Browse files
authored
1 parent 77a194c commit ad7488a

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ def err_drv_amdgpu_ieee_without_no_honor_nans : Error<
207207
"invalid argument '-mno-amdgpu-ieee' only allowed with relaxed NaN handling">;
208208
def err_drv_argument_not_allowed_with : Error<
209209
"invalid argument '%0' not allowed with '%1'">;
210+
def warn_drv_argument_not_allowed_with : Warning<
211+
"invalid argument '%0' not allowed with '%1'">,
212+
InGroup<OptionIgnored>;
210213
def err_drv_cannot_open_randomize_layout_seed_file : Error<
211214
"cannot read randomize layout seed file '%0'">;
212215
def err_drv_invalid_version_number : Error<

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9218,6 +9218,12 @@ def : CLFlag<"Qscatter-">, Alias<mno_scatter>,
92189218

92199219
def _SLASH_arch : CLCompileJoined<"arch:">,
92209220
HelpText<"Set architecture for code generation">;
9221+
def _SLASH_vlen : CLFlag<"vlen">,
9222+
HelpText<"Set default vector length for autovectorization and other optimizations">;
9223+
def _SLASH_vlen_EQ_256 : CLFlag<"vlen=256">,
9224+
HelpText<"Set vector length of 256 bits for autovectorization and other optimizations">;
9225+
def _SLASH_vlen_EQ_512 : CLFlag<"vlen=512">,
9226+
HelpText<"Set vector length of 512 bits for autovectorization and other optimizations">;
92219227

92229228
def _SLASH_M_Group : OptionGroup<"</M group>">, Group<cl_compile_Group>;
92239229
def _SLASH_volatile_Group : OptionGroup<"</volatile group>">,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8266,6 +8266,30 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
82668266
<< "/kernel";
82678267
}
82688268

8269+
if (const Arg *A = Args.getLastArg(options::OPT__SLASH_vlen,
8270+
options::OPT__SLASH_vlen_EQ_256,
8271+
options::OPT__SLASH_vlen_EQ_512)) {
8272+
llvm::Triple::ArchType AT = getToolChain().getArch();
8273+
StringRef Default = AT == llvm::Triple::x86 ? "IA32" : "SSE2";
8274+
StringRef Arch = Args.getLastArgValue(options::OPT__SLASH_arch, Default);
8275+
8276+
if (A->getOption().matches(options::OPT__SLASH_vlen_EQ_512)) {
8277+
if (Arch == "AVX512F" || Arch == "AVX512")
8278+
CmdArgs.push_back("-mprefer-vector-width=512");
8279+
else
8280+
D.Diag(diag::warn_drv_argument_not_allowed_with)
8281+
<< "/vlen=512" << std::string("/arch:").append(Arch);
8282+
}
8283+
8284+
if (A->getOption().matches(options::OPT__SLASH_vlen_EQ_256)) {
8285+
if (Arch == "AVX512F" || Arch == "AVX512")
8286+
CmdArgs.push_back("-mprefer-vector-width=256");
8287+
else if (Arch != "AVX" && Arch != "AVX2")
8288+
D.Diag(diag::warn_drv_argument_not_allowed_with)
8289+
<< "/vlen=256" << std::string("/arch:").append(Arch);
8290+
}
8291+
}
8292+
82698293
Arg *MostGeneralArg = Args.getLastArg(options::OPT__SLASH_vmg);
82708294
Arg *BestCaseArg = Args.getLastArg(options::OPT__SLASH_vmb);
82718295
if (MostGeneralArg && BestCaseArg)

clang/test/Driver/cl-x86-flags.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,28 @@
133133
// tune: "-target-cpu" "sandybridge"
134134
// tune-SAME: "-tune-cpu" "haswell"
135135

136+
// RUN: %clang_cl -m64 -arch:AVX512 -vlen=512 --target=x86_64-pc-windows -### -- 2>&1 %s | FileCheck -check-prefix=vlen512 %s
137+
// vlen512: "-mprefer-vector-width=512"
138+
139+
// RUN: %clang_cl -m64 -arch:AVX512 -vlen=256 --target=x86_64-pc-windows -### -- 2>&1 %s | FileCheck -check-prefix=vlen256 %s
140+
// vlen256: "-mprefer-vector-width=256"
141+
142+
// RUN: %clang_cl -m64 -arch:AVX512 -vlen=512 -vlen --target=x86_64-pc-windows -### -- 2>&1 %s | FileCheck -check-prefix=novlen %s
143+
// novlen-NOT: -mprefer-vector-width
144+
145+
// RUN: %clang_cl -m64 -arch:AVX2 -vlen=512 --target=x86_64-pc-windows -### -- 2>&1 %s | FileCheck -check-prefix=avx2vlen512 %s
146+
// avx2vlen512: invalid argument '/vlen=512' not allowed with '/arch:AVX2'
147+
148+
// RUN: %clang_cl -m64 -arch:AVX2 -vlen=256 --target=x86_64-pc-windows -### -- 2>&1 %s | FileCheck -check-prefix=avx2vlen256 %s
149+
// avx2vlen256-NOT: invalid argument
150+
151+
// RUN: %clang_cl -m32 -arch:SSE2 -vlen=256 --target=i386-pc-windows -### -- 2>&1 %s | FileCheck -check-prefix=sse2vlen256 %s
152+
// RUN: %clang_cl -m64 -vlen=256 --target=x86_64-pc-windows -### -- 2>&1 %s | FileCheck -check-prefix=sse2vlen256 %s
153+
// sse2vlen256: invalid argument '/vlen=256' not allowed with '/arch:SSE2'
154+
155+
// RUN: %clang_cl -m32 -vlen=256 --target=i386-pc-windows -### -- 2>&1 %s | FileCheck -check-prefix=ia32vlen256 %s
156+
// ia32vlen256: invalid argument '/vlen=256' not allowed with '/arch:IA32'
157+
136158
void f(void) {
137159
}
138160

0 commit comments

Comments
 (0)