Skip to content

Commit

Permalink
Merge branch 'sycl' into private/dvodopya/improve-allowlist
Browse files Browse the repository at this point in the history
  • Loading branch information
dm-vodopyanov authored Jun 1, 2021
2 parents c20fe51 + 75e5a26 commit 9a3dcf9
Show file tree
Hide file tree
Showing 6,327 changed files with 1,309,820 additions and 179,386 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ clang/tools/clang-offload-extract/ @sndmitriev @mlychkov @AlexeySachkov
# Explicit SIMD
SYCLLowerIR/ @kbobrovs @DenisBakhvalov
esimd/ @kbobrovs @DenisBakhvalov
sycl/include/CL/sycl/INTEL/esimd.hpp @kbobrovs @DenisBakhvalov
sycl/include/sycl/ext/intel/experimental/esimd.hpp @kbobrovs @DenisBakhvalov
sycl/doc/extensions/ExplicitSIMD/ @kbobrovs

# ITT annotations
Expand Down
5 changes: 5 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Reporting LLVM Security Issues

To report security issues in LLVM, please follow the steps outlined on the
[LLVM Security Group](https://llvm.org/docs/Security.html#how-to-report-a-security-issue)
page.
6 changes: 3 additions & 3 deletions buildbot/dependency.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ ocl_cpu_rt_ver=2021.11.3.0.09
# https://github.com/intel/llvm/releases/download/2021-WW11/win-oclcpuexp-2021.11.3.0.09_rel.zip
ocl_cpu_rt_ver_win=2021.11.3.0.09
# Same GPU driver supports Level Zero and OpenCL
# https://github.com/intel/compute-runtime/releases/tag/21.17.19709
ocl_gpu_rt_ver=21.17.19709
# https://github.com/intel/compute-runtime/releases/tag/21.19.19792
ocl_gpu_rt_ver=21.19.19792
# Same GPU driver supports Level Zero and OpenCL
# https://downloadmirror.intel.com/30381/a08/igfx_win10_100.9466.zip
ocl_gpu_rt_ver_win=27.20.100.9466
Expand All @@ -30,7 +30,7 @@ ocloc_ver_win=27.20.100.9168
[DRIVER VERSIONS]
cpu_driver_lin=2021.11.3.0.09
cpu_driver_win=2021.11.3.0.09
gpu_driver_lin=21.17.19709
gpu_driver_lin=21.19.19792
gpu_driver_win=27.20.100.9466
fpga_driver_lin=2021.11.3.0.09
fpga_driver_win=2021.11.3.0.09
Expand Down
5 changes: 3 additions & 2 deletions clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ llvm::Optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(

StringRef Value = Iter->getValue().Value;
StringRef Closest;
unsigned EditDistance = -1;
unsigned EditDistance = 3;
for (const auto &NameAndEnum : Mapping) {
if (IgnoreCase) {
if (Value.equals_lower(NameAndEnum.second))
Expand All @@ -159,7 +159,8 @@ llvm::Optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
EditDistance = 0;
continue;
}
unsigned Distance = Value.edit_distance(NameAndEnum.second);
unsigned Distance =
Value.edit_distance(NameAndEnum.second, true, EditDistance);
if (Distance < EditDistance) {
EditDistance = Distance;
Closest = NameAndEnum.second;
Expand Down
6 changes: 6 additions & 0 deletions clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
case DiagnosticsEngine::Warning:
CheckName = "clang-diagnostic-warning";
break;
case DiagnosticsEngine::Remark:
CheckName = "clang-diagnostic-remark";
break;
default:
CheckName = "clang-diagnostic-unknown";
break;
Expand All @@ -460,7 +463,10 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
Level = ClangTidyError::Error;
LastErrorRelatesToUserCode = true;
LastErrorPassesLineFilter = true;
} else if (DiagLevel == DiagnosticsEngine::Remark) {
Level = ClangTidyError::Remark;
}

bool IsWarningAsError = DiagLevel == DiagnosticsEngine::Warning &&
Context.treatAsError(CheckName);
Errors.emplace_back(CheckName, Level, Context.getCurrentBuildDirectory(),
Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
#include "IdDependentBackwardBranchCheck.h"
#include "KernelNameRestrictionCheck.h"
#include "SingleWorkItemBarrierCheck.h"
#include "StructPackAlignCheck.h"
Expand All @@ -23,6 +24,8 @@ namespace altera {
class AlteraModule : public ClangTidyModule {
public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<IdDependentBackwardBranchCheck>(
"altera-id-dependent-backward-branch");
CheckFactories.registerCheck<KernelNameRestrictionCheck>(
"altera-kernel-name-restriction");
CheckFactories.registerCheck<SingleWorkItemBarrierCheck>(
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clang-tidy/altera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS

add_clang_library(clangTidyAlteraModule
AlteraTidyModule.cpp
IdDependentBackwardBranchCheck.cpp
KernelNameRestrictionCheck.cpp
SingleWorkItemBarrierCheck.cpp
StructPackAlignCheck.cpp
Expand Down
264 changes: 264 additions & 0 deletions clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
//===--- IdDependentBackwardBranchCheck.cpp - clang-tidy ------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "IdDependentBackwardBranchCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"

using namespace clang::ast_matchers;

namespace clang {
namespace tidy {
namespace altera {

void IdDependentBackwardBranchCheck::registerMatchers(MatchFinder *Finder) {
// Prototype to identify all variables which hold a thread-variant ID.
// First Matcher just finds all the direct assignments of either ID call.
const auto ThreadID = expr(hasDescendant(callExpr(callee(functionDecl(
anyOf(hasName("get_global_id"), hasName("get_local_id")))))));

const auto RefVarOrField = forEachDescendant(
stmt(anyOf(declRefExpr(to(varDecl())).bind("assign_ref_var"),
memberExpr(member(fieldDecl())).bind("assign_ref_field"))));

Finder->addMatcher(
compoundStmt(
// Bind on actual get_local/global_id calls.
forEachDescendant(
stmt(
anyOf(declStmt(hasDescendant(varDecl(hasInitializer(ThreadID))
.bind("tid_dep_var"))),
binaryOperator(allOf(
isAssignmentOperator(), hasRHS(ThreadID),
hasLHS(anyOf(
declRefExpr(to(varDecl().bind("tid_dep_var"))),
memberExpr(member(
fieldDecl().bind("tid_dep_field")))))))))
.bind("straight_assignment"))),
this);

// Bind all VarDecls that include an initializer with a variable DeclRefExpr
// (in case it is ID-dependent).
Finder->addMatcher(
stmt(forEachDescendant(
varDecl(hasInitializer(RefVarOrField)).bind("pot_tid_var"))),
this);

// Bind all VarDecls that are assigned a value with a variable DeclRefExpr (in
// case it is ID-dependent).
Finder->addMatcher(
stmt(forEachDescendant(binaryOperator(
allOf(isAssignmentOperator(), hasRHS(RefVarOrField),
hasLHS(anyOf(
declRefExpr(to(varDecl().bind("pot_tid_var"))),
memberExpr(member(fieldDecl().bind("pot_tid_field"))))))))),
this);

// Second Matcher looks for branch statements inside of loops and bind on the
// condition expression IF it either calls an ID function or has a variable
// DeclRefExpr. DeclRefExprs are checked later to confirm whether the variable
// is ID-dependent.
const auto CondExpr =
expr(anyOf(hasDescendant(callExpr(callee(functionDecl(
anyOf(hasName("get_global_id"),
hasName("get_local_id")))))
.bind("id_call")),
hasDescendant(stmt(anyOf(declRefExpr(to(varDecl())),
memberExpr(member(fieldDecl())))))))
.bind("cond_expr");
Finder->addMatcher(stmt(anyOf(forStmt(hasCondition(CondExpr)),
doStmt(hasCondition(CondExpr)),
whileStmt(hasCondition(CondExpr))))
.bind("backward_branch"),
this);
}

IdDependentBackwardBranchCheck::IdDependencyRecord *
IdDependentBackwardBranchCheck::hasIdDepVar(const Expr *Expression) {
if (const auto *Declaration = dyn_cast<DeclRefExpr>(Expression)) {
// It is a DeclRefExpr, so check if it's an ID-dependent variable.
const auto *CheckVariable = dyn_cast<VarDecl>(Declaration->getDecl());
auto FoundVariable = IdDepVarsMap.find(CheckVariable);
if (FoundVariable == IdDepVarsMap.end())
return nullptr;
return &(FoundVariable->second);
}
for (const auto *Child : Expression->children())
if (const auto *ChildExpression = dyn_cast<Expr>(Child))
if (IdDependencyRecord *Result = hasIdDepVar(ChildExpression))
return Result;
return nullptr;
}

IdDependentBackwardBranchCheck::IdDependencyRecord *
IdDependentBackwardBranchCheck::hasIdDepField(const Expr *Expression) {
if (const auto *MemberExpression = dyn_cast<MemberExpr>(Expression)) {
const auto *CheckField =
dyn_cast<FieldDecl>(MemberExpression->getMemberDecl());
auto FoundField = IdDepFieldsMap.find(CheckField);
if (FoundField == IdDepFieldsMap.end())
return nullptr;
return &(FoundField->second);
}
for (const auto *Child : Expression->children())
if (const auto *ChildExpression = dyn_cast<Expr>(Child))
if (IdDependencyRecord *Result = hasIdDepField(ChildExpression))
return Result;
return nullptr;
}

void IdDependentBackwardBranchCheck::saveIdDepVar(const Stmt *Statement,
const VarDecl *Variable) {
// Record that this variable is thread-dependent.
IdDepVarsMap[Variable] =
IdDependencyRecord(Variable, Variable->getBeginLoc(),
Twine("assignment of ID-dependent variable ") +
Variable->getNameAsString());
}

void IdDependentBackwardBranchCheck::saveIdDepField(const Stmt *Statement,
const FieldDecl *Field) {
// Record that this field is thread-dependent.
IdDepFieldsMap[Field] = IdDependencyRecord(
Field, Statement->getBeginLoc(),
Twine("assignment of ID-dependent field ") + Field->getNameAsString());
}

void IdDependentBackwardBranchCheck::saveIdDepVarFromReference(
const DeclRefExpr *RefExpr, const MemberExpr *MemExpr,
const VarDecl *PotentialVar) {
// If the variable is already in IdDepVarsMap, ignore it.
if (IdDepVarsMap.find(PotentialVar) != IdDepVarsMap.end())
return;
std::string Message;
llvm::raw_string_ostream StringStream(Message);
StringStream << "inferred assignment of ID-dependent value from "
"ID-dependent ";
if (RefExpr) {
const auto *RefVar = dyn_cast<VarDecl>(RefExpr->getDecl());
// If variable isn't ID-dependent, but RefVar is.
if (IdDepVarsMap.find(RefVar) != IdDepVarsMap.end())
StringStream << "variable " << RefVar->getNameAsString();
}
if (MemExpr) {
const auto *RefField = dyn_cast<FieldDecl>(MemExpr->getMemberDecl());
// If variable isn't ID-dependent, but RefField is.
if (IdDepFieldsMap.find(RefField) != IdDepFieldsMap.end())
StringStream << "member " << RefField->getNameAsString();
}
IdDepVarsMap[PotentialVar] =
IdDependencyRecord(PotentialVar, PotentialVar->getBeginLoc(), Message);
}

void IdDependentBackwardBranchCheck::saveIdDepFieldFromReference(
const DeclRefExpr *RefExpr, const MemberExpr *MemExpr,
const FieldDecl *PotentialField) {
// If the field is already in IdDepFieldsMap, ignore it.
if (IdDepFieldsMap.find(PotentialField) != IdDepFieldsMap.end())
return;
std::string Message;
llvm::raw_string_ostream StringStream(Message);
StringStream << "inferred assignment of ID-dependent member from "
"ID-dependent ";
if (RefExpr) {
const auto *RefVar = dyn_cast<VarDecl>(RefExpr->getDecl());
// If field isn't ID-dependent, but RefVar is.
if (IdDepVarsMap.find(RefVar) != IdDepVarsMap.end())
StringStream << "variable " << RefVar->getNameAsString();
}
if (MemExpr) {
const auto *RefField = dyn_cast<FieldDecl>(MemExpr->getMemberDecl());
if (IdDepFieldsMap.find(RefField) != IdDepFieldsMap.end())
StringStream << "member " << RefField->getNameAsString();
}
IdDepFieldsMap[PotentialField] = IdDependencyRecord(
PotentialField, PotentialField->getBeginLoc(), Message);
}

IdDependentBackwardBranchCheck::LoopType
IdDependentBackwardBranchCheck::getLoopType(const Stmt *Loop) {
switch (Loop->getStmtClass()) {
case Stmt::DoStmtClass:
return DoLoop;
case Stmt::WhileStmtClass:
return WhileLoop;
case Stmt::ForStmtClass:
return ForLoop;
default:
return UnknownLoop;
}
}

void IdDependentBackwardBranchCheck::check(
const MatchFinder::MatchResult &Result) {
// The first half of the callback only deals with identifying and storing
// ID-dependency information into the IdDepVars and IdDepFields maps.
const auto *Variable = Result.Nodes.getNodeAs<VarDecl>("tid_dep_var");
const auto *Field = Result.Nodes.getNodeAs<FieldDecl>("tid_dep_field");
const auto *Statement = Result.Nodes.getNodeAs<Stmt>("straight_assignment");
const auto *RefExpr = Result.Nodes.getNodeAs<DeclRefExpr>("assign_ref_var");
const auto *MemExpr = Result.Nodes.getNodeAs<MemberExpr>("assign_ref_field");
const auto *PotentialVar = Result.Nodes.getNodeAs<VarDecl>("pot_tid_var");
const auto *PotentialField =
Result.Nodes.getNodeAs<FieldDecl>("pot_tid_field");

// Save variables and fields assigned directly through ID function calls.
if (Statement && (Variable || Field)) {
if (Variable)
saveIdDepVar(Statement, Variable);
else if (Field)
saveIdDepField(Statement, Field);
}

// Save variables assigned to values of Id-dependent variables and fields.
if ((RefExpr || MemExpr) && PotentialVar)
saveIdDepVarFromReference(RefExpr, MemExpr, PotentialVar);

// Save fields assigned to values of ID-dependent variables and fields.
if ((RefExpr || MemExpr) && PotentialField)
saveIdDepFieldFromReference(RefExpr, MemExpr, PotentialField);

// The second part of the callback deals with checking if a branch inside a
// loop is thread dependent.
const auto *CondExpr = Result.Nodes.getNodeAs<Expr>("cond_expr");
const auto *IDCall = Result.Nodes.getNodeAs<CallExpr>("id_call");
const auto *Loop = Result.Nodes.getNodeAs<Stmt>("backward_branch");
if (!Loop)
return;
LoopType Type = getLoopType(Loop);
if (CondExpr) {
if (IDCall) { // Conditional expression calls an ID function directly.
diag(CondExpr->getBeginLoc(),
"backward branch (%select{do|while|for}0 loop) is ID-dependent due "
"to ID function call and may cause performance degradation")
<< Type;
return;
}
// Conditional expression has DeclRefExpr(s), check ID-dependency.
IdDependencyRecord *IdDepVar = hasIdDepVar(CondExpr);
IdDependencyRecord *IdDepField = hasIdDepField(CondExpr);
if (IdDepVar) {
// Change one of these to a Note
diag(IdDepVar->Location, IdDepVar->Message, DiagnosticIDs::Note);
diag(CondExpr->getBeginLoc(),
"backward branch (%select{do|while|for}0 loop) is ID-dependent due "
"to variable reference to %1 and may cause performance degradation")
<< Type << IdDepVar->VariableDeclaration;
} else if (IdDepField) {
diag(IdDepField->Location, IdDepField->Message, DiagnosticIDs::Note);
diag(CondExpr->getBeginLoc(),
"backward branch (%select{do|while|for}0 loop) is ID-dependent due "
"to member reference to %1 and may cause performance degradation")
<< Type << IdDepField->FieldDeclaration;
}
}
}

} // namespace altera
} // namespace tidy
} // namespace clang
Loading

0 comments on commit 9a3dcf9

Please sign in to comment.