Skip to content

Commit 9a3dcf9

Browse files
Merge branch 'sycl' into private/dvodopya/improve-allowlist
2 parents c20fe51 + 75e5a26 commit 9a3dcf9

File tree

6,327 files changed

+1309820
-179386
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

6,327 files changed

+1309820
-179386
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ clang/tools/clang-offload-extract/ @sndmitriev @mlychkov @AlexeySachkov
101101
# Explicit SIMD
102102
SYCLLowerIR/ @kbobrovs @DenisBakhvalov
103103
esimd/ @kbobrovs @DenisBakhvalov
104-
sycl/include/CL/sycl/INTEL/esimd.hpp @kbobrovs @DenisBakhvalov
104+
sycl/include/sycl/ext/intel/experimental/esimd.hpp @kbobrovs @DenisBakhvalov
105105
sycl/doc/extensions/ExplicitSIMD/ @kbobrovs
106106

107107
# ITT annotations

SECURITY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Reporting LLVM Security Issues
2+
3+
To report security issues in LLVM, please follow the steps outlined on the
4+
[LLVM Security Group](https://llvm.org/docs/Security.html#how-to-report-a-security-issue)
5+
page.

buildbot/dependency.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ ocl_cpu_rt_ver=2021.11.3.0.09
44
# https://github.com/intel/llvm/releases/download/2021-WW11/win-oclcpuexp-2021.11.3.0.09_rel.zip
55
ocl_cpu_rt_ver_win=2021.11.3.0.09
66
# Same GPU driver supports Level Zero and OpenCL
7-
# https://github.com/intel/compute-runtime/releases/tag/21.17.19709
8-
ocl_gpu_rt_ver=21.17.19709
7+
# https://github.com/intel/compute-runtime/releases/tag/21.19.19792
8+
ocl_gpu_rt_ver=21.19.19792
99
# Same GPU driver supports Level Zero and OpenCL
1010
# https://downloadmirror.intel.com/30381/a08/igfx_win10_100.9466.zip
1111
ocl_gpu_rt_ver_win=27.20.100.9466
@@ -30,7 +30,7 @@ ocloc_ver_win=27.20.100.9168
3030
[DRIVER VERSIONS]
3131
cpu_driver_lin=2021.11.3.0.09
3232
cpu_driver_win=2021.11.3.0.09
33-
gpu_driver_lin=21.17.19709
33+
gpu_driver_lin=21.19.19792
3434
gpu_driver_win=27.20.100.9466
3535
fpga_driver_lin=2021.11.3.0.09
3636
fpga_driver_win=2021.11.3.0.09

clang-tools-extra/clang-tidy/ClangTidyCheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ llvm::Optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
147147

148148
StringRef Value = Iter->getValue().Value;
149149
StringRef Closest;
150-
unsigned EditDistance = -1;
150+
unsigned EditDistance = 3;
151151
for (const auto &NameAndEnum : Mapping) {
152152
if (IgnoreCase) {
153153
if (Value.equals_lower(NameAndEnum.second))
@@ -159,7 +159,8 @@ llvm::Optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
159159
EditDistance = 0;
160160
continue;
161161
}
162-
unsigned Distance = Value.edit_distance(NameAndEnum.second);
162+
unsigned Distance =
163+
Value.edit_distance(NameAndEnum.second, true, EditDistance);
163164
if (Distance < EditDistance) {
164165
EditDistance = Distance;
165166
Closest = NameAndEnum.second;

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,9 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
446446
case DiagnosticsEngine::Warning:
447447
CheckName = "clang-diagnostic-warning";
448448
break;
449+
case DiagnosticsEngine::Remark:
450+
CheckName = "clang-diagnostic-remark";
451+
break;
449452
default:
450453
CheckName = "clang-diagnostic-unknown";
451454
break;
@@ -460,7 +463,10 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
460463
Level = ClangTidyError::Error;
461464
LastErrorRelatesToUserCode = true;
462465
LastErrorPassesLineFilter = true;
466+
} else if (DiagLevel == DiagnosticsEngine::Remark) {
467+
Level = ClangTidyError::Remark;
463468
}
469+
464470
bool IsWarningAsError = DiagLevel == DiagnosticsEngine::Warning &&
465471
Context.treatAsError(CheckName);
466472
Errors.emplace_back(CheckName, Level, Context.getCurrentBuildDirectory(),

clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "../ClangTidy.h"
1010
#include "../ClangTidyModule.h"
1111
#include "../ClangTidyModuleRegistry.h"
12+
#include "IdDependentBackwardBranchCheck.h"
1213
#include "KernelNameRestrictionCheck.h"
1314
#include "SingleWorkItemBarrierCheck.h"
1415
#include "StructPackAlignCheck.h"
@@ -23,6 +24,8 @@ namespace altera {
2324
class AlteraModule : public ClangTidyModule {
2425
public:
2526
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
27+
CheckFactories.registerCheck<IdDependentBackwardBranchCheck>(
28+
"altera-id-dependent-backward-branch");
2629
CheckFactories.registerCheck<KernelNameRestrictionCheck>(
2730
"altera-kernel-name-restriction");
2831
CheckFactories.registerCheck<SingleWorkItemBarrierCheck>(

clang-tools-extra/clang-tidy/altera/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS
55

66
add_clang_library(clangTidyAlteraModule
77
AlteraTidyModule.cpp
8+
IdDependentBackwardBranchCheck.cpp
89
KernelNameRestrictionCheck.cpp
910
SingleWorkItemBarrierCheck.cpp
1011
StructPackAlignCheck.cpp
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
//===--- IdDependentBackwardBranchCheck.cpp - clang-tidy ------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "IdDependentBackwardBranchCheck.h"
10+
#include "clang/AST/ASTContext.h"
11+
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
13+
using namespace clang::ast_matchers;
14+
15+
namespace clang {
16+
namespace tidy {
17+
namespace altera {
18+
19+
void IdDependentBackwardBranchCheck::registerMatchers(MatchFinder *Finder) {
20+
// Prototype to identify all variables which hold a thread-variant ID.
21+
// First Matcher just finds all the direct assignments of either ID call.
22+
const auto ThreadID = expr(hasDescendant(callExpr(callee(functionDecl(
23+
anyOf(hasName("get_global_id"), hasName("get_local_id")))))));
24+
25+
const auto RefVarOrField = forEachDescendant(
26+
stmt(anyOf(declRefExpr(to(varDecl())).bind("assign_ref_var"),
27+
memberExpr(member(fieldDecl())).bind("assign_ref_field"))));
28+
29+
Finder->addMatcher(
30+
compoundStmt(
31+
// Bind on actual get_local/global_id calls.
32+
forEachDescendant(
33+
stmt(
34+
anyOf(declStmt(hasDescendant(varDecl(hasInitializer(ThreadID))
35+
.bind("tid_dep_var"))),
36+
binaryOperator(allOf(
37+
isAssignmentOperator(), hasRHS(ThreadID),
38+
hasLHS(anyOf(
39+
declRefExpr(to(varDecl().bind("tid_dep_var"))),
40+
memberExpr(member(
41+
fieldDecl().bind("tid_dep_field")))))))))
42+
.bind("straight_assignment"))),
43+
this);
44+
45+
// Bind all VarDecls that include an initializer with a variable DeclRefExpr
46+
// (in case it is ID-dependent).
47+
Finder->addMatcher(
48+
stmt(forEachDescendant(
49+
varDecl(hasInitializer(RefVarOrField)).bind("pot_tid_var"))),
50+
this);
51+
52+
// Bind all VarDecls that are assigned a value with a variable DeclRefExpr (in
53+
// case it is ID-dependent).
54+
Finder->addMatcher(
55+
stmt(forEachDescendant(binaryOperator(
56+
allOf(isAssignmentOperator(), hasRHS(RefVarOrField),
57+
hasLHS(anyOf(
58+
declRefExpr(to(varDecl().bind("pot_tid_var"))),
59+
memberExpr(member(fieldDecl().bind("pot_tid_field"))))))))),
60+
this);
61+
62+
// Second Matcher looks for branch statements inside of loops and bind on the
63+
// condition expression IF it either calls an ID function or has a variable
64+
// DeclRefExpr. DeclRefExprs are checked later to confirm whether the variable
65+
// is ID-dependent.
66+
const auto CondExpr =
67+
expr(anyOf(hasDescendant(callExpr(callee(functionDecl(
68+
anyOf(hasName("get_global_id"),
69+
hasName("get_local_id")))))
70+
.bind("id_call")),
71+
hasDescendant(stmt(anyOf(declRefExpr(to(varDecl())),
72+
memberExpr(member(fieldDecl())))))))
73+
.bind("cond_expr");
74+
Finder->addMatcher(stmt(anyOf(forStmt(hasCondition(CondExpr)),
75+
doStmt(hasCondition(CondExpr)),
76+
whileStmt(hasCondition(CondExpr))))
77+
.bind("backward_branch"),
78+
this);
79+
}
80+
81+
IdDependentBackwardBranchCheck::IdDependencyRecord *
82+
IdDependentBackwardBranchCheck::hasIdDepVar(const Expr *Expression) {
83+
if (const auto *Declaration = dyn_cast<DeclRefExpr>(Expression)) {
84+
// It is a DeclRefExpr, so check if it's an ID-dependent variable.
85+
const auto *CheckVariable = dyn_cast<VarDecl>(Declaration->getDecl());
86+
auto FoundVariable = IdDepVarsMap.find(CheckVariable);
87+
if (FoundVariable == IdDepVarsMap.end())
88+
return nullptr;
89+
return &(FoundVariable->second);
90+
}
91+
for (const auto *Child : Expression->children())
92+
if (const auto *ChildExpression = dyn_cast<Expr>(Child))
93+
if (IdDependencyRecord *Result = hasIdDepVar(ChildExpression))
94+
return Result;
95+
return nullptr;
96+
}
97+
98+
IdDependentBackwardBranchCheck::IdDependencyRecord *
99+
IdDependentBackwardBranchCheck::hasIdDepField(const Expr *Expression) {
100+
if (const auto *MemberExpression = dyn_cast<MemberExpr>(Expression)) {
101+
const auto *CheckField =
102+
dyn_cast<FieldDecl>(MemberExpression->getMemberDecl());
103+
auto FoundField = IdDepFieldsMap.find(CheckField);
104+
if (FoundField == IdDepFieldsMap.end())
105+
return nullptr;
106+
return &(FoundField->second);
107+
}
108+
for (const auto *Child : Expression->children())
109+
if (const auto *ChildExpression = dyn_cast<Expr>(Child))
110+
if (IdDependencyRecord *Result = hasIdDepField(ChildExpression))
111+
return Result;
112+
return nullptr;
113+
}
114+
115+
void IdDependentBackwardBranchCheck::saveIdDepVar(const Stmt *Statement,
116+
const VarDecl *Variable) {
117+
// Record that this variable is thread-dependent.
118+
IdDepVarsMap[Variable] =
119+
IdDependencyRecord(Variable, Variable->getBeginLoc(),
120+
Twine("assignment of ID-dependent variable ") +
121+
Variable->getNameAsString());
122+
}
123+
124+
void IdDependentBackwardBranchCheck::saveIdDepField(const Stmt *Statement,
125+
const FieldDecl *Field) {
126+
// Record that this field is thread-dependent.
127+
IdDepFieldsMap[Field] = IdDependencyRecord(
128+
Field, Statement->getBeginLoc(),
129+
Twine("assignment of ID-dependent field ") + Field->getNameAsString());
130+
}
131+
132+
void IdDependentBackwardBranchCheck::saveIdDepVarFromReference(
133+
const DeclRefExpr *RefExpr, const MemberExpr *MemExpr,
134+
const VarDecl *PotentialVar) {
135+
// If the variable is already in IdDepVarsMap, ignore it.
136+
if (IdDepVarsMap.find(PotentialVar) != IdDepVarsMap.end())
137+
return;
138+
std::string Message;
139+
llvm::raw_string_ostream StringStream(Message);
140+
StringStream << "inferred assignment of ID-dependent value from "
141+
"ID-dependent ";
142+
if (RefExpr) {
143+
const auto *RefVar = dyn_cast<VarDecl>(RefExpr->getDecl());
144+
// If variable isn't ID-dependent, but RefVar is.
145+
if (IdDepVarsMap.find(RefVar) != IdDepVarsMap.end())
146+
StringStream << "variable " << RefVar->getNameAsString();
147+
}
148+
if (MemExpr) {
149+
const auto *RefField = dyn_cast<FieldDecl>(MemExpr->getMemberDecl());
150+
// If variable isn't ID-dependent, but RefField is.
151+
if (IdDepFieldsMap.find(RefField) != IdDepFieldsMap.end())
152+
StringStream << "member " << RefField->getNameAsString();
153+
}
154+
IdDepVarsMap[PotentialVar] =
155+
IdDependencyRecord(PotentialVar, PotentialVar->getBeginLoc(), Message);
156+
}
157+
158+
void IdDependentBackwardBranchCheck::saveIdDepFieldFromReference(
159+
const DeclRefExpr *RefExpr, const MemberExpr *MemExpr,
160+
const FieldDecl *PotentialField) {
161+
// If the field is already in IdDepFieldsMap, ignore it.
162+
if (IdDepFieldsMap.find(PotentialField) != IdDepFieldsMap.end())
163+
return;
164+
std::string Message;
165+
llvm::raw_string_ostream StringStream(Message);
166+
StringStream << "inferred assignment of ID-dependent member from "
167+
"ID-dependent ";
168+
if (RefExpr) {
169+
const auto *RefVar = dyn_cast<VarDecl>(RefExpr->getDecl());
170+
// If field isn't ID-dependent, but RefVar is.
171+
if (IdDepVarsMap.find(RefVar) != IdDepVarsMap.end())
172+
StringStream << "variable " << RefVar->getNameAsString();
173+
}
174+
if (MemExpr) {
175+
const auto *RefField = dyn_cast<FieldDecl>(MemExpr->getMemberDecl());
176+
if (IdDepFieldsMap.find(RefField) != IdDepFieldsMap.end())
177+
StringStream << "member " << RefField->getNameAsString();
178+
}
179+
IdDepFieldsMap[PotentialField] = IdDependencyRecord(
180+
PotentialField, PotentialField->getBeginLoc(), Message);
181+
}
182+
183+
IdDependentBackwardBranchCheck::LoopType
184+
IdDependentBackwardBranchCheck::getLoopType(const Stmt *Loop) {
185+
switch (Loop->getStmtClass()) {
186+
case Stmt::DoStmtClass:
187+
return DoLoop;
188+
case Stmt::WhileStmtClass:
189+
return WhileLoop;
190+
case Stmt::ForStmtClass:
191+
return ForLoop;
192+
default:
193+
return UnknownLoop;
194+
}
195+
}
196+
197+
void IdDependentBackwardBranchCheck::check(
198+
const MatchFinder::MatchResult &Result) {
199+
// The first half of the callback only deals with identifying and storing
200+
// ID-dependency information into the IdDepVars and IdDepFields maps.
201+
const auto *Variable = Result.Nodes.getNodeAs<VarDecl>("tid_dep_var");
202+
const auto *Field = Result.Nodes.getNodeAs<FieldDecl>("tid_dep_field");
203+
const auto *Statement = Result.Nodes.getNodeAs<Stmt>("straight_assignment");
204+
const auto *RefExpr = Result.Nodes.getNodeAs<DeclRefExpr>("assign_ref_var");
205+
const auto *MemExpr = Result.Nodes.getNodeAs<MemberExpr>("assign_ref_field");
206+
const auto *PotentialVar = Result.Nodes.getNodeAs<VarDecl>("pot_tid_var");
207+
const auto *PotentialField =
208+
Result.Nodes.getNodeAs<FieldDecl>("pot_tid_field");
209+
210+
// Save variables and fields assigned directly through ID function calls.
211+
if (Statement && (Variable || Field)) {
212+
if (Variable)
213+
saveIdDepVar(Statement, Variable);
214+
else if (Field)
215+
saveIdDepField(Statement, Field);
216+
}
217+
218+
// Save variables assigned to values of Id-dependent variables and fields.
219+
if ((RefExpr || MemExpr) && PotentialVar)
220+
saveIdDepVarFromReference(RefExpr, MemExpr, PotentialVar);
221+
222+
// Save fields assigned to values of ID-dependent variables and fields.
223+
if ((RefExpr || MemExpr) && PotentialField)
224+
saveIdDepFieldFromReference(RefExpr, MemExpr, PotentialField);
225+
226+
// The second part of the callback deals with checking if a branch inside a
227+
// loop is thread dependent.
228+
const auto *CondExpr = Result.Nodes.getNodeAs<Expr>("cond_expr");
229+
const auto *IDCall = Result.Nodes.getNodeAs<CallExpr>("id_call");
230+
const auto *Loop = Result.Nodes.getNodeAs<Stmt>("backward_branch");
231+
if (!Loop)
232+
return;
233+
LoopType Type = getLoopType(Loop);
234+
if (CondExpr) {
235+
if (IDCall) { // Conditional expression calls an ID function directly.
236+
diag(CondExpr->getBeginLoc(),
237+
"backward branch (%select{do|while|for}0 loop) is ID-dependent due "
238+
"to ID function call and may cause performance degradation")
239+
<< Type;
240+
return;
241+
}
242+
// Conditional expression has DeclRefExpr(s), check ID-dependency.
243+
IdDependencyRecord *IdDepVar = hasIdDepVar(CondExpr);
244+
IdDependencyRecord *IdDepField = hasIdDepField(CondExpr);
245+
if (IdDepVar) {
246+
// Change one of these to a Note
247+
diag(IdDepVar->Location, IdDepVar->Message, DiagnosticIDs::Note);
248+
diag(CondExpr->getBeginLoc(),
249+
"backward branch (%select{do|while|for}0 loop) is ID-dependent due "
250+
"to variable reference to %1 and may cause performance degradation")
251+
<< Type << IdDepVar->VariableDeclaration;
252+
} else if (IdDepField) {
253+
diag(IdDepField->Location, IdDepField->Message, DiagnosticIDs::Note);
254+
diag(CondExpr->getBeginLoc(),
255+
"backward branch (%select{do|while|for}0 loop) is ID-dependent due "
256+
"to member reference to %1 and may cause performance degradation")
257+
<< Type << IdDepField->FieldDeclaration;
258+
}
259+
}
260+
}
261+
262+
} // namespace altera
263+
} // namespace tidy
264+
} // namespace clang

0 commit comments

Comments
 (0)