Skip to content

Commit e8d3cc9

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:96568f3539d8a72432a03257a7a8ed2f36014b59 into amd-gfx:112cc7959e1b
Local branch amd-gfx 112cc79 Merged main:5e9dd8827b3ccd03f8499b610deb6accd2d71d21 into amd-gfx:99bda3f8b18c Remote branch main 96568f3 [llvm][ctx_profile] Add instrumentation lowering (llvm#90821)
2 parents 112cc79 + 96568f3 commit e8d3cc9

File tree

591 files changed

+14294
-4584
lines changed

Some content is hidden

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

591 files changed

+14294
-4584
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/llvm/lib/Analysis/ScalarEvolution.cpp @nikic
2424
/llvm/lib/Analysis/ValueTracking.cpp @nikic
2525
/llvm/lib/IR/ConstantRange.cpp @nikic
26+
/llvm/lib/IR/Core.cpp @nikic
2627
/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @nikic
2728
/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @nikic
2829
/llvm/lib/Transforms/InstCombine/ @nikic
@@ -63,8 +64,8 @@ clang/test/AST/Interp/ @tbaederr
6364
/mlir/Dialect/*/Transforms/Bufferize.cpp @matthias-springer
6465

6566
# Linalg Dialect in MLIR.
66-
/mlir/include/mlir/Dialect/Linalg/* @dcaballe @nicolasvasilache
67-
/mlir/lib/Dialect/Linalg/* @dcaballe @nicolasvasilache
67+
/mlir/include/mlir/Dialect/Linalg/* @dcaballe @nicolasvasilache @rengolin
68+
/mlir/lib/Dialect/Linalg/* @dcaballe @nicolasvasilache @rengolin
6869
/mlir/lib/Dialect/Linalg/Transforms/DecomposeLinalgOps.cpp @MaheshRavishankar @nicolasvasilache
6970
/mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp @MaheshRavishankar @nicolasvasilache
7071
/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp @MaheshRavishankar @nicolasvasilache

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,8 @@ class BinaryFunction {
930930
return const_cast<BinaryFunction *>(this)->getInstructionAtOffset(Offset);
931931
}
932932

933+
std::optional<MCInst> disassembleInstructionAtOffset(uint64_t Offset) const;
934+
933935
/// Return offset for the first instruction. If there is data at the
934936
/// beginning of a function then offset of the first instruction could
935937
/// be different from 0

bolt/include/bolt/Passes/FrameAnalysis.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@ class FrameAnalysis {
170170
std::unique_ptr<StackPointerTracking>>
171171
SPTMap;
172172

173-
/// A vector that stores ids of the allocators that are used in SPT
174-
/// computation
175-
std::vector<MCPlusBuilder::AllocatorIdTy> SPTAllocatorsId;
176-
177173
public:
178174
explicit FrameAnalysis(BinaryContext &BC, BinaryFunctionCallGraph &CG);
179175

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,21 @@ void BinaryFunction::handleAArch64IndirectCall(MCInst &Instruction,
11671167
}
11681168
}
11691169

1170+
std::optional<MCInst>
1171+
BinaryFunction::disassembleInstructionAtOffset(uint64_t Offset) const {
1172+
assert(CurrentState == State::Empty && "Function should not be disassembled");
1173+
assert(Offset < MaxSize && "Invalid offset");
1174+
ErrorOr<ArrayRef<unsigned char>> FunctionData = getData();
1175+
assert(FunctionData && "Cannot get function as data");
1176+
MCInst Instr;
1177+
uint64_t InstrSize = 0;
1178+
const uint64_t InstrAddress = getAddress() + Offset;
1179+
if (BC.DisAsm->getInstruction(Instr, InstrSize, FunctionData->slice(Offset),
1180+
InstrAddress, nulls()))
1181+
return Instr;
1182+
return std::nullopt;
1183+
}
1184+
11701185
Error BinaryFunction::disassemble() {
11711186
NamedRegionTimer T("disassemble", "Disassemble function", "buildfuncs",
11721187
"Build Binary Functions", opts::TimeBuild);

bolt/lib/Passes/FrameAnalysis.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,6 @@ FrameAnalysis::FrameAnalysis(BinaryContext &BC, BinaryFunctionCallGraph &CG)
561561
NamedRegionTimer T1("clearspt", "clear spt", "FA", "FA breakdown",
562562
opts::TimeFA);
563563
clearSPTMap();
564-
565-
// Clean up memory allocated for annotation values
566-
if (!opts::NoThreads)
567-
for (MCPlusBuilder::AllocatorIdTy Id : SPTAllocatorsId)
568-
BC.MIB->freeValuesAllocator(Id);
569564
}
570565
}
571566

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,19 @@ bool DataAggregator::doInterBranch(BinaryFunction *FromFunc,
773773

774774
bool DataAggregator::doBranch(uint64_t From, uint64_t To, uint64_t Count,
775775
uint64_t Mispreds) {
776+
bool IsReturn = false;
776777
auto handleAddress = [&](uint64_t &Addr, bool IsFrom) -> BinaryFunction * {
777778
if (BinaryFunction *Func = getBinaryFunctionContainingAddress(Addr)) {
778779
Addr -= Func->getAddress();
780+
if (IsFrom) {
781+
auto checkReturn = [&](auto MaybeInst) {
782+
IsReturn = MaybeInst && BC->MIB->isReturn(*MaybeInst);
783+
};
784+
if (Func->hasInstructions())
785+
checkReturn(Func->getInstructionAtOffset(Addr));
786+
else
787+
checkReturn(Func->disassembleInstructionAtOffset(Addr));
788+
}
779789

780790
if (BAT)
781791
Addr = BAT->translate(Func->getAddress(), Addr, IsFrom);
@@ -792,6 +802,9 @@ bool DataAggregator::doBranch(uint64_t From, uint64_t To, uint64_t Count,
792802
};
793803

794804
BinaryFunction *FromFunc = handleAddress(From, /*IsFrom=*/true);
805+
// Ignore returns.
806+
if (IsReturn)
807+
return true;
795808
BinaryFunction *ToFunc = handleAddress(To, /*IsFrom=*/false);
796809
if (!FromFunc && !ToFunc)
797810
return false;

