[llvm-branch-commits] [cfe-branch] r243699 - Merging r243642, r243643, and r243644:

Hans Wennborg hans at hanshq.net
Thu Jul 30 15:47:41 PDT 2015


Author: hans
Date: Thu Jul 30 17:47:41 2015
New Revision: 243699

URL: http://llvm.org/viewvc/llvm-project?rev=243699&view=rev
Log:
Merging r243642, r243643, and r243644:
------------------------------------------------------------------------
r243642 | uweigand | 2015-07-30 07:08:36 -0700 (Thu, 30 Jul 2015) | 29 lines

Add support for System z vector language extensions

The z13 vector facility has an associated language extension,
closely modeled on AltiVec/VSX.  The main differences are:

- vector long, vector float and vector pixel are not supported

- vector long long and vector double are supported (like VSX)

- comparison operators return a vector rather than a scalar integer

- shift operators behave like the OpenCL shift operators

- vector bool is only supported as argument to certain operators;
  some operators allow mixing a bool with a non-bool vector 

This patch adds clang support for the extension.  It is closely modelled
on the AltiVec support.  Similarly to the -faltivec option, there's a
new -fzvector option to enable the extensions (as well as an -mzvector
alias for compatibility with GCC).  There's also a separate LangOpt.

The extension as implemented here is intended to be compatible with
the -mzvector extension recently implemented by GCC.

Based on a patch by Richard Sandiford.

Differential Revision: http://reviews.llvm.org/D11001
------------------------------------------------------------------------

------------------------------------------------------------------------
r243643 | uweigand | 2015-07-30 07:10:43 -0700 (Thu, 30 Jul 2015) | 18 lines

[SystemZ] Add support for vecintrin.h vector built-in functions

This patch adds support for the System Z vector built-in functions.
The API-defined header file has the name vecintrin.h.

The user-level functions are defined in the same style as the clang
version of altivec.h, making heavy use of the __overloadable__ and
__always_inline__ attributes.  Where possible the functions expand to
generic operations rather than specific built-in functions, in the hope
that that form can be optimised better.

Where a built-in routine is specified to require an immediate integer
argument, the __enable_if__ attribute is used to verify the argument is
in fact constant and in the appropriate range.

Based on a patch by Richard Sandiford.
------------------------------------------------------------------------

------------------------------------------------------------------------
r243644 | uweigand | 2015-07-30 08:53:58 -0700 (Thu, 30 Jul 2015) | 21 lines

Fix sanitizer fallout from r243642

The memory-sanitizer build bot reported:

==5574== WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f03089e15f6 in
clang::Parser::TryAltiVecTokenOutOfLine(clang::DeclSpec&,
clang::SourceLocation, char const*&, unsigned int&, bool&)
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Parse/ParseDecl.cpp:6290:11

This is because the "Ident_pixel" variable was uninitialized
in the getLangOpts().ZVector case, but we'd still call into
clang::Parser::TryAltiVecTokenOutOfLine, which uses the variable.

The simplest fix for this without sprinkling !getLangOpts().ZVector
checks all over the code seems to be to just initialize the variable
to nullptr; this will then do the right thing on ZVector.

Checked in to unbreak the build bots.
------------------------------------------------------------------------

Added:
    cfe/branches/release_37/lib/Headers/vecintrin.h
      - copied unchanged from r243643, cfe/trunk/lib/Headers/vecintrin.h
    cfe/branches/release_37/test/CodeGen/builtins-systemz-zvector-error.c
      - copied unchanged from r243643, cfe/trunk/test/CodeGen/builtins-systemz-zvector-error.c
    cfe/branches/release_37/test/CodeGen/builtins-systemz-zvector.c
      - copied unchanged from r243643, cfe/trunk/test/CodeGen/builtins-systemz-zvector.c
    cfe/branches/release_37/test/CodeGen/zvector.c
      - copied unchanged from r243642, cfe/trunk/test/CodeGen/zvector.c
    cfe/branches/release_37/test/Sema/zvector.c
      - copied unchanged from r243642, cfe/trunk/test/Sema/zvector.c
Modified:
    cfe/branches/release_37/   (props changed)
    cfe/branches/release_37/include/clang/Basic/DiagnosticParseKinds.td
    cfe/branches/release_37/include/clang/Basic/LangOptions.def
    cfe/branches/release_37/include/clang/Basic/TokenKinds.def
    cfe/branches/release_37/include/clang/Driver/Options.td
    cfe/branches/release_37/include/clang/Parse/Parser.h
    cfe/branches/release_37/include/clang/Sema/Sema.h
    cfe/branches/release_37/lib/Basic/IdentifierTable.cpp
    cfe/branches/release_37/lib/Basic/Module.cpp
    cfe/branches/release_37/lib/Basic/Targets.cpp
    cfe/branches/release_37/lib/Driver/Tools.cpp
    cfe/branches/release_37/lib/Frontend/CompilerInvocation.cpp
    cfe/branches/release_37/lib/Headers/CMakeLists.txt
    cfe/branches/release_37/lib/Headers/module.modulemap
    cfe/branches/release_37/lib/Headers/s390intrin.h
    cfe/branches/release_37/lib/Parse/Parser.cpp
    cfe/branches/release_37/lib/Sema/DeclSpec.cpp
    cfe/branches/release_37/lib/Sema/SemaExpr.cpp
    cfe/branches/release_37/lib/Sema/SemaExprCXX.cpp
    cfe/branches/release_37/lib/Sema/SemaLookup.cpp
    cfe/branches/release_37/test/Preprocessor/predefined-arch-macros.c

