Skip to content

Commit

Permalink
Merging r243642, r243643, and r243644:
Browse files Browse the repository at this point in the history
------------------------------------------------------------------------
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.
------------------------------------------------------------------------

llvm-svn: 243699
  • Loading branch information
zmodem committed Jul 30, 2015
1 parent 6b7585c commit 6e8ff10
Show file tree
Hide file tree
Showing 25 changed files with 16,485 additions and 46 deletions.
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/DiagnosticParseKinds.td
Expand Up @@ -358,6 +358,10 @@ def err_invalid_pixel_decl_spec_combination : Error<
"'%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)">;
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Basic/LangOptions.def
Expand Up @@ -104,6 +104,7 @@ LANGOPT(WritableStrings , 1, 0, "writable string support")
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")
Expand Down
8 changes: 5 additions & 3 deletions clang/include/clang/Basic/TokenKinds.def
Expand Up @@ -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
Expand Down Expand Up @@ -501,7 +503,7 @@ ALIAS("write_only", __write_only , KEYOPENCL)
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)
Expand All @@ -510,9 +512,9 @@ KEYWORD(__builtin_omp_required_simd_align, KEYALL)
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)
Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/Driver/Options.td
Expand Up @@ -1351,6 +1351,13 @@ def mno_altivec : Flag<["-"], "mno-altivec">, Alias<fno_altivec>;
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>,
Expand Down
21 changes: 12 additions & 9 deletions clang/include/clang/Parse/Parser.h
Expand Up @@ -108,12 +108,13 @@ class Parser : public CodeCompletionHandler {
/// 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;
Expand Down Expand Up @@ -605,10 +606,12 @@ class Parser : public CodeCompletionHandler {
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);
Expand All @@ -618,7 +621,7 @@ class Parser : public CodeCompletionHandler {
/// 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();
}
Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/Sema/Sema.h
Expand Up @@ -8363,7 +8363,8 @@ class Sema {

/// 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);
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Basic/IdentifierTable.cpp
Expand Up @@ -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.
};

Expand Down
1 change: 1 addition & 0 deletions clang/lib/Basic/Module.cpp
Expand Up @@ -67,6 +67,7 @@ static bool hasFeature(StringRef Feature, const LangOptions &LangOpts,
.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(),
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Basic/Targets.cpp
Expand Up @@ -5725,6 +5725,8 @@ class SystemZTargetInfo : public TargetInfo {
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 {
Expand Down
12 changes: 10 additions & 2 deletions clang/lib/Driver/Tools.cpp
Expand Up @@ -4049,9 +4049,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
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);

Expand Down Expand Up @@ -4096,6 +4098,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
<< "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);

Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Frontend/CompilerInvocation.cpp
Expand Up @@ -1260,6 +1260,7 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
// OpenCL has some additional defaults.
if (Opts.OpenCL) {
Opts.AltiVec = 0;
Opts.ZVector = 0;
Opts.CXXOperatorNames = 1;
Opts.LaxVectorConversions = 0;
Opts.DefaultFPContract = 1;
Expand Down Expand Up @@ -1448,6 +1449,9 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
if (Args.hasArg(OPT_faltivec))
Opts.AltiVec = 1;

if (Args.hasArg(OPT_fzvector))
Opts.ZVector = 1;

if (Args.hasArg(OPT_pthread))
Opts.POSIXThreads = 1;

Expand Down
1 change: 1 addition & 0 deletions clang/lib/Headers/CMakeLists.txt
Expand Up @@ -59,6 +59,7 @@ set(files
unwind.h
vadefs.h
varargs.h
vecintrin.h
__wmmintrin_aes.h
wmmintrin.h
__wmmintrin_pclmul.h
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Headers/module.modulemap
Expand Up @@ -158,6 +158,11 @@ module _Builtin_intrinsics [system] [extern_c] {
header "htmintrin.h"
header "htmxlintrin.h"
}

explicit module zvector {
requires zvector, vx
header "vecintrin.h"
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Headers/s390intrin.h
Expand Up @@ -32,4 +32,8 @@
#include <htmintrin.h>
#endif

#ifdef __VEC__
#include <vecintrin.h>
#endif

#endif /* __S390INTRIN_H*/

0 comments on commit 6e8ff10

Please sign in to comment.