Skip to content

Commit e9954ec

Browse files
committed
[BOLT] Detect .warm split functions as cold fragments (llvm#93759)
CDSplit splits functions up to three ways: main fragment with no suffix, and fragments with .cold and .warm suffixes. Add .warm suffix to the regex used to recognize split fragments. Test Plan: updated register-fragments-bolt-symbols.s
1 parent f38d84c commit e9954ec

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/Object/ELFObjectFile.h"
2222
#include "llvm/Object/ObjectFile.h"
2323
#include "llvm/Support/Error.h"
24+
#include "llvm/Support/Regex.h"
2425
#include <map>
2526
#include <set>
2627
#include <unordered_map>
@@ -596,6 +597,9 @@ class RewriteInstance {
596597

597598
NameResolver NR;
598599

600+
// Regex object matching split function names.
601+
const Regex FunctionFragmentTemplate{"(.*)\\.(cold|warm)(\\.[0-9]+)?"};
602+
599603
friend class RewriteInstanceDiff;
600604
};
601605

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
#include "llvm/Support/Error.h"
5656
#include "llvm/Support/FileSystem.h"
5757
#include "llvm/Support/ManagedStatic.h"
58-
#include "llvm/Support/Regex.h"
5958
#include "llvm/Support/Timer.h"
6059
#include "llvm/Support/ToolOutputFile.h"
6160
#include "llvm/Support/raw_ostream.h"
@@ -945,9 +944,6 @@ void RewriteInstance::discoverFileObjects() {
945944
BinaryFunction *PreviousFunction = nullptr;
946945
unsigned AnonymousId = 0;
947946

948-
// Regex object for matching cold fragments.
949-
const Regex ColdFragment(".*\\.cold(\\.[0-9]+)?");
950-
951947
const auto SortedSymbolsEnd =
952948
LastSymbol == SortedSymbols.end() ? LastSymbol : std::next(LastSymbol);
953949
for (auto Iter = SortedSymbols.begin(); Iter != SortedSymbolsEnd; ++Iter) {
@@ -1229,7 +1225,7 @@ void RewriteInstance::discoverFileObjects() {
12291225
}
12301226

12311227
// Check if it's a cold function fragment.
1232-
if (ColdFragment.match(SymName)) {
1228+
if (FunctionFragmentTemplate.match(SymName)) {
12331229
static bool PrintedWarning = false;
12341230
if (!PrintedWarning) {
12351231
PrintedWarning = true;
@@ -1460,10 +1456,10 @@ void RewriteInstance::registerFragments() {
14601456
for (StringRef Name : Function.getNames()) {
14611457
StringRef BaseName = NR.restore(Name);
14621458
const bool IsGlobal = BaseName == Name;
1463-
const size_t ColdSuffixPos = BaseName.find(".cold");
1464-
if (ColdSuffixPos == StringRef::npos)
1459+
SmallVector<StringRef> Matches;
1460+
if (!FunctionFragmentTemplate.match(BaseName, &Matches))
14651461
continue;
1466-
StringRef ParentName = BaseName.substr(0, ColdSuffixPos);
1462+
StringRef ParentName = Matches[1];
14671463
const BinaryData *BD = BC->getBinaryDataByName(ParentName);
14681464
const uint64_t NumPossibleLocalParents =
14691465
NR.getUniquifiedNameCount(ParentName);

bolt/test/X86/register-fragments-bolt-symbols.s

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@
33
# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %S/cdsplit-symbol-names.s -o %t.main.o
44
# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.chain.o
55
# RUN: link_fdata %S/cdsplit-symbol-names.s %t.main.o %t.fdata
6-
# RUN: sed -i 's|chain|chain/2|g' %t.fdata
76
# RUN: llvm-strip --strip-unneeded %t.main.o
7+
8+
## Check warm fragment name matching (produced by cdsplit)
9+
# RUN: %clang %cflags %t.main.o -o %t.warm.exe -Wl,-q
10+
# RUN: llvm-bolt %t.warm.exe -o %t.warm.bolt --split-functions --split-strategy=cdsplit \
11+
# RUN: --call-scale=2 --data=%t.fdata --reorder-blocks=ext-tsp --enable-bat
12+
# RUN: link_fdata %s %t.warm.bolt %t.preagg.warm PREAGGWARM
13+
# PREAGGWARM: B X:0 #chain.warm# 1 0
14+
# RUN: perf2bolt %t.warm.bolt -p %t.preagg.warm --pa -o %t.warm.fdata -w %t.warm.yaml \
15+
# RUN: -v=1 | FileCheck %s --check-prefix=CHECK-BOLT-WARM
16+
17+
# CHECK-BOLT-WARM: marking chain.warm/1(*2) as a fragment of chain
18+
19+
# RUN: sed -i 's|chain|chain/2|g' %t.fdata
820
# RUN: llvm-objcopy --localize-symbol=chain %t.main.o
921
# RUN: %clang %cflags %t.chain.o %t.main.o -o %t.exe -Wl,-q
1022
# RUN: llvm-bolt %t.exe -o %t.bolt --split-functions --split-strategy=randomN \

0 commit comments

Comments
 (0)