Propchange: cfe/branches/release_37/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jul 30 17:47:41 2015
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:242244,242285,242293,242297,242313,242382,242422,242499,242574,242600,242660,242662,242667,242678,242766,242854,242905,242973,243018,243048,243098,243101,243105,243144,243153,243196,243206,243277,243280,243285,243289,243343,243417,243463,243538,243594
+/cfe/trunk:242244,242285,242293,242297,242313,242382,242422,242499,242574,242600,242660,242662,242667,242678,242766,242854,242905,242973,243018,243048,243098,243101,243105,243144,243153,243196,243206,243277,243280,243285,243289,243343,243417,243463,243538,243594,243642-243644
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_37/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/include/clang/Basic/DiagnosticParseKinds.td?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/branches/release_37/include/clang/Basic/DiagnosticParseKinds.td Thu Jul 30 17:47:41 2015
@@ -358,6 +358,10 @@ def err_invalid_pixel_decl_spec_combinat
   "'%0' declaration specifier not allowed here">;
 def err_invalid_vector_bool_decl_spec : Error<
   "cannot use '%0' with '__vector bool'">;
+def err_invalid_vector_long_decl_spec : Error<
+  "cannot use 'long' with '__vector'">;
+def err_invalid_vector_float_decl_spec : Error<
+  "cannot use 'float' with '__vector'">;
 def err_invalid_vector_double_decl_spec : Error <
   "use of 'double' with '__vector' requires VSX support to be enabled "
   "(available on POWER7 or later)">;

