Skip to content

Commit 241c47c

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-remove-region-before-cg
2 parents c274eea + 4b89339 commit 241c47c

File tree

175 files changed

+5191
-2394
lines changed

Some content is hidden

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

175 files changed

+5191
-2394
lines changed

bolt/include/bolt/Profile/DataReader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ struct FuncSampleData {
246246
/// Get the number of samples recorded in [Start, End)
247247
uint64_t getSamples(uint64_t Start, uint64_t End) const;
248248

249+
/// Returns the total number of samples recorded in this function.
250+
uint64_t getSamples() const;
251+
249252
/// Aggregation helper
250253
DenseMap<uint64_t, size_t> Index;
251254

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -565,15 +565,14 @@ void DataAggregator::processProfile(BinaryContext &BC) {
565565
processMemEvents();
566566

567567
// Mark all functions with registered events as having a valid profile.
568-
const auto Flags = opts::BasicAggregation ? BinaryFunction::PF_SAMPLE
569-
: BinaryFunction::PF_LBR;
570568
for (auto &BFI : BC.getBinaryFunctions()) {
571569
BinaryFunction &BF = BFI.second;
572-
FuncBranchData *FBD = getBranchData(BF);
573-
if (FBD || getFuncSampleData(BF.getNames())) {
574-
BF.markProfiled(Flags);
575-
if (FBD)
576-
BF.RawBranchCount = FBD->getNumExecutedBranches();
570+
if (FuncBranchData *FBD = getBranchData(BF)) {
571+
BF.markProfiled(BinaryFunction::PF_LBR);
572+
BF.RawBranchCount = FBD->getNumExecutedBranches();
573+
} else if (FuncSampleData *FSD = getFuncSampleData(BF.getNames())) {
574+
BF.markProfiled(BinaryFunction::PF_SAMPLE);
575+
BF.RawBranchCount = FSD->getSamples();
577576
}
578577
}
579578

@@ -630,10 +629,18 @@ StringRef DataAggregator::getLocationName(const BinaryFunction &Func,
630629

631630
bool DataAggregator::doSample(BinaryFunction &OrigFunc, uint64_t Address,
632631
uint64_t Count) {
632+
// To record executed bytes, use basic block size as is regardless of BAT.
633+
uint64_t BlockSize = 0;
634+
if (BinaryBasicBlock *BB = OrigFunc.getBasicBlockContainingOffset(
635+
Address - OrigFunc.getAddress()))
636+
BlockSize = BB->getOriginalSize();
637+
633638
BinaryFunction *ParentFunc = getBATParentFunction(OrigFunc);
634639
BinaryFunction &Func = ParentFunc ? *ParentFunc : OrigFunc;
635-
if (ParentFunc || (BAT && !BAT->isBATFunction(OrigFunc.getAddress())))
640+
if (ParentFunc || (BAT && !BAT->isBATFunction(Func.getAddress())))
636641
NumColdSamples += Count;
642+
// Attach executed bytes to parent function in case of cold fragment.
643+
Func.SampleCountInBytes += Count * BlockSize;
637644

638645
auto I = NamesToSamples.find(Func.getOneName());
639646
if (I == NamesToSamples.end()) {

bolt/lib/Profile/DataReader.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ uint64_t FuncSampleData::getSamples(uint64_t Start, uint64_t End) const {
128128
return Result;
129129
}
130130

131+
uint64_t FuncSampleData::getSamples() const {
132+
uint64_t Result = 0;
133+
for (const SampleInfo &I : Data)
134+
Result += I.Hits;
135+
return Result;
136+
}
137+
131138
void FuncSampleData::bumpCount(uint64_t Offset, uint64_t Count) {
132139
auto Iter = Index.find(Offset);
133140
if (Iter == Index.end()) {
@@ -1028,9 +1035,8 @@ ErrorOr<SampleInfo> DataReader::parseSampleInfo() {
10281035
}
10291036

10301037
ErrorOr<bool> DataReader::maybeParseNoLBRFlag() {
1031-
if (ParsingBuf.size() < 6 || ParsingBuf.substr(0, 6) != "no_lbr")
1038+
if (!ParsingBuf.consume_front("no_lbr"))
10321039
return false;
1033-
ParsingBuf = ParsingBuf.drop_front(6);
10341040
Col += 6;
10351041

10361042
if (ParsingBuf.size() > 0 && ParsingBuf[0] == ' ')
@@ -1051,9 +1057,8 @@ ErrorOr<bool> DataReader::maybeParseNoLBRFlag() {
10511057
}
10521058

10531059
ErrorOr<bool> DataReader::maybeParseBATFlag() {
1054-
if (ParsingBuf.size() < 16 || ParsingBuf.substr(0, 16) != "boltedcollection")
1060+
if (!ParsingBuf.consume_front("boltedcollection"))
10551061
return false;
1056-
ParsingBuf = ParsingBuf.drop_front(16);
10571062
Col += 16;
10581063

10591064
if (!checkAndConsumeNewLine()) {

bolt/lib/Rewrite/BuildIDRewriter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ Error BuildIDRewriter::sectionInitializer() {
7878
"out of bounds while reading note section: %s",
7979
toString(Cursor.takeError()).c_str());
8080

81-
if (Type == ELF::NT_GNU_BUILD_ID && Name.substr(0, 3) == "GNU" &&
82-
DescSz) {
81+
if (Type == ELF::NT_GNU_BUILD_ID && Name.starts_with("GNU") && DescSz) {
8382
BuildIDSection = NoteSection;
8483
BuildID = Desc;
8584
BC.setFileBuildID(getPrintableBuildID(Desc));

bolt/test/perf2bolt/perf_test.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ RUN: perf2bolt %t -p=%t2 -o %t3 -nl -ignore-build-id 2>&1 | FileCheck %s
88

99
CHECK-NOT: PERF2BOLT-ERROR
1010
CHECK-NOT: !! WARNING !! This high mismatch ratio indicates the input binary is probably not the same binary used during profiling collection.
11+
CHECK: BOLT-INFO: Functions with density >= {{.*}} account for 99.00% total sample counts.
1112

1213
RUN: %clang %S/Inputs/perf_test.c -no-pie -fuse-ld=lld -o %t4
1314
RUN: perf record -Fmax -e cycles:u -o %t5 -- %t4

clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ namespace {
1919

2020
StringRef removeFirstSuffix(StringRef Str, ArrayRef<const char *> Suffixes) {
2121
for (StringRef Suffix : Suffixes) {
22-
if (Str.ends_with(Suffix)) {
23-
return Str.substr(0, Str.size() - Suffix.size());
24-
}
22+
if (Str.consume_back(Suffix))
23+
return Str;
2524
}
2625
return Str;
2726
}

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,7 @@ enum DriverMode : unsigned char {
404404
DriverMode getDriverMode(const std::vector<std::string> &Args) {
405405
DriverMode Mode = DM_GCC;
406406
llvm::StringRef Argv0 = Args.front();
407-
if (Argv0.ends_with_insensitive(".exe"))
408-
Argv0 = Argv0.drop_back(strlen(".exe"));
407+
Argv0.consume_back_insensitive(".exe");
409408
if (Argv0.ends_with_insensitive("cl"))
410409
Mode = DM_CL;
411410
for (const llvm::StringRef Arg : Args) {

clang-tools-extra/docs/clang-tidy/checks/bugprone/crtp-constructor-accessibility.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ can be constructed outside itself and the derived class.
99
The CRTP is an idiom, in which a class derives from a template class, where
1010
itself is the template argument. It should be ensured that if a class is
1111
intended to be a base class in this idiom, it can only be instantiated if
12-
the derived class is it's template argument.
12+
the derived class is its template argument.
1313

1414
Example:
1515

clang-tools-extra/modularize/Modularize.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,8 @@ struct Location {
406406
}
407407

408408
friend bool operator<(const Location &X, const Location &Y) {
409-
if (X.File != Y.File)
410-
return X.File < Y.File;
411-
if (X.Line != Y.Line)
412-
return X.Line < Y.Line;
413-
return X.Column < Y.Column;
409+
return std::tie(X.File, X.Line, X.Column) <
410+
std::tie(Y.File, Y.Line, Y.Column);
414411
}
415412
friend bool operator>(const Location &X, const Location &Y) { return Y < X; }
416413
friend bool operator<=(const Location &X, const Location &Y) {

clang-tools-extra/modularize/PreprocessorTracker.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -494,19 +494,8 @@ class PPItemKey {
494494
return Column == Other.Column;
495495
}
496496
bool operator<(const PPItemKey &Other) const {
497-
if (Name < Other.Name)
498-
return true;
499-
else if (Name > Other.Name)
500-
return false;
501-
if (File < Other.File)
502-
return true;
503-
else if (File > Other.File)
504-
return false;
505-
if (Line < Other.Line)
506-
return true;
507-
else if (Line > Other.Line)
508-
return false;
509-
return Column < Other.Column;
497+
return std::tie(Name, File, Line, Column) <
498+
std::tie(Other.Name, Other.File, Other.Line, Other.Column);
510499
}
511500
StringHandle Name;
512501
HeaderHandle File;

0 commit comments

Comments
 (0)