[clang-tools-extra] r326909 - [clang-tidy] Add "portability" module and rename readability-simd-intrinsics to portability-simd-intrinsics
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 7 08:57:43 PST 2018
Author: maskray
Date: Wed Mar 7 08:57:42 2018
New Revision: 326909
URL: http://llvm.org/viewvc/llvm-project?rev=326909&view=rev
Log:
[clang-tidy] Add "portability" module and rename readability-simd-intrinsics to portability-simd-intrinsics
Reviewers: alexfh
Subscribers: klimek, nemanjai, mgorny, xazax.hun, kbarton, cfe-commits
Differential Revision: https://reviews.llvm.org/D44173
Added:
clang-tools-extra/trunk/clang-tidy/portability/
clang-tools-extra/trunk/clang-tidy/portability/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/portability/PortabilityTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.cpp
- copied, changed from r326809, clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.cpp
clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.h
- copied, changed from r326809, clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/portability-simd-intrinsics.rst
- copied, changed from r326809, clang-tools-extra/trunk/docs/clang-tidy/checks/readability-simd-intrinsics.rst
clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-ppc.cpp
- copied, changed from r326809, clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-ppc.cpp
clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-x86.cpp
- copied, changed from r326809, clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-x86.cpp
Removed:
clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-simd-intrinsics.rst
clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-ppc.cpp
clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-x86.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp
clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/index.rst
Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/CMakeLists.txt?rev=326909&r1=326908&r2=326909&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt Wed Mar 7 08:57:42 2018
@@ -41,6 +41,7 @@ add_subdirectory(mpi)
add_subdirectory(objc)
add_subdirectory(performance)
add_subdirectory(plugin)
+add_subdirectory(portability)
add_subdirectory(readability)
add_subdirectory(tool)
add_subdirectory(utils)
Modified: clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt?rev=326909&r1=326908&r2=326909&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt Wed Mar 7 08:57:42 2018
@@ -19,6 +19,7 @@ add_clang_library(clangTidyPlugin
clangTidyMPIModule
clangTidyObjCModule
clangTidyPerformanceModule
+ clangTidyPortabilityModule
clangTidyReadabilityModule
clangTooling
)
Modified: clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp?rev=326909&r1=326908&r2=326909&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp Wed Mar 7 08:57:42 2018
@@ -118,6 +118,11 @@ extern volatile int PerformanceModuleAnc
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 =
Added: clang-tools-extra/trunk/clang-tidy/portability/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/portability/CMakeLists.txt?rev=326909&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/portability/CMakeLists.txt (added)
+++ clang-tools-extra/trunk/clang-tidy/portability/CMakeLists.txt Wed Mar 7 08:57:42 2018
@@ -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
+ )
Added: clang-tools-extra/trunk/clang-tidy/portability/PortabilityTidyModule.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/portability/PortabilityTidyModule.cpp?rev=326909&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/portability/PortabilityTidyModule.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/portability/PortabilityTidyModule.cpp Wed Mar 7 08:57:42 2018
@@ -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<SIMDIntrinsicsCheck>(
+ "portability-simd-intrinsics");
+ }
+};
+
+// Register the PortabilityModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add<PortabilityModule>
+ 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
Copied: clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.cpp (from r326809, clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.cpp)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.cpp?p2=clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.cpp&p1=clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.cpp&r1=326809&r2=326909&rev=326909&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.cpp Wed Mar 7 08:57:42 2018
@@ -18,7 +18,7 @@ using namespace clang::ast_matchers;
namespace clang {
namespace tidy {
-namespace readability {
+namespace portability {
namespace {
@@ -84,17 +84,21 @@ static StringRef TrySuggestX86(StringRef
SIMDIntrinsicsCheck::SIMDIntrinsicsCheck(StringRef Name,
ClangTidyContext *Context)
- : ClangTidyCheck(Name, Context), Suggest(Options.get("Suggest", 0) != 0) {}
+ : 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.
- Std = getLangOpts().CPlusPlus2a ? "std" : "std::experimental";
+ if (Std.empty())
+ Std = getLangOpts().CPlusPlus2a ? "std" : "std::experimental";
Finder->addMatcher(callExpr(callee(functionDecl(allOf(
matchesName("^::(_mm_|_mm256_|_mm512_|vec_)"),
@@ -116,20 +120,23 @@ void SIMDIntrinsicsCheck::check(const Ma
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;
+ 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
@@ -137,7 +144,8 @@ void SIMDIntrinsicsCheck::check(const Ma
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);
+ Message =
+ llvm::Regex("\\$simd").sub((Std.str() + "::simd").str(), Message);
} else {
Message = (Twine("'") + Old + "' is a non-portable " +
llvm::Triple::getArchTypeName(Arch) + " intrinsic function")
@@ -147,6 +155,6 @@ void SIMDIntrinsicsCheck::check(const Ma
}
}
-} // namespace readability
+} // namespace portability
} // namespace tidy
} // namespace clang
Copied: clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.h (from r326809, clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.h)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.h?p2=clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.h&p1=clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.h&r1=326809&r2=326909&rev=326909&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.h Wed Mar 7 08:57:42 2018
@@ -12,14 +12,16 @@
#include "../ClangTidy.h"
+#include "llvm/ADT/SmallString.h"
+
namespace clang {
namespace tidy {
-namespace readability {
+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/readability-simd-intrinsics.html
+/// http://clang.llvm.org/extra/clang-tidy/checks/portability-simd-intrinsics.html
class SIMDIntrinsicsCheck : public ClangTidyCheck {
public:
SIMDIntrinsicsCheck(StringRef Name, ClangTidyContext *Context);
@@ -29,11 +31,11 @@ public:
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
private:
+ llvm::SmallString<32> Std;
const bool Suggest;
- StringRef Std;
};
-} // namespace readability
+} // namespace portability
} // namespace tidy
} // namespace clang
Modified: clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt?rev=326909&r1=326908&r2=326909&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt Wed Mar 7 08:57:42 2018
@@ -24,7 +24,6 @@ add_clang_library(clangTidyReadabilityMo
RedundantStringCStrCheck.cpp
RedundantSmartptrGetCheck.cpp
RedundantStringInitCheck.cpp
- SIMDIntrinsicsCheck.cpp
SimplifyBooleanExprCheck.cpp
StaticAccessedThroughInstanceCheck.cpp
StaticDefinitionInAnonymousNamespaceCheck.cpp
Modified: clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp?rev=326909&r1=326908&r2=326909&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp Wed Mar 7 08:57:42 2018
@@ -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 @@ public:
"readability-redundant-string-cstr");
CheckFactories.registerCheck<RedundantStringInitCheck>(
"readability-redundant-string-init");
- CheckFactories.registerCheck<SIMDIntrinsicsCheck>(
- "readability-simd-intrinsics");
CheckFactories.registerCheck<SimplifyBooleanExprCheck>(
"readability-simplify-boolean-expr");
CheckFactories.registerCheck<UniqueptrDeleteReleaseCheck>(
Removed: clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.cpp?rev=326908&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.cpp (removed)
@@ -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<StringRef> 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<CallExpr>("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
Removed: clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.h?rev=326908&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.h (removed)
@@ -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
Modified: clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt?rev=326909&r1=326908&r2=326909&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt Wed Mar 7 08:57:42 2018
@@ -31,6 +31,7 @@ target_link_libraries(clang-tidy
clangTidyMPIModule
clangTidyObjCModule
clangTidyPerformanceModule
+ clangTidyPortabilityModule
clangTidyReadabilityModule
clangTooling
clangToolingCore
Modified: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=326909&r1=326908&r2=326909&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp Wed Mar 7 08:57:42 2018
@@ -554,6 +554,11 @@ extern volatile int PerformanceModuleAnc
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 =
Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=326909&r1=326908&r2=326909&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Wed Mar 7 08:57:42 2018
@@ -57,6 +57,8 @@ The improvements are...
Improvements to clang-tidy
--------------------------
+- New module ``portability``.
+
- New `bugprone-throw-keyword-missing
<http://clang.llvm.org/extra/clang-tidy/checks/bugprone-throw-keyword-missing.html>`_ check
@@ -95,10 +97,10 @@ Improvements to clang-tidy
Finds and replaces deprecated uses of ``std::uncaught_exception`` to
``std::uncaught_exceptions``.
-- New `readability-simd-intrinsics
- <http://clang.llvm.org/extra/clang-tidy/checks/readability-simd-intrinsics.html>`_ check
+- New `portability-simd-intrinsics
+ <http://clang.llvm.org/extra/clang-tidy/checks/portability-simd-intrinsics.html>`_ 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
Copied: clang-tools-extra/trunk/docs/clang-tidy/checks/portability-simd-intrinsics.rst (from r326809, clang-tools-extra/trunk/docs/clang-tidy/checks/readability-simd-intrinsics.rst)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/portability-simd-intrinsics.rst?p2=clang-tools-extra/trunk/docs/clang-tidy/checks/portability-simd-intrinsics.rst&p1=clang-tools-extra/trunk/docs/clang-tidy/checks/readability-simd-intrinsics.rst&r1=326809&r2=326909&rev=326909&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/readability-simd-intrinsics.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/portability-simd-intrinsics.rst Wed Mar 7 08:57:42 2018
@@ -1,6 +1,6 @@
-.. title:: clang-tidy - readability-simd-intrinsics
+.. title:: clang-tidy - portability-simd-intrinsics
-readability-simd-intrinsics
+portability-simd-intrinsics
===========================
Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_)
@@ -41,4 +41,9 @@ Options
`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
Removed: clang-tools-extra/trunk/docs/clang-tidy/checks/readability-simd-intrinsics.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/readability-simd-intrinsics.rst?rev=326908&view=auto
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/readability-simd-intrinsics.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/readability-simd-intrinsics.rst (removed)
@@ -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
Modified: clang-tools-extra/trunk/docs/clang-tidy/index.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/index.rst?rev=326909&r1=326908&r2=326909&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/index.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/index.rst Wed Mar 7 08:57:42 2018
@@ -71,6 +71,8 @@ Name prefix Description
``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.
====================== =========================================================
Copied: clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-ppc.cpp (from r326809, clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-ppc.cpp)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-ppc.cpp?p2=clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-ppc.cpp&p1=clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-ppc.cpp&r1=326809&r2=326909&rev=326909&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-ppc.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-ppc.cpp Wed Mar 7 08:57:42 2018
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
// RUN: -config='{CheckOptions: [ \
-// RUN: {key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN: {key: portability-simd-intrinsics.Suggest, value: 1} \
// RUN: ]}' -- -target ppc64le -maltivec -std=c++11
vector int vec_add(vector int, vector int);
@@ -9,5 +9,5 @@ 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]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
}
Copied: clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-x86.cpp (from r326809, clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-x86.cpp)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-x86.cpp?p2=clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-x86.cpp&p1=clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-x86.cpp&r1=326809&r2=326909&rev=326909&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-x86.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-x86.cpp Wed Mar 7 08:57:42 2018
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
// RUN: -config='{CheckOptions: [ \
-// RUN: {key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN: {key: portability-simd-intrinsics.Suggest, value: 1} \
// RUN: ]}' -- -target x86_64 -std=c++11
typedef long long __m128i __attribute__((vector_size(16)));
@@ -17,7 +17,7 @@ void X86() {
__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]
+// 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);
Removed: clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-ppc.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-ppc.cpp?rev=326908&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-ppc.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-ppc.cpp (removed)
@@ -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]
-}
Removed: clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-x86.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-x86.cpp?rev=326908&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-x86.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-x86.cpp (removed)
@@ -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);
-}
More information about the cfe-commits
mailing list