bolt/test/X86/bolt-address-translation-yaml.test

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN: llvm-bolt %t.exe -data %t.fdata -w %t.yaml-fdata -o /dev/null
1313
RUN: FileCheck --input-file %t.yaml-fdata --check-prefix YAML-BAT-CHECK %s
1414

1515
# Test resulting YAML profile with the original binary (no-stale mode)
16-
RUN: llvm-bolt %t.exe -data %t.yaml -o %t.null -dyno-stats \
16+
RUN: llvm-bolt %t.exe -data %t.yaml -o %t.null -dyno-stats 2>&1 \
1717
RUN: | FileCheck --check-prefix CHECK-BOLT-YAML %s
1818

1919
WRITE-BAT-CHECK: BOLT-INFO: Wrote 5 BAT maps
@@ -63,7 +63,8 @@ YAML-BAT-CHECK-NEXT: blocks:
6363
YAML-BAT-CHECK: - bid: 1
6464
YAML-BAT-CHECK-NEXT: insns: [[#]]
6565
YAML-BAT-CHECK-NEXT: hash: 0xD70DC695320E0010
66-
YAML-BAT-CHECK-NEXT: succ: {{.*}} { bid: 2, cnt: [[#]] }
66+
YAML-BAT-CHECK-NEXT: succ: {{.*}} { bid: 2, cnt: [[#]]
6767

6868
CHECK-BOLT-YAML: pre-processing profile using YAML profile reader
6969
CHECK-BOLT-YAML-NEXT: 5 out of 16 functions in the binary (31.2%) have non-empty execution profile
70+
CHECK-BOLT-YAML-NOT: invalid (possibly stale) profile

bolt/test/runtime/bolt-reserved.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// REQUIRES: system-linux
2+
3+
/*
4+
* Check that llvm-bolt uses reserved space in a binary for allocating
5+
* new sections.
6+
*/
7+
8+
// RUN: %clang %s -o %t.exe -Wl,-q
9+
// RUN: llvm-bolt %t.exe -o %t.bolt.exe 2>&1 | FileCheck %s
10+
// RUN: %t.bolt.exe
11+
12+
// CHECK: BOLT-INFO: using reserved space
13+
14+
/*
15+
* Check that llvm-bolt detects a condition when the reserved space is
16+
* not enough for allocating new sections.
17+
*/
18+
19+
// RUN: %clang %s -o %t.exe -Wl,--no-eh-frame-hdr -Wl,-q -DTINY
20+
// RUN: not llvm-bolt %t.exe -o %t.bolt.exe 2>&1 | \
21+
// RUN: FileCheck %s --check-prefix=CHECK-TINY
22+
23+
// CHECK-TINY: BOLT-ERROR: reserved space (1 byte) is smaller than required
24+
25+
#ifdef TINY
26+
#define RSIZE "1"
27+
#else
28+
#define RSIZE "8192 * 1024"
29+
#endif
30+
31+
asm(".pushsection .text \n\
32+
.globl __bolt_reserved_start \n\
33+
.type __bolt_reserved_start, @object \n\
34+
__bolt_reserved_start: \n\
35+
.space " RSIZE " \n\
36+
.globl __bolt_reserved_end \n\
37+
__bolt_reserved_end: \n\
38+
.popsection");
39+
40+
int main() { return 0; }

clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "SignedBitwiseCheck.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
#include "clang/ASTMatchers/ASTMatchers.h"
1213

1314
using namespace clang::ast_matchers;
1415
using namespace clang::ast_matchers::internal;
@@ -29,8 +30,8 @@ void SignedBitwiseCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
2930
void SignedBitwiseCheck::registerMatchers(MatchFinder *Finder) {
3031
const auto SignedIntegerOperand =
3132
(IgnorePositiveIntegerLiterals
32-
? expr(ignoringImpCasts(hasType(isSignedInteger())),
33-
unless(integerLiteral()))
33+
? expr(ignoringImpCasts(
34+
allOf(hasType(isSignedInteger()), unless(integerLiteral()))))
3435
: expr(ignoringImpCasts(hasType(isSignedInteger()))))
3536
.bind("signed-operand");
3637

clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ void StaticAccessedThroughInstanceCheck::check(
5959

6060
const Expr *BaseExpr = MemberExpression->getBase();
6161

62-
// Do not warn for overloaded -> operators.
63-
if (isa<CXXOperatorCallExpr>(BaseExpr))
64-
return;
65-
6662
const QualType BaseType =
6763
BaseExpr->getType()->isPointerType()
6864
? BaseExpr->getType()->getPointeeType().getUnqualifiedType()
@@ -89,17 +85,30 @@ void StaticAccessedThroughInstanceCheck::check(
8985
return;
9086

9187
SourceLocation MemberExprStartLoc = MemberExpression->getBeginLoc();
92-
auto Diag =
93-
diag(MemberExprStartLoc, "static member accessed through instance");
94-
95-
if (BaseExpr->HasSideEffects(*AstContext) ||
96-
getNameSpecifierNestingLevel(BaseType) > NameSpecifierNestingThreshold)
97-
return;
88+
auto CreateFix = [&] {
89+
return FixItHint::CreateReplacement(
90+
CharSourceRange::getCharRange(MemberExprStartLoc,
91+
MemberExpression->getMemberLoc()),
92+
BaseTypeName + "::");
93+
};
94+
95+
{
96+
auto Diag =
97+
diag(MemberExprStartLoc, "static member accessed through instance");
98+
99+
if (getNameSpecifierNestingLevel(BaseType) > NameSpecifierNestingThreshold)
100+
return;
101+
102+
if (!BaseExpr->HasSideEffects(*AstContext,
103+
/* IncludePossibleEffects =*/true)) {
104+
Diag << CreateFix();
105+
return;
106+
}
107+
}
98108

99-
Diag << FixItHint::CreateReplacement(
100-
CharSourceRange::getCharRange(MemberExprStartLoc,
101-
MemberExpression->getMemberLoc()),
102-
BaseTypeName + "::");
109+
diag(MemberExprStartLoc, "member base expression may carry some side effects",
110+
DiagnosticIDs::Level::Note)
111+
<< BaseExpr->getSourceRange() << CreateFix();
103112
}
104113

105114
} // namespace clang::tidy::readability

clang-tools-extra/clangd/Preamble.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,9 @@ void PreamblePatch::apply(CompilerInvocation &CI) const {
918918
// no guarantees around using arbitrary options when reusing PCHs, and
919919
// different target opts can result in crashes, see
920920
// ParsedASTTest.PreambleWithDifferentTarget.
921-
CI.TargetOpts = Baseline->TargetOpts;
921+
// Make sure this is a deep copy, as the same Baseline might be used
922+
// concurrently.
923+
*CI.TargetOpts = *Baseline->TargetOpts;
922924

923925
// No need to map an empty file.
924926
if (PatchContents.empty())

clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,10 +642,7 @@ TEST_F(TargetDeclTest, RewrittenBinaryOperator) {
642642
bool x = (Foo(1) [[!=]] Foo(2));
643643
)cpp";
644644
EXPECT_DECLS("CXXRewrittenBinaryOperator",
645-
{"std::strong_ordering operator<=>(const Foo &) const = default",
646-
Rel::TemplatePattern},
647-
{"bool operator==(const Foo &) const noexcept = default",
648-
Rel::TemplateInstantiation});
645+
{"bool operator==(const Foo &) const noexcept = default"});
649646
}
650647

651648
TEST_F(TargetDeclTest, FunctionTemplate) {

clang-tools-extra/clangd/unittests/HoverTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,7 +3091,7 @@ TEST(Hover, All) {
30913091
HI.NamespaceScope = "";
30923092
HI.Definition =
30933093
"bool operator==(const Foo &) const noexcept = default";
3094-
HI.Documentation = "Foo spaceship";
3094+
HI.Documentation = "";
30953095
}},
30963096
};
30973097

@@ -3894,7 +3894,7 @@ TEST(Hover, SpaceshipTemplateNoCrash) {
38943894
TU.ExtraArgs.push_back("-std=c++20");
38953895
auto AST = TU.build();
38963896
auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
3897-
EXPECT_EQ(HI->Documentation, "Foo bar baz");
3897+
EXPECT_EQ(HI->Documentation, "");
38983898
}
38993899

39003900
TEST(Hover, ForwardStructNoCrash) {

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ Changes in existing checks
259259
- Improved :doc:`google-runtime-int <clang-tidy/checks/google/runtime-int>`
260260
check performance through optimizations.
261261

262+
- Improved :doc:`hicpp-signed-bitwise <clang-tidy/checks/hicpp/signed-bitwise>`
263+
check by ignoring false positives involving positive integer literals behind
264+
implicit casts when `IgnorePositiveIntegerLiterals` is enabled.
265+
262266
- Improved :doc:`hicpp-ignored-remove-result <clang-tidy/checks/hicpp/ignored-remove-result>`
263267
check by ignoring other functions with same prefixes as the target specific
264268
functions.
@@ -348,6 +352,11 @@ Changes in existing checks
348352
<clang-tidy/checks/readability/redundant-inline-specifier>` check to properly
349353
emit warnings for static data member with an in-class initializer.
350354

355+
- Improved :doc:`readability-static-accessed-through-instance
356+
<clang-tidy/checks/readability/static-accessed-through-instance>` check to
357+
support calls to overloaded operators as base expression and provide fixes to
358+
expressions with side-effects.
359+
351360
- Improved :doc:`readability-static-definition-in-anonymous-namespace
352361
<clang-tidy/checks/readability/static-definition-in-anonymous-namespace>`
353362
check by resolving fix-it overlaps in template code by disregarding implicit

clang-tools-extra/docs/clang-tidy/checks/readability/static-accessed-through-instance.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ is changed to:
3535
C::E1;
3636
C::E2;
3737
38+
The `--fix` commandline option provides default support for safe fixes, whereas
39+
`--fix-notes` enables fixes that may replace expressions with side effects,
40+
potentially altering the program's behavior.

clang-tools-extra/test/clang-tidy/checkers/hicpp/signed-bitwise-integer-literals.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ void examples() {
1111
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use of a signed integer operand with a binary bitwise operator
1212

1313
unsigned URes2 = URes << 1; //Ok
14+
unsigned URes3 = URes & 1; //Ok
1415

1516
int IResult;
1617
IResult = 10 & 2; //Ok
@@ -21,6 +22,8 @@ void examples() {
2122
IResult = Int << 1;
2223
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
2324
IResult = ~0; //Ok
25+
IResult = -1 & 1;
26+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator [hicpp-signed-bitwise]
2427
}
2528

2629
enum EnumConstruction {

clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s readability-static-accessed-through-instance %t -- -- -isystem %S/Inputs/static-accessed-through-instance
1+
// RUN: %check_clang_tidy %s readability-static-accessed-through-instance %t -- --fix-notes -- -isystem %S/Inputs/static-accessed-through-instance
22
#include <__clang_cuda_builtin_vars.h>
33

44
enum OutEnum {
@@ -47,7 +47,8 @@ C &f(int, int, int, int);
4747
void g() {
4848
f(1, 2, 3, 4).x;
4949
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member accessed through instance [readability-static-accessed-through-instance]
50-
// CHECK-FIXES: {{^}} f(1, 2, 3, 4).x;{{$}}
50+
// CHECK-MESSAGES: :[[@LINE-2]]:3: note: member base expression may carry some side effects
51+
// CHECK-FIXES: {{^}} C::x;{{$}}
5152
}
5253

5354
int i(int &);
@@ -59,20 +60,23 @@ int k(bool);
5960
void f(C c) {
6061
j(i(h().x));
6162
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: static member
62-
// CHECK-FIXES: {{^}} j(i(h().x));{{$}}
63+
// CHECK-MESSAGES: :[[@LINE-2]]:7: note: member base expression may carry some side effects
64+
// CHECK-FIXES: {{^}} j(i(C::x));{{$}}
6365

6466
// The execution of h() depends on the return value of a().
6567
j(k(a() && h().x));
6668
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: static member
67-
// CHECK-FIXES: {{^}} j(k(a() && h().x));{{$}}
69+
// CHECK-MESSAGES: :[[@LINE-2]]:14: note: member base expression may carry some side effects
70+
// CHECK-FIXES: {{^}} j(k(a() && C::x));{{$}}
6871

6972
if ([c]() {
7073
c.ns();
7174
return c;
7275
}().x == 15)
7376
;
7477
// CHECK-MESSAGES: :[[@LINE-5]]:7: warning: static member
75-
// CHECK-FIXES: {{^}} if ([c]() {{{$}}
78+
// CHECK-MESSAGES: :[[@LINE-6]]:7: note: member base expression may carry some side effects
79+
// CHECK-FIXES: {{^}} if (C::x == 15){{$}}
7680
}
7781

7882
// Nested specifiers
@@ -261,8 +265,11 @@ struct Qptr {
261265
};
262266

263267
int func(Qptr qp) {
264-
qp->y = 10; // OK, the overloaded operator might have side-effects.
265-
qp->K = 10; //
268+
qp->y = 10;
269+
qp->K = 10;
270+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member accessed through instance [readability-static-accessed-through-instance]
271+
// CHECK-MESSAGES: :[[@LINE-2]]:3: note: member base expression may carry some side effects
272+
// CHECK-FIXES: {{^}} Q::K = 10;
266273
}
267274

268275
namespace {
@@ -380,3 +387,20 @@ namespace PR51861 {
380387
// CHECK-FIXES: {{^}} PR51861::Foo::getBar();{{$}}
381388
}
382389
}
390+
391+
namespace PR75163 {
392+
struct Static {
393+
static void call();
394+
};
395+
396+
struct Ptr {
397+
Static* operator->();
398+
};
399+
400+
void test(Ptr& ptr) {
401+
ptr->call();
402+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: static member accessed through instance [readability-static-accessed-through-instance]
403+
// CHECK-MESSAGES: :[[@LINE-2]]:5: note: member base expression may carry some side effects
404+
// CHECK-FIXES: {{^}} PR75163::Static::call();{{$}}
405+
}
406+
}

0 commit comments

Comments
 (0)