Skip to content

Commit df5aaf4

Browse files
committed
merge main into amd-staging
Change-Id: I695e3cd9f2d2ac11bb349154ec67f0bf758aea1e
2 parents efd092b + 882b4fc commit df5aaf4

File tree

192 files changed

+4868
-2334
lines changed

Some content is hidden

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

192 files changed

+4868
-2334
lines changed

bolt/lib/Passes/CacheMetrics.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,20 @@
1414
#include "bolt/Passes/CacheMetrics.h"
1515
#include "bolt/Core/BinaryBasicBlock.h"
1616
#include "bolt/Core/BinaryFunction.h"
17-
#include "llvm/Support/CommandLine.h"
1817
#include <unordered_map>
1918

2019
using namespace llvm;
2120
using namespace bolt;
2221

23-
namespace opts {
24-
25-
extern cl::OptionCategory BoltOptCategory;
26-
27-
extern cl::opt<unsigned> ITLBPageSize;
28-
extern cl::opt<unsigned> ITLBEntries;
29-
30-
} // namespace opts
31-
3222
namespace {
3323

24+
/// The following constants are used to estimate the number of i-TLB cache
25+
/// misses for a given code layout. Empirically the values result in high
26+
/// correlations between the estimations and the perf measurements.
27+
/// The constants do not affect the code layout algorithms.
28+
constexpr unsigned ITLBPageSize = 4096;
29+
constexpr unsigned ITLBEntries = 16;
30+
3431
/// Initialize and return a position map for binary basic blocks
3532
void extractBasicBlockInfo(
3633
const std::vector<BinaryFunction *> &BinaryFunctions,
@@ -133,9 +130,6 @@ double expectedCacheHitRatio(
133130
const std::vector<BinaryFunction *> &BinaryFunctions,
134131
const std::unordered_map<BinaryBasicBlock *, uint64_t> &BBAddr,
135132
const std::unordered_map<BinaryBasicBlock *, uint64_t> &BBSize) {
136-
137-
const double PageSize = opts::ITLBPageSize;
138-
const uint64_t CacheEntries = opts::ITLBEntries;
139133
std::unordered_map<const BinaryFunction *, Predecessors> Calls =
140134
extractFunctionCalls(BinaryFunctions);
141135
// Compute 'hotness' of the functions
@@ -155,7 +149,8 @@ double expectedCacheHitRatio(
155149
for (BinaryFunction *BF : BinaryFunctions) {
156150
if (BF->getLayout().block_empty())
157151
continue;
158-
double Page = BBAddr.at(BF->getLayout().block_front()) / PageSize;
152+
const uint64_t Page =
153+
BBAddr.at(BF->getLayout().block_front()) / ITLBPageSize;
159154
PageSamples[Page] += FunctionSamples.at(BF);
160155
}
161156

@@ -166,15 +161,17 @@ double expectedCacheHitRatio(
166161
if (BF->getLayout().block_empty() || FunctionSamples.at(BF) == 0.0)
167162
continue;
168163
double Samples = FunctionSamples.at(BF);
169-
double Page = BBAddr.at(BF->getLayout().block_front()) / PageSize;
164+
const uint64_t Page =
165+
BBAddr.at(BF->getLayout().block_front()) / ITLBPageSize;
170166
// The probability that the page is not present in the cache
171-
double MissProb = pow(1.0 - PageSamples[Page] / TotalSamples, CacheEntries);
167+
const double MissProb =
168+
pow(1.0 - PageSamples[Page] / TotalSamples, ITLBEntries);
172169

173170
// Processing all callers of the function
174171
for (std::pair<BinaryFunction *, uint64_t> Pair : Calls[BF]) {
175172
BinaryFunction *SrcFunction = Pair.first;
176-
double SrcPage =
177-
BBAddr.at(SrcFunction->getLayout().block_front()) / PageSize;
173+
const uint64_t SrcPage =
174+
BBAddr.at(SrcFunction->getLayout().block_front()) / ITLBPageSize;
178175
// Is this a 'long' or a 'short' call?
179176
if (Page != SrcPage) {
180177
// This is a miss

bolt/lib/Rewrite/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ set(LLVM_LINK_COMPONENTS
55
MC
66
Object
77
Support
8-
DWARFLinkerBase
98
DWARFLinker
9+
DWARFLinkerClassic
1010
AsmPrinter
1111
TargetParser
1212
)

clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "StaticAssertCheck.h"
10+
#include "../utils/Matchers.h"
1011
#include "clang/AST/ASTContext.h"
1112
#include "clang/AST/Expr.h"
1213
#include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -45,13 +46,20 @@ void StaticAssertCheck::registerMatchers(MatchFinder *Finder) {
4546
IsAlwaysFalse);
4647
auto NonConstexprFunctionCall =
4748
callExpr(hasDeclaration(functionDecl(unless(isConstexpr()))));
49+
auto NonConstexprVariableReference =
50+
declRefExpr(to(varDecl(unless(isConstexpr()))),
51+
unless(hasAncestor(expr(matchers::hasUnevaluatedContext()))),
52+
unless(hasAncestor(typeLoc())));
53+
54+
auto NonConstexprCode =
55+
expr(anyOf(NonConstexprFunctionCall, NonConstexprVariableReference));
4856
auto AssertCondition =
4957
expr(
5058
anyOf(expr(ignoringParenCasts(anyOf(
5159
AssertExprRoot, unaryOperator(hasUnaryOperand(
5260
ignoringParenCasts(AssertExprRoot)))))),
5361
anything()),
54-
unless(findAll(NonConstexprFunctionCall)))
62+
unless(NonConstexprCode), unless(hasDescendant(NonConstexprCode)))
5563
.bind("condition");
5664
auto Condition =
5765
anyOf(ignoringParenImpCasts(callExpr(

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Improvements to clang-tidy
119119

120120
- Improved `--dump-config` to print check options in alphabetical order.
121121

122-
- Improved :program:`clang-tidy-diff.py` script.
122+
- Improved :program:`clang-tidy-diff.py` script.
123123
* Return exit code `1` if any :program:`clang-tidy` subprocess exits with
124124
a non-zero code or if exporting fixes fails.
125125

@@ -381,6 +381,10 @@ Changes in existing checks
381381
<clang-tidy/checks/misc/redundant-expression>` check to ignore
382382
false-positives in unevaluated context (e.g., ``decltype``).
383383

384+
- Improved :doc:`misc-static-assert
385+
<clang-tidy/checks/misc/static-assert>` check to ignore false-positives when
386+
referring to non-``constexpr`` variables in non-unevaluated context.
387+
384388
- Improved :doc:`misc-unused-using-decls
385389
<clang-tidy/checks/misc/unused-using-decls>` check to avoid false positive when
386390
using in elaborated type and only check cpp files.

clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,48 @@ void print(...);
2020
#define my_macro() assert(0 == 1)
2121
// CHECK-FIXES: #define my_macro() assert(0 == 1)
2222

23+
namespace PR24066 {
24+
25+
void referenceMember() {
26+
struct {
27+
int A;
28+
int B;
29+
} S;
30+
assert(&S.B - &S.A == 1);
31+
}
32+
33+
const int X = 1;
34+
void referenceVariable() {
35+
assert(X > 0);
36+
}
37+
38+
39+
constexpr int Y = 1;
40+
void referenceConstexprVariable() {
41+
assert(Y > 0);
42+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be replaced by static_assert() [misc-static-assert]
43+
// CHECK-FIXES-CXX11: {{^ }}static_assert(Y > 0, "");
44+
// CHECK-FIXES-CXX17: {{^ }}static_assert(Y > 0);
45+
}
46+
47+
void useInSizeOf() {
48+
char a = 0;
49+
assert(sizeof(a) == 1U);
50+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be replaced by static_assert() [misc-static-assert]
51+
// CHECK-FIXES-CXX11: {{^ }}static_assert(sizeof(a) == 1U, "");
52+
// CHECK-FIXES-CXX17: {{^ }}static_assert(sizeof(a) == 1U);
53+
}
54+
55+
void useInDecltype() {
56+
char a = 0;
57+
assert(static_cast<decltype(a)>(256) == 0);
58+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be replaced by static_assert() [misc-static-assert]
59+
// CHECK-FIXES-CXX11: {{^ }}static_assert(static_cast<decltype(a)>(256) == 0, "");
60+
// CHECK-FIXES-CXX17: {{^ }}static_assert(static_cast<decltype(a)>(256) == 0);
61+
}
62+
63+
}
64+
2365
constexpr bool myfunc(int a, int b) { return a * b == 0; }
2466

2567
typedef __SIZE_TYPE__ size_t;

clang/docs/ReleaseNotes.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,29 @@ These changes are ones which we think may surprise users when upgrading to
3737
Clang |release| because of the opportunity they pose for disruption to existing
3838
code bases.
3939

40+
- Fix a bug in reversed argument for templated operators.
41+
This breaks code in C++20 which was previously accepted in C++17.
42+
Clang did not properly diagnose such casese in C++20 before this change. Eg:
43+
44+
.. code-block:: cpp
45+
46+
struct P {};
47+
template<class S> bool operator==(const P&, const S&);
48+
49+
struct A : public P {};
50+
struct B : public P {};
51+
52+
// This equality is now ambiguous in C++20.
53+
bool ambiguous(A a, B b) { return a == b; }
54+
55+
template<class S> bool operator!=(const P&, const S&);
56+
// Ok. Found a matching operator!=.
57+
bool fine(A a, B b) { return a == b; }
58+
59+
To reduce such widespread breakages, as an extension, Clang accepts this code
60+
with an existing warning ``-Wambiguous-reversed-operator`` warning.
61+
Fixes `GH <https://github.com/llvm/llvm-project/issues/53954>`_.
62+
4063
- The CMake variable ``GCC_INSTALL_PREFIX`` (which sets the default
4164
``--gcc-toolchain=``) is deprecated and will be removed. Specify
4265
``--gcc-install-dir=`` or ``--gcc-triple=`` in a `configuration file
@@ -781,6 +804,10 @@ Bug Fixes in This Version
781804
- Clang now emits correct source location for code-coverage regions in `if constexpr`
782805
and `if consteval` branches.
783806
Fixes (`#54419 <https://github.com/llvm/llvm-project/issues/54419>`_)
807+
- Fix assertion failure when declaring a template friend function with
808+
a constrained parameter in a template class that declares a class method
809+
or lambda at different depth.
810+
Fixes (`#75426 <https://github.com/llvm/llvm-project/issues/75426>`_)
784811
- Fix an issue where clang cannot find conversion function with template
785812
parameter when instantiation of template class.
786813
Fixes (`#77583 <https://github.com/llvm/llvm-project/issues/77583>`_)

clang/include/clang/Basic/OpenACCKinds.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,37 @@ enum class OpenACCClauseKind {
103103
Copy,
104104
/// 'use_device' clause, allowed on 'host_data' construct.
105105
UseDevice,
106+
/// 'attach' clause, allowed on Compute and Combined constructs, plus 'data'
107+
/// and 'enter data'.
108+
Attach,
109+
/// 'delete' clause, allowed on the 'exit data' construct.
110+
Delete,
111+
/// 'detach' clause, allowed on the 'exit data' construct.
112+
Detach,
113+
/// 'device' clause, allowed on the 'update' construct.
114+
Device,
115+
/// 'deviceptr' clause, allowed on Compute and Combined Constructs, plus
116+
/// 'data' and 'declare'.
117+
DevicePtr,
118+
/// 'device_resident' clause, allowed on the 'declare' construct.
119+
DeviceResident,
120+
/// 'firstprivate' clause, allowed on 'parallel', 'serial', 'parallel loop',
121+
/// and 'serial loop' constructs.
122+
FirstPrivate,
123+
/// 'host' clause, allowed on 'update' construct.
124+
Host,
125+
/// 'link' clause, allowed on 'declare' construct.
126+
Link,
127+
/// 'no_create' clause, allowed on allowed on Compute and Combined constructs,
128+
/// plus 'data'.
129+
NoCreate,
130+
/// 'present' clause, allowed on Compute and Combined constructs, plus 'data'
131+
/// and 'declare'.
132+
Present,
133+
/// 'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel
134+
/// loop', and 'serial loop' constructs.
135+
Private,
136+
106137
/// Represents an invalid clause, for the purposes of parsing.
107138
Invalid,
108139
};

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,8 +1451,10 @@ WhitespaceManager::CellDescriptions WhitespaceManager::getCells(unsigned Start,
14511451
} else if (C.Tok->is(tok::comma)) {
14521452
if (!Cells.empty())
14531453
Cells.back().EndIndex = i;
1454-
if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
1454+
if (const auto *Next = C.Tok->getNextNonComment();
1455+
Next && Next->isNot(tok::r_brace)) { // dangling comma
14551456
++Cell;
1457+
}
14561458
}
14571459
} else if (Depth == 1) {
14581460
if (C.Tok == MatchingParen) {

clang/lib/Parse/ParseOpenACC.cpp

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,29 @@ OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
8787
if (!Tok.is(tok::identifier))
8888
return OpenACCClauseKind::Invalid;
8989

90+
// TODO: ERICH: add new clauses here.
9091
return llvm::StringSwitch<OpenACCClauseKind>(
9192
Tok.getIdentifierInfo()->getName())
93+
.Case("attach",OpenACCClauseKind::Attach)
9294
.Case("auto", OpenACCClauseKind::Auto)
9395
.Case("copy", OpenACCClauseKind::Copy)
9496
.Case("default", OpenACCClauseKind::Default)
97+
.Case("delete", OpenACCClauseKind::Delete)
98+
.Case("detach", OpenACCClauseKind::Detach)
99+
.Case("device", OpenACCClauseKind::Device)
100+
.Case("device_resident", OpenACCClauseKind::DeviceResident)
101+
.Case("deviceptr", OpenACCClauseKind::DevicePtr)
95102
.Case("finalize", OpenACCClauseKind::Finalize)
103+
.Case("firstprivate", OpenACCClauseKind::FirstPrivate)
104+
.Case("host", OpenACCClauseKind::Host)
96105
.Case("if", OpenACCClauseKind::If)
97106
.Case("if_present", OpenACCClauseKind::IfPresent)
98107
.Case("independent", OpenACCClauseKind::Independent)
108+
.Case("link", OpenACCClauseKind::Link)
109+
.Case("no_create", OpenACCClauseKind::NoCreate)
99110
.Case("nohost", OpenACCClauseKind::NoHost)
111+
.Case("present", OpenACCClauseKind::Present)
112+
.Case("private", OpenACCClauseKind::Private)
100113
.Case("self", OpenACCClauseKind::Self)
101114
.Case("seq", OpenACCClauseKind::Seq)
102115
.Case("use_device", OpenACCClauseKind::UseDevice)
@@ -331,14 +344,55 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) {
331344
return DirKind;
332345
}
333346

347+
enum ClauseParensKind {
348+
None,
349+
Optional,
350+
Required
351+
};
352+
353+
ClauseParensKind getClauseParensKind(OpenACCClauseKind Kind) {
354+
switch (Kind) {
355+
case OpenACCClauseKind::Self:
356+
return ClauseParensKind::Optional;
357+
358+
case OpenACCClauseKind::Default:
359+
case OpenACCClauseKind::If:
360+
case OpenACCClauseKind::Copy:
361+
case OpenACCClauseKind::UseDevice:
362+
case OpenACCClauseKind::NoCreate:
363+
case OpenACCClauseKind::Present:
364+
case OpenACCClauseKind::DevicePtr:
365+
case OpenACCClauseKind::Attach:
366+
case OpenACCClauseKind::Detach:
367+
case OpenACCClauseKind::Private:
368+
case OpenACCClauseKind::FirstPrivate:
369+
case OpenACCClauseKind::Delete:
370+
case OpenACCClauseKind::DeviceResident:
371+
case OpenACCClauseKind::Device:
372+
case OpenACCClauseKind::Link:
373+
case OpenACCClauseKind::Host:
374+
return ClauseParensKind::Required;
375+
376+
case OpenACCClauseKind::Auto:
377+
case OpenACCClauseKind::Finalize:
378+
case OpenACCClauseKind::IfPresent:
379+
case OpenACCClauseKind::Independent:
380+
case OpenACCClauseKind::Invalid:
381+
case OpenACCClauseKind::NoHost:
382+
case OpenACCClauseKind::Seq:
383+
case OpenACCClauseKind::Worker:
384+
case OpenACCClauseKind::Vector:
385+
return ClauseParensKind::None;
386+
}
387+
llvm_unreachable("Unhandled clause kind");
388+
}
389+
334390
bool ClauseHasOptionalParens(OpenACCClauseKind Kind) {
335-
return Kind == OpenACCClauseKind::Self;
391+
return getClauseParensKind(Kind) == ClauseParensKind::Optional;
336392
}
337393

338394
bool ClauseHasRequiredParens(OpenACCClauseKind Kind) {
339-
return Kind == OpenACCClauseKind::Default || Kind == OpenACCClauseKind::If ||
340-
Kind == OpenACCClauseKind::Copy ||
341-
Kind == OpenACCClauseKind::UseDevice;
395+
return getClauseParensKind(Kind) == ClauseParensKind::Required;
342396
}
343397

344398
ExprResult ParseOpenACCConditionalExpr(Parser &P) {
@@ -463,8 +517,20 @@ bool Parser::ParseOpenACCClauseParams(OpenACCClauseKind Kind) {
463517
return true;
464518
break;
465519
}
466-
case OpenACCClauseKind::UseDevice:
520+
case OpenACCClauseKind::Attach:
467521
case OpenACCClauseKind::Copy:
522+
case OpenACCClauseKind::Delete:
523+
case OpenACCClauseKind::Detach:
524+
case OpenACCClauseKind::Device:
525+
case OpenACCClauseKind::DeviceResident:
526+
case OpenACCClauseKind::DevicePtr:
527+
case OpenACCClauseKind::FirstPrivate:
528+
case OpenACCClauseKind::Host:
529+
case OpenACCClauseKind::Link:
530+
case OpenACCClauseKind::NoCreate:
531+
case OpenACCClauseKind::Present:
532+
case OpenACCClauseKind::Private:
533+
case OpenACCClauseKind::UseDevice:
468534
if (ParseOpenACCClauseVarList(Kind))
469535
return true;
470536
break;

0 commit comments

Comments
 (0)