r320419 - [Driver][CodeGen] Add -mprefer-vector-width driver option and attribute during CodeGen.
Craig Topper via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 11 13:09:20 PST 2017
Author: ctopper
Date: Mon Dec 11 13:09:19 2017
New Revision: 320419
URL: http://llvm.org/viewvc/llvm-project?rev=320419&view=rev
Log:
[Driver][CodeGen] Add -mprefer-vector-width driver option and attribute during CodeGen.
This adds a new command line option -mprefer-vector-width to specify a preferred vector width for the vectorizers. Valid values are 'none' and unsigned integers. The driver will check that it meets those constraints. Specific supported integers will be managed by the targets in the backend.
Clang will take the value and add it as a new function attribute during CodeGen.
This represents the alternate direction proposed by Sanjay in this RFC: http://lists.llvm.org/pipermail/llvm-dev/2017-November/118734.html
The syntax here matches gcc, though gcc treats it as an x86 specific command line argument. gcc only allows values of 128, 256, and 512. I'm not having clang check any values.
Differential Revision: https://reviews.llvm.org/D40230
Added:
cfe/trunk/test/CodeGen/attr-mprefer-vector-width.c (with props)
cfe/trunk/test/Driver/mprefer-vector-width.c (with props)
Modified:
cfe/trunk/docs/ClangCommandLineReference.rst
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.h
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
Modified: cfe/trunk/docs/ClangCommandLineReference.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangCommandLineReference.rst?rev=320419&r1=320418&r2=320419&view=diff
==============================================================================
--- cfe/trunk/docs/ClangCommandLineReference.rst (original)
+++ cfe/trunk/docs/ClangCommandLineReference.rst Mon Dec 11 13:09:19 2017
@@ -2120,6 +2120,10 @@ Omit frame pointer setup for leaf functi
Use copy relocations support for PIE builds
+.. option:: -mprefer-vector-width=<arg>
+
+Specifies preferred vector width for auto-vectorization. Defaults to 'none' which allows target specific decisions.
+
.. option:: -mqdsp6-compat
Enable hexagon-qdsp6 backward compatibility
Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=320419&r1=320418&r2=320419&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Mon Dec 11 13:09:19 2017
@@ -1954,6 +1954,8 @@ def mno_implicit_float : Flag<["-"], "mn
def mimplicit_float : Flag<["-"], "mimplicit-float">, Group<m_Group>;
def mrecip : Flag<["-"], "mrecip">, Group<m_Group>;
def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group<m_Group>, Flags<[CC1Option]>;
+def mprefer_vector_width_EQ : Joined<["-"], "mprefer-vector-width=">, Group<m_Group>, Flags<[CC1Option]>,
+ HelpText<"Specifies preferred vector width for auto-vectorization. Defaults to 'none' which allows target specific decisions.">;
def mpie_copy_relocations : Flag<["-"], "mpie-copy-relocations">, Group<m_Group>,
Flags<[CC1Option]>,
HelpText<"Use copy relocations support for PIE builds">;
Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.h?rev=320419&r1=320418&r2=320419&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.h Mon Dec 11 13:09:19 2017
@@ -253,6 +253,11 @@ public:
std::vector<std::string> Reciprocals;
+ /// The preferred width for auto-vectorization transforms. This is intended to
+ /// override default transforms based on the width of the architected vector
+ /// registers.
+ std::string PreferVectorWidth;
+
public:
// Define accessors/mutators for code generation options of enumeration type.
#define CODEGENOPT(Name, Bits, Default)
Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=320419&r1=320418&r2=320419&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Dec 11 13:09:19 2017
@@ -1744,6 +1744,11 @@ void CodeGenModule::ConstructDefaultFnAt
FuncAttrs.addAttribute("reciprocal-estimates",
llvm::join(Recips, ","));
+ if (!CodeGenOpts.PreferVectorWidth.empty() &&
+ CodeGenOpts.PreferVectorWidth != "none")
+ FuncAttrs.addAttribute("prefer-vector-width",
+ CodeGenOpts.PreferVectorWidth);
+
if (CodeGenOpts.StackRealignment)
FuncAttrs.addAttribute("stackrealign");
if (CodeGenOpts.Backchain)
Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=320419&r1=320418&r2=320419&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Dec 11 13:09:19 2017
@@ -274,6 +274,27 @@ static void ParseMRecip(const Driver &D,
OutStrings.push_back(Args.MakeArgString(Out));
}
+/// The -mprefer-vector-width option accepts either a positive integer
+/// or the string "none".
+static void ParseMPreferVectorWidth(const Driver &D, const ArgList &Args,
+ ArgStringList &CmdArgs) {
+ Arg *A = Args.getLastArg(options::OPT_mprefer_vector_width_EQ);
+ if (!A)
+ return;
+
+ StringRef Value = A->getValue();
+ if (Value == "none") {
+ CmdArgs.push_back("-mprefer-vector-width=none");
+ } else {
+ unsigned Width;
+ if (Value.getAsInteger(10, Width)) {
+ D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Value;
+ return;
+ }
+ CmdArgs.push_back(Args.MakeArgString("-mprefer-vector-width=" + Value));
+ }
+}
+
static void getWebAssemblyTargetFeatures(const ArgList &Args,
std::vector<StringRef> &Features) {
handleTargetFeaturesGroup(Args, Features, options::OPT_m_wasm_Features_Group);
@@ -4333,6 +4354,8 @@ void Clang::ConstructJob(Compilation &C,
options::OPT_fno_slp_vectorize, EnableSLPVec))
CmdArgs.push_back("-vectorize-slp");
+ ParseMPreferVectorWidth(D, Args, CmdArgs);
+
if (Arg *A = Args.getLastArg(options::OPT_fshow_overloads_EQ))
A->render(Args, CmdArgs);
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=320419&r1=320418&r2=320419&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Dec 11 13:09:19 2017
@@ -713,6 +713,8 @@ static bool ParseCodeGenArgs(CodeGenOpti
Opts.VectorizeLoop = Args.hasArg(OPT_vectorize_loops);
Opts.VectorizeSLP = Args.hasArg(OPT_vectorize_slp);
+ Opts.PreferVectorWidth = Args.getLastArgValue(OPT_mprefer_vector_width_EQ);
+
Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name);
Opts.VerifyModule = !Args.hasArg(OPT_disable_llvm_verifier);
Added: cfe/trunk/test/CodeGen/attr-mprefer-vector-width.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/attr-mprefer-vector-width.c?rev=320419&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/attr-mprefer-vector-width.c (added)
+++ cfe/trunk/test/CodeGen/attr-mprefer-vector-width.c Mon Dec 11 13:09:19 2017
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -mprefer-vector-width=128 -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK128
+// RUN: %clang_cc1 -mprefer-vector-width=256 -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK256
+// RUN: %clang_cc1 -mprefer-vector-width=none -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECKNONE
+
+int baz(int a) { return 4; }
+
+// CHECK128: baz{{.*}} #0
+// CHECK128: #0 = {{.*}}"prefer-vector-width"="128"
+
+// CHECK256: baz{{.*}} #0
+// CHECK256: #0 = {{.*}}"prefer-vector-width"="256"
+
+// CHECKNONE: baz{{.*}} #0
+// CHECKNONE-NOT: #0 = {{.*}}"prefer-vector-width"="none"
Propchange: cfe/trunk/test/CodeGen/attr-mprefer-vector-width.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/CodeGen/attr-mprefer-vector-width.c
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Rev URL"
Propchange: cfe/trunk/test/CodeGen/attr-mprefer-vector-width.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cfe/trunk/test/Driver/mprefer-vector-width.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/mprefer-vector-width.c?rev=320419&view=auto
==============================================================================
--- cfe/trunk/test/Driver/mprefer-vector-width.c (added)
+++ cfe/trunk/test/Driver/mprefer-vector-width.c Mon Dec 11 13:09:19 2017
@@ -0,0 +1,24 @@
+////
+//// Verify that valid options for the -mprefer-vector-width flag are passed through and invalid options cause an error.
+////
+
+//// If there are no options, convert to 'all'.
+
+// RUN: %clang -### -S %s -mprefer-vector-width=none 2>&1 | FileCheck --check-prefix=WIDTHNONE %s
+// WIDTHNONE: "-mprefer-vector-width=none"
+
+//// Check options that cover all types.
+
+// RUN: %clang -### -S %s -mprefer-vector-width=128 2>&1 | FileCheck --check-prefix=WIDTH128 %s
+// WIDTH128: "-mprefer-vector-width=128"
+
+//// Check invalid parameters.
+
+// RUN: %clang -### -S %s -mprefer-vector-width=one 2>&1 | FileCheck --check-prefix=WIDTHONE %s
+// WIDTHONE: invalid value 'one' in 'mprefer-vector-width='
+
+// RUN: %clang -### -S %s -mprefer-vector-width=128.5 2>&1 | FileCheck --check-prefix=WIDTH128p5 %s
+// WIDTH128p5: invalid value '128.5' in 'mprefer-vector-width='
+
+// RUN: %clang -### -S %s -mprefer-vector-width=-128 2>&1 | FileCheck --check-prefix=WIDTHNEG128 %s
+// WIDTHNEG128: invalid value '-128' in 'mprefer-vector-width='
Propchange: cfe/trunk/test/Driver/mprefer-vector-width.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/Driver/mprefer-vector-width.c
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Rev URL"
Propchange: cfe/trunk/test/Driver/mprefer-vector-width.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list