10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
26 hasAttr(attr::Kind::OpenCLKernel),
28 forEachDescendant(callExpr(callee(functionDecl(hasAnyName(
29 "barrier",
"work_group_barrier"))))
32 unless(hasDescendant(callExpr(callee(functionDecl(
33 hasAnyName(
"get_global_id",
"get_local_id",
"get_group_id",
34 "get_local_linear_id")))))))
40 const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>(
"function");
41 const auto *MatchedBarrier = Result.Nodes.getNodeAs<CallExpr>(
"barrier");
42 if (AOCVersion < 1701) {
44 diag(MatchedDecl->getLocation(),
45 "kernel function %0 does not call 'get_global_id' or 'get_local_id' "
46 "and will be treated as a single work-item")
48 diag(MatchedBarrier->getBeginLoc(),
49 "barrier call is in a single work-item and may error out",
54 bool IsNDRange =
false;
55 if (MatchedDecl->hasAttr<ReqdWorkGroupSizeAttr>()) {
56 const auto *Attribute = MatchedDecl->getAttr<ReqdWorkGroupSizeAttr>();
57 if (Attribute->getXDim() > 1 || Attribute->getYDim() > 1 ||
58 Attribute->getZDim() > 1)
63 diag(MatchedDecl->getLocation(),
64 "kernel function %0 does not call an ID function and may be a viable "
65 "single work-item, but will be forced to execute as an NDRange")
67 diag(MatchedBarrier->getBeginLoc(),
68 "barrier call will force NDRange execution; if single work-item "
69 "semantics are desired a mem_fence may be more efficient",
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.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
llvm::StringMap< ClangTidyValue > OptionMap