Modified: cfe/branches/release_37/include/clang/Basic/LangOptions.def
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/include/clang/Basic/LangOptions.def?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/include/clang/Basic/LangOptions.def (original)
+++ cfe/branches/release_37/include/clang/Basic/LangOptions.def Thu Jul 30 17:47:41 2015
@@ -104,6 +104,7 @@ LANGOPT(WritableStrings   , 1, 0, "writa
 LANGOPT(ConstStrings      , 1, 0, "const-qualified string support")
 LANGOPT(LaxVectorConversions , 1, 1, "lax vector conversions")
 LANGOPT(AltiVec           , 1, 0, "AltiVec-style vector initializers")
+LANGOPT(ZVector           , 1, 0, "System z vector extensions")
 LANGOPT(Exceptions        , 1, 0, "exception handling")
 LANGOPT(ObjCExceptions    , 1, 0, "Objective-C exceptions")
 LANGOPT(CXXExceptions     , 1, 0, "C++ exceptions")

Modified: cfe/branches/release_37/include/clang/Basic/TokenKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/include/clang/Basic/TokenKinds.def?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/include/clang/Basic/TokenKinds.def (original)
+++ cfe/branches/release_37/include/clang/Basic/TokenKinds.def Thu Jul 30 17:47:41 2015
@@ -239,6 +239,8 @@ PUNCTUATOR(greatergreatergreater, ">>>")
 //   KEYOPENCL  - This is a keyword in OpenCL
 //   KEYNOOPENCL  - This is a keyword that is not supported in OpenCL
 //   KEYALTIVEC - This is a keyword in AltiVec
+//   KEYZVECTOR - This is a keyword for the System z vector extensions,
+//                which are heavily based on AltiVec
 //   KEYBORLAND - This is a keyword if Borland extensions are enabled
 //   BOOLSUPPORT - This is a keyword if 'bool' is a built-in type
 //   HALFSUPPORT - This is a keyword if 'half' is a built-in type
@@ -501,7 +503,7 @@ ALIAS("write_only", __write_only    , KE
 ALIAS("read_write", __read_write    , KEYOPENCL)
 // OpenCL builtins
 KEYWORD(__builtin_astype            , KEYOPENCL)
-KEYWORD(vec_step                    , KEYOPENCL|KEYALTIVEC)
+KEYWORD(vec_step                    , KEYOPENCL|KEYALTIVEC|KEYZVECTOR)
 
 // OpenMP Type Traits
 KEYWORD(__builtin_omp_required_simd_align, KEYALL)
@@ -510,9 +512,9 @@ KEYWORD(__builtin_omp_required_simd_alig
 KEYWORD(__pascal                    , KEYALL)
 
 // Altivec Extension.
-KEYWORD(__vector                    , KEYALTIVEC)
+KEYWORD(__vector                    , KEYALTIVEC|KEYZVECTOR)
 KEYWORD(__pixel                     , KEYALTIVEC)
-KEYWORD(__bool                      , KEYALTIVEC)
+KEYWORD(__bool                      , KEYALTIVEC|KEYZVECTOR)
 
 // ARM NEON extensions.
 ALIAS("__fp16", half                , KEYALL)

Modified: cfe/branches/release_37/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/include/clang/Driver/Options.td?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/include/clang/Driver/Options.td (original)
+++ cfe/branches/release_37/include/clang/Driver/Options.td Thu Jul 30 17:47:41 2015
@@ -1351,6 +1351,13 @@ def mno_altivec : Flag<["-"], "mno-altiv
 def mvx : Flag<["-"], "mvx">, Group<m_Group>;
 def mno_vx : Flag<["-"], "mno-vx">, Group<m_Group>;
 
+def fzvector : Flag<["-"], "fzvector">, Group<f_Group>, Flags<[CC1Option]>,
+  HelpText<"Enable System z vector language extension">;
+def fno_zvector : Flag<["-"], "fno-zvector">, Group<f_Group>,
+  Flags<[CC1Option]>;
+def mzvector : Flag<["-"], "mzvector">, Alias<fzvector>;
+def mno_zvector : Flag<["-"], "mno-zvector">, Alias<fno_zvector>;
+
 def mno_warn_nonportable_cfstrings : Flag<["-"], "mno-warn-nonportable-cfstrings">, Group<m_Group>;
 def mno_omit_leaf_frame_pointer : Flag<["-"], "mno-omit-leaf-frame-pointer">, Group<m_Group>;
 def momit_leaf_frame_pointer : Flag<["-"], "momit-leaf-frame-pointer">, Group<m_Group>,

Modified: cfe/branches/release_37/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/include/clang/Parse/Parser.h?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/include/clang/Parse/Parser.h (original)
+++ cfe/branches/release_37/include/clang/Parse/Parser.h Thu Jul 30 17:47:41 2015
@@ -108,12 +108,13 @@ class Parser : public CodeCompletionHand
   /// Ident_super - IdentifierInfo for "super", to support fast
   /// comparison.
   IdentifierInfo *Ident_super;
-  /// Ident_vector, Ident_pixel, Ident_bool - cached IdentifierInfo's
-  /// for "vector", "pixel", and "bool" fast comparison.  Only present
-  /// if AltiVec enabled.
+  /// Ident_vector, Ident_bool - cached IdentifierInfos for "vector" and
+  /// "bool" fast comparison.  Only present if AltiVec or ZVector are enabled.
   IdentifierInfo *Ident_vector;
-  IdentifierInfo *Ident_pixel;
   IdentifierInfo *Ident_bool;
+  /// Ident_pixel - cached IdentifierInfos for "pixel" fast comparison.
+  /// Only present if AltiVec enabled.
+  IdentifierInfo *Ident_pixel;
 
   /// Objective-C contextual keywords.
   mutable IdentifierInfo *Ident_instancetype;
@@ -605,10 +606,12 @@ private:
   bool TryAltiVecToken(DeclSpec &DS, SourceLocation Loc,
                        const char *&PrevSpec, unsigned &DiagID,
                        bool &isInvalid) {
-    if (!getLangOpts().AltiVec ||
-        (Tok.getIdentifierInfo() != Ident_vector &&
-         Tok.getIdentifierInfo() != Ident_pixel &&
-         Tok.getIdentifierInfo() != Ident_bool))
+    if (!getLangOpts().AltiVec && !getLangOpts().ZVector)
+      return false;
+
+    if (Tok.getIdentifierInfo() != Ident_vector &&
+        Tok.getIdentifierInfo() != Ident_bool &&
+        (!getLangOpts().AltiVec || Tok.getIdentifierInfo() != Ident_pixel))
       return false;
 
     return TryAltiVecTokenOutOfLine(DS, Loc, PrevSpec, DiagID, isInvalid);
@@ -618,7 +621,7 @@ private:
   /// identifier token, replacing it with the non-context-sensitive __vector.
   /// This returns true if the token was replaced.
   bool TryAltiVecVectorToken() {
-    if (!getLangOpts().AltiVec ||
+    if ((!getLangOpts().AltiVec && !getLangOpts().ZVector) ||
         Tok.getIdentifierInfo() != Ident_vector) return false;
     return TryAltiVecVectorTokenOutOfLine();
   }

Modified: cfe/branches/release_37/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/include/clang/Sema/Sema.h?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/include/clang/Sema/Sema.h (original)
+++ cfe/branches/release_37/include/clang/Sema/Sema.h Thu Jul 30 17:47:41 2015
@@ -8363,7 +8363,8 @@ public:
 
   /// type checking for vector binary operators.
   QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
-                               SourceLocation Loc, bool IsCompAssign);
+                               SourceLocation Loc, bool IsCompAssign,
+                               bool AllowBothBool, bool AllowBoolConversion);
   QualType GetSignedVectorType(QualType V);
   QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS,
                                       SourceLocation Loc, bool isRelational);

Modified: cfe/branches/release_37/lib/Basic/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/lib/Basic/IdentifierTable.cpp?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/lib/Basic/IdentifierTable.cpp (original)
+++ cfe/branches/release_37/lib/Basic/IdentifierTable.cpp Thu Jul 30 17:47:41 2015
@@ -110,7 +110,8 @@ namespace {
     HALFSUPPORT = 0x08000,
     KEYCONCEPTS = 0x10000,
     KEYOBJC2    = 0x20000,
-    KEYALL = (0x3ffff & ~KEYNOMS18 &
+    KEYZVECTOR  = 0x40000,
+    KEYALL = (0x7ffff & ~KEYNOMS18 &
               ~KEYNOOPENCL) // KEYNOMS18 and KEYNOOPENCL are used to exclude.
   };
 

Modified: cfe/branches/release_37/lib/Basic/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/lib/Basic/Module.cpp?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/lib/Basic/Module.cpp (original)
+++ cfe/branches/release_37/lib/Basic/Module.cpp Thu Jul 30 17:47:41 2015
@@ -67,6 +67,7 @@ static bool hasFeature(StringRef Feature
                         .Case("objc_arc", LangOpts.ObjCAutoRefCount)
                         .Case("opencl", LangOpts.OpenCL)
                         .Case("tls", Target.isTLSSupported())
+                        .Case("zvector", LangOpts.ZVector)
                         .Default(Target.hasFeature(Feature));
   if (!HasFeature)
     HasFeature = std::find(LangOpts.ModuleFeatures.begin(),

Modified: cfe/branches/release_37/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/lib/Basic/Targets.cpp?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/lib/Basic/Targets.cpp (original)
+++ cfe/branches/release_37/lib/Basic/Targets.cpp Thu Jul 30 17:47:41 2015
@@ -5725,6 +5725,8 @@ public:
     Builder.defineMacro("__LONG_DOUBLE_128__");
     if (HasTransactionalExecution)
       Builder.defineMacro("__HTM__");
+    if (Opts.ZVector)
+      Builder.defineMacro("__VEC__", "10301");
   }
   void getTargetBuiltins(const Builtin::Info *&Records,
                          unsigned &NumRecords) const override {

Modified: cfe/branches/release_37/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/lib/Driver/Tools.cpp?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/lib/Driver/Tools.cpp (original)
+++ cfe/branches/release_37/lib/Driver/Tools.cpp Thu Jul 30 17:47:41 2015
@@ -4049,9 +4049,11 @@ void Clang::ConstructJob(Compilation &C,
   Args.AddLastArg(CmdArgs, options::OPT_fstandalone_debug);
   Args.AddLastArg(CmdArgs, options::OPT_fno_standalone_debug);
   Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
-  // AltiVec language extensions aren't relevant for assembling.
-  if (!isa<PreprocessJobAction>(JA) || Output.getType() != types::TY_PP_Asm)
+  // AltiVec-like language extensions aren't relevant for assembling.
+  if (!isa<PreprocessJobAction>(JA) || Output.getType() != types::TY_PP_Asm) {
     Args.AddLastArg(CmdArgs, options::OPT_faltivec);
+    Args.AddLastArg(CmdArgs, options::OPT_fzvector);
+  }
   Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_show_template_tree);
   Args.AddLastArg(CmdArgs, options::OPT_fno_elide_type);
 
@@ -4096,6 +4098,12 @@ void Clang::ConstructJob(Compilation &C,
                                                        << "ppc/ppc64/ppc64le";
   }
 
+  // -fzvector is incompatible with -faltivec.
+  if (Arg *A = Args.getLastArg(options::OPT_fzvector))
+    if (Args.hasArg(options::OPT_faltivec))
+      D.Diag(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args)
+                                                      << "-faltivec";
+
   if (getToolChain().SupportsProfiling())
     Args.AddLastArg(CmdArgs, options::OPT_pg);
 

Modified: cfe/branches/release_37/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/lib/Frontend/CompilerInvocation.cpp?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/branches/release_37/lib/Frontend/CompilerInvocation.cpp Thu Jul 30 17:47:41 2015
@@ -1260,6 +1260,7 @@ void CompilerInvocation::setLangDefaults
   // OpenCL has some additional defaults.
   if (Opts.OpenCL) {
     Opts.AltiVec = 0;
+    Opts.ZVector = 0;
     Opts.CXXOperatorNames = 1;
     Opts.LaxVectorConversions = 0;
     Opts.DefaultFPContract = 1;
@@ -1448,6 +1449,9 @@ static void ParseLangArgs(LangOptions &O
   if (Args.hasArg(OPT_faltivec))
     Opts.AltiVec = 1;
 
+  if (Args.hasArg(OPT_fzvector))
+    Opts.ZVector = 1;
+
   if (Args.hasArg(OPT_pthread))
     Opts.POSIXThreads = 1;
 

Modified: cfe/branches/release_37/lib/Headers/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/lib/Headers/CMakeLists.txt?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/lib/Headers/CMakeLists.txt (original)
+++ cfe/branches/release_37/lib/Headers/CMakeLists.txt Thu Jul 30 17:47:41 2015
@@ -59,6 +59,7 @@ set(files
   unwind.h
   vadefs.h
   varargs.h
+  vecintrin.h
   __wmmintrin_aes.h
   wmmintrin.h
   __wmmintrin_pclmul.h

Modified: cfe/branches/release_37/lib/Headers/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/lib/Headers/module.modulemap?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/lib/Headers/module.modulemap (original)
+++ cfe/branches/release_37/lib/Headers/module.modulemap Thu Jul 30 17:47:41 2015
@@ -158,6 +158,11 @@ module _Builtin_intrinsics [system] [ext
       header "htmintrin.h"
       header "htmxlintrin.h"
     }
+
+    explicit module zvector {
+      requires zvector, vx
+      header "vecintrin.h"
+    }
   }
 }
 

Modified: cfe/branches/release_37/lib/Headers/s390intrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/lib/Headers/s390intrin.h?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/lib/Headers/s390intrin.h (original)
+++ cfe/branches/release_37/lib/Headers/s390intrin.h Thu Jul 30 17:47:41 2015
@@ -32,4 +32,8 @@
 #include <htmintrin.h>
 #endif
 
+#ifdef __VEC__
+#include <vecintrin.h>
+#endif
+
 #endif /* __S390INTRIN_H*/

Modified: cfe/branches/release_37/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/lib/Parse/Parser.cpp?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/lib/Parse/Parser.cpp (original)
+++ cfe/branches/release_37/lib/Parse/Parser.cpp Thu Jul 30 17:47:41 2015
@@ -476,11 +476,15 @@ void Parser::Initialize() {
 
   Ident_super = &PP.getIdentifierTable().get("super");
 
-  if (getLangOpts().AltiVec) {
+  Ident_vector = nullptr;
+  Ident_bool = nullptr;
+  Ident_pixel = nullptr;
+  if (getLangOpts().AltiVec || getLangOpts().ZVector) {
     Ident_vector = &PP.getIdentifierTable().get("vector");
-    Ident_pixel = &PP.getIdentifierTable().get("pixel");
     Ident_bool = &PP.getIdentifierTable().get("bool");
   }
+  if (getLangOpts().AltiVec)
+    Ident_pixel = &PP.getIdentifierTable().get("pixel");
 
   Ident_introduced = nullptr;
   Ident_deprecated = nullptr;

Modified: cfe/branches/release_37/lib/Sema/DeclSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/lib/Sema/DeclSpec.cpp?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/lib/Sema/DeclSpec.cpp (original)
+++ cfe/branches/release_37/lib/Sema/DeclSpec.cpp Thu Jul 30 17:47:41 2015
@@ -987,10 +987,11 @@ void DeclSpec::Finish(DiagnosticsEngine
         Diag(D, TSWLoc, diag::err_invalid_vector_bool_decl_spec)
           << getSpecifierName((TSW)TypeSpecWidth);
 
-      // vector bool long long requires VSX support.
+      // vector bool long long requires VSX support or ZVector.
       if ((TypeSpecWidth == TSW_longlong) &&
           (!PP.getTargetInfo().hasFeature("vsx")) &&
-          (!PP.getTargetInfo().hasFeature("power8-vector")))
+          (!PP.getTargetInfo().hasFeature("power8-vector")) &&
+          !PP.getLangOpts().ZVector)
         Diag(D, TSTLoc, diag::err_invalid_vector_long_long_decl_spec);
 
       // Elements of vector bool are interpreted as unsigned. (PIM 2.1)
@@ -999,14 +1000,23 @@ void DeclSpec::Finish(DiagnosticsEngine
         TypeSpecSign = TSS_unsigned;
     } else if (TypeSpecType == TST_double) {
       // vector long double and vector long long double are never allowed.
-      // vector double is OK for Power7 and later.
+      // vector double is OK for Power7 and later, and ZVector.
       if (TypeSpecWidth == TSW_long || TypeSpecWidth == TSW_longlong)
         Diag(D, TSWLoc, diag::err_invalid_vector_long_double_decl_spec);
-      else if (!PP.getTargetInfo().hasFeature("vsx"))
+      else if (!PP.getTargetInfo().hasFeature("vsx") &&
+               !PP.getLangOpts().ZVector)
         Diag(D, TSTLoc, diag::err_invalid_vector_double_decl_spec);
+    } else if (TypeSpecType == TST_float) {
+      // vector float is unsupported for ZVector.
+      if (PP.getLangOpts().ZVector)
+        Diag(D, TSTLoc, diag::err_invalid_vector_float_decl_spec);
     } else if (TypeSpecWidth == TSW_long) {
-      Diag(D, TSWLoc, diag::warn_vector_long_decl_spec_combination)
-        << getSpecifierName((TST)TypeSpecType, Policy);
+      // vector long is unsupported for ZVector and deprecated for AltiVec.
+      if (PP.getLangOpts().ZVector)
+        Diag(D, TSWLoc, diag::err_invalid_vector_long_decl_spec);
+      else
+        Diag(D, TSWLoc, diag::warn_vector_long_decl_spec_combination)
+          << getSpecifierName((TST)TypeSpecType, Policy);
     }
 
     if (TypeAltiVecPixel) {

Modified: cfe/branches/release_37/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/lib/Sema/SemaExpr.cpp?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/lib/Sema/SemaExpr.cpp (original)
+++ cfe/branches/release_37/lib/Sema/SemaExpr.cpp Thu Jul 30 17:47:41 2015
@@ -5518,7 +5518,7 @@ Sema::ActOnCastExpr(Scope *S, SourceLoca
   // i.e. all the elements are integer constants.
   ParenExpr *PE = dyn_cast<ParenExpr>(CastExpr);
   ParenListExpr *PLE = dyn_cast<ParenListExpr>(CastExpr);
-  if ((getLangOpts().AltiVec || getLangOpts().OpenCL)
+  if ((getLangOpts().AltiVec || getLangOpts().ZVector || getLangOpts().OpenCL)
        && castType->isVectorType() && (PE || PLE)) {
     if (PLE && PLE->getNumExprs() == 0) {
       Diag(PLE->getExprLoc(), diag::err_altivec_empty_initializer);
@@ -6075,7 +6075,9 @@ OpenCLCheckVectorConditional(Sema &S, Ex
   if (LHS.get()->getType()->isVectorType() ||
       RHS.get()->getType()->isVectorType()) {
     QualType VecResTy = S.CheckVectorOperands(LHS, RHS, QuestionLoc,
-                                              /*isCompAssign*/false);
+                                              /*isCompAssign*/false,
+                                              /*AllowBothBool*/true,
+                                              /*AllowBoolConversions*/false);
     if (VecResTy.isNull()) return QualType();
     // The result type must match the condition type as specified in
     // OpenCL v1.1 s6.11.6.
@@ -6126,7 +6128,9 @@ QualType Sema::CheckConditionalOperands(
   // Now check the two expressions.
   if (LHS.get()->getType()->isVectorType() ||
       RHS.get()->getType()->isVectorType())
-    return CheckVectorOperands(LHS, RHS, QuestionLoc, /*isCompAssign*/false);
+    return CheckVectorOperands(LHS, RHS, QuestionLoc, /*isCompAssign*/false,
+                               /*AllowBothBool*/true,
+                               /*AllowBoolConversions*/false);
 
   QualType ResTy = UsualArithmeticConversions(LHS, RHS);
   if (LHS.isInvalid() || RHS.isInvalid())
@@ -7267,7 +7271,9 @@ static bool tryVectorConvertAndSplat(Sem
 }
 
 QualType Sema::CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
-                                   SourceLocation Loc, bool IsCompAssign) {
+                                   SourceLocation Loc, bool IsCompAssign,
+                                   bool AllowBothBool,
+                                   bool AllowBoolConversions) {
   if (!IsCompAssign) {
     LHS = DefaultFunctionArrayLvalueConversion(LHS.get());
     if (LHS.isInvalid())
@@ -7282,14 +7288,21 @@ QualType Sema::CheckVectorOperands(ExprR
   QualType LHSType = LHS.get()->getType().getUnqualifiedType();
   QualType RHSType = RHS.get()->getType().getUnqualifiedType();
 
-  // If the vector types are identical, return.
-  if (Context.hasSameType(LHSType, RHSType))
-    return LHSType;
-
   const VectorType *LHSVecType = LHSType->getAs<VectorType>();
   const VectorType *RHSVecType = RHSType->getAs<VectorType>();
   assert(LHSVecType || RHSVecType);
 
+  // AltiVec-style "vector bool op vector bool" combinations are allowed
+  // for some operators but not others.
+  if (!AllowBothBool &&
+      LHSVecType && LHSVecType->getVectorKind() == VectorType::AltiVecBool &&
+      RHSVecType && RHSVecType->getVectorKind() == VectorType::AltiVecBool)
+    return InvalidOperands(Loc, LHS, RHS);
+
+  // If the vector types are identical, return.
+  if (Context.hasSameType(LHSType, RHSType))
+    return LHSType;
+
   // If we have compatible AltiVec and GCC vector types, use the AltiVec type.
   if (LHSVecType && RHSVecType &&
       Context.areCompatibleVectorTypes(LHSType, RHSType)) {
@@ -7303,6 +7316,28 @@ QualType Sema::CheckVectorOperands(ExprR
     return RHSType;
   }
 
+  // AllowBoolConversions says that bool and non-bool AltiVec vectors
+  // can be mixed, with the result being the non-bool type.  The non-bool
+  // operand must have integer element type.
+  if (AllowBoolConversions && LHSVecType && RHSVecType &&
+      LHSVecType->getNumElements() == RHSVecType->getNumElements() &&
+      (Context.getTypeSize(LHSVecType->getElementType()) ==
+       Context.getTypeSize(RHSVecType->getElementType()))) {
+    if (LHSVecType->getVectorKind() == VectorType::AltiVecVector &&
+        LHSVecType->getElementType()->isIntegerType() &&
+        RHSVecType->getVectorKind() == VectorType::AltiVecBool) {
+      RHS = ImpCastExprToType(RHS.get(), LHSType, CK_BitCast);
+      return LHSType;
+    }
+    if (!IsCompAssign &&
+        LHSVecType->getVectorKind() == VectorType::AltiVecBool &&
+        RHSVecType->getVectorKind() == VectorType::AltiVecVector &&
+        RHSVecType->getElementType()->isIntegerType()) {
+      LHS = ImpCastExprToType(LHS.get(), RHSType, CK_BitCast);
+      return RHSType;
+    }
+  }
+
   // If there's an ext-vector type and a scalar, try to convert the scalar to
   // the vector element type and splat.
   if (!RHSVecType && isa<ExtVectorType>(LHSVecType)) {
@@ -7391,7 +7426,9 @@ QualType Sema::CheckMultiplyDivideOperan
 
   if (LHS.get()->getType()->isVectorType() ||
       RHS.get()->getType()->isVectorType())
-    return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign);
+    return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign,
+                               /*AllowBothBool*/getLangOpts().AltiVec,
+                               /*AllowBoolConversions*/false);
 
   QualType compType = UsualArithmeticConversions(LHS, RHS, IsCompAssign);
   if (LHS.isInvalid() || RHS.isInvalid())
@@ -7420,7 +7457,9 @@ QualType Sema::CheckRemainderOperands(
       RHS.get()->getType()->isVectorType()) {
     if (LHS.get()->getType()->hasIntegerRepresentation() && 
         RHS.get()->getType()->hasIntegerRepresentation())
-      return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign);
+      return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign,
+                                 /*AllowBothBool*/getLangOpts().AltiVec,
+                                 /*AllowBoolConversions*/false);
     return InvalidOperands(Loc, LHS, RHS);
   }
 
@@ -7706,7 +7745,10 @@ QualType Sema::CheckAdditionOperands( //
 
   if (LHS.get()->getType()->isVectorType() ||
       RHS.get()->getType()->isVectorType()) {
-    QualType compType = CheckVectorOperands(LHS, RHS, Loc, CompLHSTy);
+    QualType compType = CheckVectorOperands(
+        LHS, RHS, Loc, CompLHSTy,
+        /*AllowBothBool*/getLangOpts().AltiVec,
+        /*AllowBoolConversions*/getLangOpts().ZVector);
     if (CompLHSTy) *CompLHSTy = compType;
     return compType;
   }
@@ -7781,7 +7823,10 @@ QualType Sema::CheckSubtractionOperands(
 
   if (LHS.get()->getType()->isVectorType() ||
       RHS.get()->getType()->isVectorType()) {
-    QualType compType = CheckVectorOperands(LHS, RHS, Loc, CompLHSTy);
+    QualType compType = CheckVectorOperands(
+        LHS, RHS, Loc, CompLHSTy,
+        /*AllowBothBool*/getLangOpts().AltiVec,
+        /*AllowBoolConversions*/getLangOpts().ZVector);
     if (CompLHSTy) *CompLHSTy = compType;
     return compType;
   }
@@ -8023,7 +8068,21 @@ QualType Sema::CheckShiftOperands(ExprRe
       RHS.get()->getType()->isVectorType()) {
     if (LangOpts.OpenCL)
       return checkOpenCLVectorShift(*this, LHS, RHS, Loc, IsCompAssign);
-    return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign);
+    if (LangOpts.ZVector) {
+      // The shift operators for the z vector extensions work basically
+      // like OpenCL shifts, except that neither the LHS nor the RHS is
+      // allowed to be a "vector bool".
+      if (auto LHSVecType = LHS.get()->getType()->getAs<VectorType>())
+        if (LHSVecType->getVectorKind() == VectorType::AltiVecBool)
+          return InvalidOperands(Loc, LHS, RHS);
+      if (auto RHSVecType = RHS.get()->getType()->getAs<VectorType>())
+        if (RHSVecType->getVectorKind() == VectorType::AltiVecBool)
+          return InvalidOperands(Loc, LHS, RHS);
+      return checkOpenCLVectorShift(*this, LHS, RHS, Loc, IsCompAssign);
+    }
+    return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign,
+                               /*AllowBothBool*/true,
+                               /*AllowBoolConversions*/false);
   }
 
   // Shifts don't perform usual arithmetic conversions, they just do integer
@@ -8797,7 +8856,9 @@ QualType Sema::CheckVectorCompareOperand
                                           bool IsRelational) {
   // Check to make sure we're operating on vectors of the same type and width,
   // Allowing one side to be a scalar of element type.
-  QualType vType = CheckVectorOperands(LHS, RHS, Loc, /*isCompAssign*/false);
+  QualType vType = CheckVectorOperands(LHS, RHS, Loc, /*isCompAssign*/false,
+                              /*AllowBothBool*/true,
+                              /*AllowBoolConversions*/getLangOpts().ZVector);
   if (vType.isNull())
     return vType;
 
@@ -8805,7 +8866,8 @@ QualType Sema::CheckVectorCompareOperand
 
   // If AltiVec, the comparison results in a numeric type, i.e.
   // bool for C++, int for C
-  if (vType->getAs<VectorType>()->getVectorKind() == VectorType::AltiVecVector)
+  if (getLangOpts().AltiVec &&
+      vType->getAs<VectorType>()->getVectorKind() == VectorType::AltiVecVector)
     return Context.getLogicalOperationType();
 
   // For non-floating point types, check for self-comparisons of the form
@@ -8839,7 +8901,9 @@ QualType Sema::CheckVectorLogicalOperand
                                           SourceLocation Loc) {
   // Ensure that either both operands are of the same vector type, or
   // one operand is of a vector type and the other is of its element type.
-  QualType vType = CheckVectorOperands(LHS, RHS, Loc, false);
+  QualType vType = CheckVectorOperands(LHS, RHS, Loc, false,
+                                       /*AllowBothBool*/true,
+                                       /*AllowBoolConversions*/false);
   if (vType.isNull())
     return InvalidOperands(Loc, LHS, RHS);
   if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion < 120 &&
@@ -8857,8 +8921,9 @@ inline QualType Sema::CheckBitwiseOperan
       RHS.get()->getType()->isVectorType()) {
     if (LHS.get()->getType()->hasIntegerRepresentation() &&
         RHS.get()->getType()->hasIntegerRepresentation())
-      return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign);
-    
+      return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign,
+                        /*AllowBothBool*/true,
+                        /*AllowBoolConversions*/getLangOpts().ZVector);
     return InvalidOperands(Loc, LHS, RHS);
   }
 
@@ -9472,6 +9537,10 @@ static QualType CheckIncrementDecrementO
                                           IsInc, IsPrefix);
   } else if (S.getLangOpts().AltiVec && ResType->isVectorType()) {
     // OK! ( C/C++ Language Extensions for CBEA(Version 2.6) 10.3 )
+  } else if (S.getLangOpts().ZVector && ResType->isVectorType() &&
+             (ResType->getAs<VectorType>()->getVectorKind() !=
+              VectorType::AltiVecBool)) {
+    // The z vector extensions allow ++ and -- for non-bool vectors.
   } else if(S.getLangOpts().OpenCL && ResType->isVectorType() &&
             ResType->getAs<VectorType>()->getElementType()->isIntegerType()) {
     // OpenCL V1.2 6.3 says dec/inc ops operate on integer vector types.
@@ -10552,8 +10621,13 @@ ExprResult Sema::CreateBuiltinUnaryOp(So
     resultType = Input.get()->getType();
     if (resultType->isDependentType())
       break;
-    if (resultType->isArithmeticType() || // C99 6.5.3.3p1
-        resultType->isVectorType()) 
+    if (resultType->isArithmeticType()) // C99 6.5.3.3p1
+      break;
+    else if (resultType->isVectorType() &&
+             // The z vector extensions don't allow + or - with bool vectors.
+             (!Context.getLangOpts().ZVector ||
+              resultType->getAs<VectorType>()->getVectorKind() !=
+              VectorType::AltiVecBool))
       break;
     else if (getLangOpts().CPlusPlus && // C++ [expr.unary.op]p6
              Opc == UO_Plus &&

Modified: cfe/branches/release_37/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/lib/Sema/SemaExprCXX.cpp?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/branches/release_37/lib/Sema/SemaExprCXX.cpp Thu Jul 30 17:47:41 2015
@@ -4950,7 +4950,9 @@ QualType Sema::CXXCheckConditionalOperan
 
   // Extension: conditional operator involving vector types.
   if (LTy->isVectorType() || RTy->isVectorType())
-    return CheckVectorOperands(LHS, RHS, QuestionLoc, /*isCompAssign*/false);
+    return CheckVectorOperands(LHS, RHS, QuestionLoc, /*isCompAssign*/false,
+                               /*AllowBothBool*/true,
+                               /*AllowBoolConversions*/false);
 
   //   -- The second and third operands have arithmetic or enumeration type;
   //      the usual arithmetic conversions are performed to bring them to a

Modified: cfe/branches/release_37/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/lib/Sema/SemaLookup.cpp?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/lib/Sema/SemaLookup.cpp (original)
+++ cfe/branches/release_37/lib/Sema/SemaLookup.cpp Thu Jul 30 17:47:41 2015
@@ -4245,7 +4245,7 @@ std::unique_ptr<TypoCorrectionConsumer>
   // Don't try to correct the identifier "vector" when in AltiVec mode.
   // TODO: Figure out why typo correction misbehaves in this case, fix it, and
   // remove this workaround.
-  if (getLangOpts().AltiVec && Typo->isStr("vector"))
+  if ((getLangOpts().AltiVec || getLangOpts().ZVector) && Typo->isStr("vector"))
     return nullptr;
 
   // Provide a stop gap for files that are just seriously broken.  Trying

Modified: cfe/branches/release_37/test/Preprocessor/predefined-arch-macros.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/test/Preprocessor/predefined-arch-macros.c?rev=243699&r1=243698&r2=243699&view=diff
==============================================================================
--- cfe/branches/release_37/test/Preprocessor/predefined-arch-macros.c (original)
+++ cfe/branches/release_37/test/Preprocessor/predefined-arch-macros.c Thu Jul 30 17:47:41 2015
@@ -1748,3 +1748,12 @@
 // RUN:   | FileCheck %s -check-prefix=CHECK_SYSTEMZ_HTM
 //
 // CHECK_SYSTEMZ_HTM: #define __HTM__ 1
+//
+// RUN: %clang -fzvector -E -dM %s -o - 2>&1 \
+// RUN:     -target s390x-unknown-linux \
+// RUN:   | FileCheck %s -check-prefix=CHECK_SYSTEMZ_ZVECTOR
+// RUN: %clang -mzvector -E -dM %s -o - 2>&1 \
+// RUN:     -target s390x-unknown-linux \
+// RUN:   | FileCheck %s -check-prefix=CHECK_SYSTEMZ_ZVECTOR
+//
+// CHECK_SYSTEMZ_ZVECTOR: #define __VEC__ 10301





More information about the llvm-branch-commits mailing list