Index: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt =================================================================== --- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt +++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt @@ -41,6 +41,7 @@ add_subdirectory(objc) add_subdirectory(performance) add_subdirectory(plugin) +add_subdirectory(portability) add_subdirectory(readability) add_subdirectory(tool) add_subdirectory(utils) Index: clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt =================================================================== --- clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt +++ clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt @@ -19,6 +19,7 @@ clangTidyMPIModule clangTidyObjCModule clangTidyPerformanceModule + clangTidyPortabilityModule clangTidyReadabilityModule clangTooling ) Index: clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp +++ clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp @@ -118,6 +118,11 @@ static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination = PerformanceModuleAnchorSource; +// This anchor is used to force the linker to link the PortabilityModule. +extern volatile int PortabilityModuleAnchorSource; +static int LLVM_ATTRIBUTE_UNUSED PortabilityModuleAnchorDestination = + PortabilityModuleAnchorSource; + // This anchor is used to force the linker to link the ReadabilityModule. extern volatile int ReadabilityModuleAnchorSource; static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination = Index: clang-tools-extra/trunk/clang-tidy/portability/CMakeLists.txt =================================================================== --- clang-tools-extra/trunk/clang-tidy/portability/CMakeLists.txt +++ clang-tools-extra/trunk/clang-tidy/portability/CMakeLists.txt @@ -0,0 +1,15 @@ +set(LLVM_LINK_COMPONENTS support) + +add_clang_library(clangTidyPortabilityModule + PortabilityTidyModule.cpp + SIMDIntrinsicsCheck.cpp + + LINK_LIBS + clangAST + clangASTMatchers + clangBasic + clangLex + clangTidy + clangTidyUtils + clangTooling + ) Index: clang-tools-extra/trunk/clang-tidy/portability/PortabilityTidyModule.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/portability/PortabilityTidyModule.cpp +++ clang-tools-extra/trunk/clang-tidy/portability/PortabilityTidyModule.cpp @@ -0,0 +1,38 @@ +//===--- PortabilityTidyModule.cpp - clang-tidy ---------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "../ClangTidy.h" +#include "../ClangTidyModule.h" +#include "../ClangTidyModuleRegistry.h" +#include "SIMDIntrinsicsCheck.h" + +namespace clang { +namespace tidy { +namespace portability { + +class PortabilityModule : public ClangTidyModule { +public: + void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + CheckFactories.registerCheck( + "portability-simd-intrinsics"); + } +}; + +// Register the PortabilityModule using this statically initialized variable. +static ClangTidyModuleRegistry::Add + X("portability-module", "Adds portability-related checks."); + +} // namespace portability + +// This anchor is used to force the linker to link in the generated object file +// and thus register the PortabilityModule. +volatile int PortabilityModuleAnchorSource = 0; + +} // namespace tidy +} // namespace clang Index: clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.h =================================================================== --- clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.h +++ clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.h @@ -0,0 +1,42 @@ +//===--- SIMDIntrinsicsCheck.h - clang-tidy----------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H + +#include "../ClangTidy.h" + +#include "llvm/ADT/SmallString.h" + +namespace clang { +namespace tidy { +namespace portability { + +/// Find SIMD intrinsics calls and suggest std::experimental::simd alternatives. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/portability-simd-intrinsics.html +class SIMDIntrinsicsCheck : public ClangTidyCheck { +public: + SIMDIntrinsicsCheck(StringRef Name, ClangTidyContext *Context); + + void storeOptions(ClangTidyOptions::OptionMap &Opts) override; + void registerMatchers(ast_matchers::MatchFinder *Finder) override; + void check(const ast_matchers::MatchFinder::MatchResult &Result) override; + + private: + llvm::SmallString<32> Std; + const bool Suggest; +}; + +} // namespace portability +} // namespace tidy +} // namespace clang + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H Index: clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.cpp @@ -0,0 +1,160 @@ +//===--- SIMDIntrinsicsCheck.cpp - clang-tidy------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "SIMDIntrinsicsCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/Triple.h" +#include "llvm/Support/Regex.h" + +using namespace clang::ast_matchers; + +namespace clang { +namespace tidy { +namespace portability { + +namespace { + +// If the callee has parameter of VectorType or pointer to VectorType, +// or the return type is VectorType, we consider it a vector function +// and a candidate for checking. +AST_MATCHER(FunctionDecl, isVectorFunction) { + bool IsVector = Node.getReturnType()->isVectorType(); + for (const ParmVarDecl *Parm : Node.parameters()) { + QualType Type = Parm->getType(); + if (Type->isPointerType()) + Type = Type->getPointeeType(); + if (Type->isVectorType()) + IsVector = true; + } + return IsVector; +} + +} // namespace + +static StringRef TrySuggestPPC(StringRef Name) { + if (!Name.consume_front("vec_")) + return {}; + + static const llvm::StringMap Mapping{ + // [simd.alg] + {"max", "$std::max"}, + {"min", "$std::min"}, + + // [simd.binary] + {"add", "operator+ on $simd objects"}, + {"sub", "operator- on $simd objects"}, + {"mul", "operator* on $simd objects"}, + }; + + auto It = Mapping.find(Name); + if (It != Mapping.end()) + return It->second; + return {}; +} + +static StringRef TrySuggestX86(StringRef Name) { + if (!(Name.consume_front("_mm_") || Name.consume_front("_mm256_") || + Name.consume_front("_mm512_"))) + return {}; + + // [simd.alg] + if (Name.startswith("max_")) + return "$simd::max"; + if (Name.startswith("min_")) + return "$simd::min"; + + // [simd.binary] + if (Name.startswith("add_")) + return "operator+ on $simd objects"; + if (Name.startswith("sub_")) + return "operator- on $simd objects"; + if (Name.startswith("mul_")) + return "operator* on $simd objects"; + + return {}; +} + +SIMDIntrinsicsCheck::SIMDIntrinsicsCheck(StringRef Name, + ClangTidyContext *Context) + : ClangTidyCheck(Name, Context), Std(Options.get("Std", "")), + Suggest(Options.get("Suggest", 0) != 0) {} + +void SIMDIntrinsicsCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { + Options.store(Opts, "Std", ""); + Options.store(Opts, "Suggest", 0); +} + +void SIMDIntrinsicsCheck::registerMatchers(MatchFinder *Finder) { + if (!getLangOpts().CPlusPlus11) + return; + // If Std is not specified, infer it from the language options. + // libcxx implementation backports it to C++11 std::experimental::simd. + if (Std.empty()) + Std = getLangOpts().CPlusPlus2a ? "std" : "std::experimental"; + + Finder->addMatcher(callExpr(callee(functionDecl(allOf( + matchesName("^::(_mm_|_mm256_|_mm512_|vec_)"), + isVectorFunction()))), + unless(isExpansionInSystemHeader())) + .bind("call"), + this); +} + +void SIMDIntrinsicsCheck::check(const MatchFinder::MatchResult &Result) { + const auto *Call = Result.Nodes.getNodeAs("call"); + assert(Call != nullptr); + const FunctionDecl *Callee = Call->getDirectCallee(); + if (!Callee) + return; + + StringRef Old = Callee->getName(); + StringRef New; + llvm::Triple::ArchType Arch = + Result.Context->getTargetInfo().getTriple().getArch(); + + // We warn or suggest if this SIMD intrinsic function has a std::simd + // replacement. + switch (Arch) { + default: + break; + case llvm::Triple::ppc: + case llvm::Triple::ppc64: + case llvm::Triple::ppc64le: + New = TrySuggestPPC(Old); + break; + case llvm::Triple::x86: + case llvm::Triple::x86_64: + New = TrySuggestX86(Old); + break; + } + + // We have found a std::simd replacement. + if (!New.empty()) { + std::string Message; + // If Suggest is true, give a P0214 alternative, otherwise point it out it + // is non-portable. + if (Suggest) { + Message = (Twine("'") + Old + "' can be replaced by " + New).str(); + Message = llvm::Regex("\\$std").sub(Std, Message); + Message = + llvm::Regex("\\$simd").sub((Std.str() + "::simd").str(), Message); + } else { + Message = (Twine("'") + Old + "' is a non-portable " + + llvm::Triple::getArchTypeName(Arch) + " intrinsic function") + .str(); + } + diag(Call->getExprLoc(), Message); + } +} + +} // namespace portability +} // namespace tidy +} // namespace clang Index: clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt =================================================================== --- clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt +++ clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt @@ -24,7 +24,6 @@ RedundantStringCStrCheck.cpp RedundantSmartptrGetCheck.cpp RedundantStringInitCheck.cpp - SIMDIntrinsicsCheck.cpp SimplifyBooleanExprCheck.cpp StaticAccessedThroughInstanceCheck.cpp StaticDefinitionInAnonymousNamespaceCheck.cpp Index: clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp +++ clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp @@ -31,7 +31,6 @@ #include "RedundantSmartptrGetCheck.h" #include "RedundantStringCStrCheck.h" #include "RedundantStringInitCheck.h" -#include "SIMDIntrinsicsCheck.h" #include "SimplifyBooleanExprCheck.h" #include "StaticAccessedThroughInstanceCheck.h" #include "StaticDefinitionInAnonymousNamespaceCheck.h" @@ -93,8 +92,6 @@ "readability-redundant-string-cstr"); CheckFactories.registerCheck( "readability-redundant-string-init"); - CheckFactories.registerCheck( - "readability-simd-intrinsics"); CheckFactories.registerCheck( "readability-simplify-boolean-expr"); CheckFactories.registerCheck( Index: clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.h =================================================================== --- clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.h +++ clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.h @@ -1,40 +0,0 @@ -//===--- SIMDIntrinsicsCheck.h - clang-tidy----------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H - -#include "../ClangTidy.h" - -namespace clang { -namespace tidy { -namespace readability { - -/// Find SIMD intrinsics calls and suggest std::experimental::simd alternatives. -/// -/// For the user-facing documentation see: -/// http://clang.llvm.org/extra/clang-tidy/checks/readability-simd-intrinsics.html -class SIMDIntrinsicsCheck : public ClangTidyCheck { -public: - SIMDIntrinsicsCheck(StringRef Name, ClangTidyContext *Context); - - void storeOptions(ClangTidyOptions::OptionMap &Opts) override; - void registerMatchers(ast_matchers::MatchFinder *Finder) override; - void check(const ast_matchers::MatchFinder::MatchResult &Result) override; - - private: - const bool Suggest; - StringRef Std; -}; - -} // namespace readability -} // namespace tidy -} // namespace clang - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H Index: clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.cpp @@ -1,152 +0,0 @@ -//===--- SIMDIntrinsicsCheck.cpp - clang-tidy------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "SIMDIntrinsicsCheck.h" -#include "clang/AST/ASTContext.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" -#include "llvm/ADT/StringMap.h" -#include "llvm/ADT/Triple.h" -#include "llvm/Support/Regex.h" - -using namespace clang::ast_matchers; - -namespace clang { -namespace tidy { -namespace readability { - -namespace { - -// If the callee has parameter of VectorType or pointer to VectorType, -// or the return type is VectorType, we consider it a vector function -// and a candidate for checking. -AST_MATCHER(FunctionDecl, isVectorFunction) { - bool IsVector = Node.getReturnType()->isVectorType(); - for (const ParmVarDecl *Parm : Node.parameters()) { - QualType Type = Parm->getType(); - if (Type->isPointerType()) - Type = Type->getPointeeType(); - if (Type->isVectorType()) - IsVector = true; - } - return IsVector; -} - -} // namespace - -static StringRef TrySuggestPPC(StringRef Name) { - if (!Name.consume_front("vec_")) - return {}; - - static const llvm::StringMap Mapping{ - // [simd.alg] - {"max", "$std::max"}, - {"min", "$std::min"}, - - // [simd.binary] - {"add", "operator+ on $simd objects"}, - {"sub", "operator- on $simd objects"}, - {"mul", "operator* on $simd objects"}, - }; - - auto It = Mapping.find(Name); - if (It != Mapping.end()) - return It->second; - return {}; -} - -static StringRef TrySuggestX86(StringRef Name) { - if (!(Name.consume_front("_mm_") || Name.consume_front("_mm256_") || - Name.consume_front("_mm512_"))) - return {}; - - // [simd.alg] - if (Name.startswith("max_")) - return "$simd::max"; - if (Name.startswith("min_")) - return "$simd::min"; - - // [simd.binary] - if (Name.startswith("add_")) - return "operator+ on $simd objects"; - if (Name.startswith("sub_")) - return "operator- on $simd objects"; - if (Name.startswith("mul_")) - return "operator* on $simd objects"; - - return {}; -} - -SIMDIntrinsicsCheck::SIMDIntrinsicsCheck(StringRef Name, - ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), Suggest(Options.get("Suggest", 0) != 0) {} - -void SIMDIntrinsicsCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "Suggest", 0); -} - -void SIMDIntrinsicsCheck::registerMatchers(MatchFinder *Finder) { - if (!getLangOpts().CPlusPlus11) - return; - // libcxx implementation backports it to C++11 std::experimental::simd. - Std = getLangOpts().CPlusPlus2a ? "std" : "std::experimental"; - - Finder->addMatcher(callExpr(callee(functionDecl(allOf( - matchesName("^::(_mm_|_mm256_|_mm512_|vec_)"), - isVectorFunction()))), - unless(isExpansionInSystemHeader())) - .bind("call"), - this); -} - -void SIMDIntrinsicsCheck::check(const MatchFinder::MatchResult &Result) { - const auto *Call = Result.Nodes.getNodeAs("call"); - assert(Call != nullptr); - const FunctionDecl *Callee = Call->getDirectCallee(); - if (!Callee) - return; - - StringRef Old = Callee->getName(); - StringRef New; - llvm::Triple::ArchType Arch = - Result.Context->getTargetInfo().getTriple().getArch(); - - switch (Arch) { - default: - break; - case llvm::Triple::ppc: - case llvm::Triple::ppc64: - case llvm::Triple::ppc64le: - New = TrySuggestPPC(Old); - break; - case llvm::Triple::x86: - case llvm::Triple::x86_64: - New = TrySuggestX86(Old); - break; - } - - if (!New.empty()) { - std::string Message; - // If Suggest is true, give a P0214 alternative, otherwise point it out it - // is non-portable. - if (Suggest) { - Message = (Twine("'") + Old + "' can be replaced by " + New).str(); - Message = llvm::Regex("\\$std").sub(Std, Message); - Message = llvm::Regex("\\$simd").sub(Std.str() + "::simd", Message); - } else { - Message = (Twine("'") + Old + "' is a non-portable " + - llvm::Triple::getArchTypeName(Arch) + " intrinsic function") - .str(); - } - diag(Call->getExprLoc(), Message); - } -} - -} // namespace readability -} // namespace tidy -} // namespace clang Index: clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt =================================================================== --- clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt +++ clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt @@ -31,6 +31,7 @@ clangTidyMPIModule clangTidyObjCModule clangTidyPerformanceModule + clangTidyPortabilityModule clangTidyReadabilityModule clangTooling clangToolingCore Index: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp +++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp @@ -554,6 +554,11 @@ static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination = PerformanceModuleAnchorSource; +// This anchor is used to force the linker to link the PortabilityModule. +extern volatile int PortabilityModuleAnchorSource; +static int LLVM_ATTRIBUTE_UNUSED PortabilityModuleAnchorDestination = + PortabilityModuleAnchorSource; + // This anchor is used to force the linker to link the ReadabilityModule. extern volatile int ReadabilityModuleAnchorSource; static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination = Index: clang-tools-extra/trunk/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/trunk/docs/ReleaseNotes.rst +++ clang-tools-extra/trunk/docs/ReleaseNotes.rst @@ -57,6 +57,8 @@ Improvements to clang-tidy -------------------------- +- New module ``portability``. + - New `bugprone-throw-keyword-missing `_ check @@ -95,10 +97,10 @@ Finds and replaces deprecated uses of ``std::uncaught_exception`` to ``std::uncaught_exceptions``. -- New `readability-simd-intrinsics - `_ check +- New `portability-simd-intrinsics + `_ check - Warns if SIMD intrinsics are used which can be replaced by + Warns or suggests alternatives if SIMD intrinsics are used which can be replaced by ``std::experimental::simd`` operations. - New alias `hicpp-avoid-goto Index: clang-tools-extra/trunk/docs/clang-tidy/checks/portability-simd-intrinsics.rst =================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/portability-simd-intrinsics.rst +++ clang-tools-extra/trunk/docs/clang-tidy/checks/portability-simd-intrinsics.rst @@ -0,0 +1,49 @@ +.. title:: clang-tidy - portability-simd-intrinsics + +portability-simd-intrinsics +=========================== + +Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) +alternatives. + +If the option ``Suggest`` is set to non-zero, for + +.. code-block:: c++ + + _mm_add_epi32(a, b); // x86 + vec_add(a, b); // Power + +the check suggests an alternative: ``operator+`` on ``std::experimental::simd`` +objects. + +Otherwise, it just complains the intrinsics are non-portable (and there are +`P0214`_ alternatives). + +Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX, +ARM NEON). It is common that SIMD code implementing the same algorithm, is +written in multiple target-dispatching pieces to optimize for different +architectures or micro-architectures. + +The C++ standard proposal `P0214`_ and its extensions cover many common SIMD +operations. By migrating from target-dependent intrinsics to `P0214`_ +operations, the SIMD code can be simplified and pieces for different targets can +be unified. + +Refer to `P0214`_ for introduction and motivation for the data-parallel standard +library. + +Options +------- + +.. option:: Suggest + + If this option is set to non-zero (default is `0`), the check will suggest + `P0214`_ alternatives, otherwise it only points out the intrinsic function is + non-portable. + +.. option:: Std + + The namespace used to suggest `P0214`_ alternatives. If not specified, `std::` + for `-std=c++2a` and `std::experimental::` for `-std=c++11`. + +.. _P0214: http://wg21.link/p0214 Index: clang-tools-extra/trunk/docs/clang-tidy/checks/readability-simd-intrinsics.rst =================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/readability-simd-intrinsics.rst +++ clang-tools-extra/trunk/docs/clang-tidy/checks/readability-simd-intrinsics.rst @@ -1,44 +0,0 @@ -.. title:: clang-tidy - readability-simd-intrinsics - -readability-simd-intrinsics -=========================== - -Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) -alternatives. - -If the option ``Suggest`` is set to non-zero, for - -.. code-block:: c++ - - _mm_add_epi32(a, b); // x86 - vec_add(a, b); // Power - -the check suggests an alternative: ``operator+`` on ``std::experimental::simd`` -objects. - -Otherwise, it just complains the intrinsics are non-portable (and there are -`P0214`_ alternatives). - -Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX, -ARM NEON). It is common that SIMD code implementing the same algorithm, is -written in multiple target-dispatching pieces to optimize for different -architectures or micro-architectures. - -The C++ standard proposal `P0214`_ and its extensions cover many common SIMD -operations. By migrating from target-dependent intrinsics to `P0214`_ -operations, the SIMD code can be simplified and pieces for different targets can -be unified. - -Refer to `P0214`_ for introduction and motivation for the data-parallel standard -library. - -Options -------- - -.. option:: Suggest - - If this option is set to non-zero (default is `0`), the check will suggest - `P0214`_ alternatives, otherwise it only points out the intrinsic function is - non-portable. - -.. _P0214: http://wg21.link/p0214 Index: clang-tools-extra/trunk/docs/clang-tidy/index.rst =================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/index.rst +++ clang-tools-extra/trunk/docs/clang-tidy/index.rst @@ -71,6 +71,8 @@ ``mpi-`` Checks related to MPI (Message Passing Interface). ``objc-`` Checks related to Objective-C coding conventions. ``performance-`` Checks that target performance-related issues. +``portability-`` Checks that target portability-related issues that don't + relate to any particular coding style. ``readability-`` Checks that target readability-related issues that don't relate to any particular coding style. ====================== ========================================================= Index: clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-ppc.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-ppc.cpp +++ clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-ppc.cpp @@ -0,0 +1,13 @@ +// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \ +// RUN: -config='{CheckOptions: [ \ +// RUN: {key: portability-simd-intrinsics.Suggest, value: 1} \ +// RUN: ]}' -- -target ppc64le -maltivec -std=c++11 + +vector int vec_add(vector int, vector int); + +void PPC() { + vector int i0, i1; + + vec_add(i0, i1); +// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics] +} Index: clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-x86.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-x86.cpp +++ clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-x86.cpp @@ -0,0 +1,25 @@ +// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \ +// RUN: -config='{CheckOptions: [ \ +// RUN: {key: portability-simd-intrinsics.Suggest, value: 1} \ +// RUN: ]}' -- -target x86_64 -std=c++11 + +typedef long long __m128i __attribute__((vector_size(16))); +typedef double __m256 __attribute__((vector_size(32))); + +__m128i _mm_add_epi32(__m128i, __m128i); +__m256 _mm256_load_pd(double const *); +void _mm256_store_pd(double *, __m256); + +int _mm_add_fake(int, int); + +void X86() { + __m128i i0, i1; + __m256 d0; + + _mm_add_epi32(i0, i1); +// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics] + d0 = _mm256_load_pd(0); + _mm256_store_pd(0, d0); + + _mm_add_fake(0, 1); +} Index: clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-ppc.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-ppc.cpp +++ clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-ppc.cpp @@ -1,13 +0,0 @@ -// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \ -// RUN: -config='{CheckOptions: [ \ -// RUN: {key: readability-simd-intrinsics.Suggest, value: 1} \ -// RUN: ]}' -- -target ppc64le -maltivec -std=c++11 - -vector int vec_add(vector int, vector int); - -void PPC() { - vector int i0, i1; - - vec_add(i0, i1); -// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics] -} Index: clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-x86.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-x86.cpp +++ clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-x86.cpp @@ -1,25 +0,0 @@ -// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \ -// RUN: -config='{CheckOptions: [ \ -// RUN: {key: readability-simd-intrinsics.Suggest, value: 1} \ -// RUN: ]}' -- -target x86_64 -std=c++11 - -typedef long long __m128i __attribute__((vector_size(16))); -typedef double __m256 __attribute__((vector_size(32))); - -__m128i _mm_add_epi32(__m128i, __m128i); -__m256 _mm256_load_pd(double const *); -void _mm256_store_pd(double *, __m256); - -int _mm_add_fake(int, int); - -void X86() { - __m128i i0, i1; - __m256 d0; - - _mm_add_epi32(i0, i1); -// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics] - d0 = _mm256_load_pd(0); - _mm256_store_pd(0, d0); - - _mm_add_fake(0, 1); -}