Go to the documentation of this file.
10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
12 #include "clang/Basic/TargetInfo.h"
13 #include "llvm/ADT/StringMap.h"
14 #include "llvm/ADT/Triple.h"
15 #include "llvm/Support/Regex.h"
21 namespace portability {
29 bool IsVector = Node.getReturnType()->isVectorType();
30 for (
const ParmVarDecl *
Parm : Node.parameters()) {
32 if (
Type->isPointerType())
34 if (
Type->isVectorType())
43 if (!
Name.consume_front(
"vec_"))
46 return llvm::StringSwitch<StringRef>(
Name)
48 .Case(
"max",
"$std::max")
49 .Case(
"min",
"$std::min")
51 .Case(
"add",
"operator+ on $simd objects")
52 .Case(
"sub",
"operator- on $simd objects")
53 .Case(
"mul",
"operator* on $simd objects")
58 if (!(
Name.consume_front(
"_mm_") ||
Name.consume_front(
"_mm256_") ||
59 Name.consume_front(
"_mm512_")))
63 if (
Name.startswith(
"max_"))
65 if (
Name.startswith(
"min_"))
69 if (
Name.startswith(
"add_"))
70 return "operator+ on $simd objects";
71 if (
Name.startswith(
"sub_"))
72 return "operator- on $simd objects";
73 if (
Name.startswith(
"mul_"))
74 return "operator* on $simd objects";
79 SIMDIntrinsicsCheck::SIMDIntrinsicsCheck(StringRef
Name,
82 Suggest(Options.get(
"Suggest", false)) {}
93 Std =
getLangOpts().CPlusPlus20 ?
"std" :
"std::experimental";
95 Finder->addMatcher(callExpr(callee(functionDecl(
96 matchesName(
"^::(_mm_|_mm256_|_mm512_|vec_)"),
98 unless(isExpansionInSystemHeader()))
104 const auto *Call = Result.Nodes.getNodeAs<CallExpr>(
"call");
105 assert(Call !=
nullptr);
106 const FunctionDecl *Callee = Call->getDirectCallee();
110 StringRef Old = Callee->getName();
112 llvm::Triple::ArchType Arch =
113 Result.Context->getTargetInfo().getTriple().getArch();
120 case llvm::Triple::ppc:
121 case llvm::Triple::ppc64:
122 case llvm::Triple::ppc64le:
125 case llvm::Triple::x86:
126 case llvm::Triple::x86_64:
137 Message = (Twine(
"'") + Old +
"' can be replaced by " + New).str();
140 llvm::Regex(
"\\$simd").sub((Std.str() +
"::simd").str(),
Message);
142 Message = (Twine(
"'") + Old +
"' is a non-portable " +
143 llvm::Triple::getArchTypeName(Arch) +
" intrinsic function")
static const char Message[]
Base class for all clang-tidy checks.
const LangOptions & getLangOpts() const
Returns the language options from the context.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
static constexpr llvm::StringLiteral Name
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
AST_MATCHER(Expr, isMacroID)
static StringRef TrySuggestX86(StringRef Name)
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
static StringRef TrySuggestPPC(StringRef Name)
std::map< std::string, ClangTidyValue > OptionMap