[llvm-branch-commits] [BOLT] Detect .warm split functions as cold fragments (PR #93759)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed May 29 20:01:30 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-bolt
Author: Amir Ayupov (aaupov)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/93759.diff
3 Files Affected:
- (modified) bolt/include/bolt/Rewrite/RewriteInstance.h (+4)
- (modified) bolt/lib/Rewrite/RewriteInstance.cpp (+3-7)
- (modified) bolt/test/X86/register-fragments-bolt-symbols.s (+13-1)
``````````diff
diff --git a/bolt/include/bolt/Rewrite/RewriteInstance.h b/bolt/include/bolt/Rewrite/RewriteInstance.h
index 64113bd026012..d8d62badcc377 100644
--- a/bolt/include/bolt/Rewrite/RewriteInstance.h
+++ b/bolt/include/bolt/Rewrite/RewriteInstance.h
@@ -21,6 +21,7 @@
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/Regex.h"
#include <map>
#include <set>
#include <unordered_map>
@@ -596,6 +597,9 @@ class RewriteInstance {
NameResolver NR;
+ // Regex object matching split function names.
+ const Regex ColdFragment{"(.*)\\.(cold|warm)(\\.[0-9]+)?"};
+
friend class RewriteInstanceDiff;
};
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 4b4913dd7a16c..fb920ebbeafc4 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -55,7 +55,6 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/Regex.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/raw_ostream.h"
@@ -945,9 +944,6 @@ void RewriteInstance::discoverFileObjects() {
BinaryFunction *PreviousFunction = nullptr;
unsigned AnonymousId = 0;
- // Regex object for matching cold fragments.
- const Regex ColdFragment(".*\\.cold(\\.[0-9]+)?");
-
const auto SortedSymbolsEnd =
LastSymbol == SortedSymbols.end() ? LastSymbol : std::next(LastSymbol);
for (auto Iter = SortedSymbols.begin(); Iter != SortedSymbolsEnd; ++Iter) {
@@ -1460,10 +1456,10 @@ void RewriteInstance::registerFragments() {
for (StringRef Name : Function.getNames()) {
StringRef BaseName = NR.restore(Name);
const bool IsGlobal = BaseName == Name;
- const size_t ColdSuffixPos = BaseName.find(".cold");
- if (ColdSuffixPos == StringRef::npos)
+ SmallVector<StringRef> Matches;
+ if (!ColdFragment.match(BaseName, &Matches))
continue;
- StringRef ParentName = BaseName.substr(0, ColdSuffixPos);
+ StringRef ParentName = Matches[1];
const BinaryData *BD = BC->getBinaryDataByName(ParentName);
const uint64_t NumPossibleLocalParents =
NR.getUniquifiedNameCount(ParentName);
diff --git a/bolt/test/X86/register-fragments-bolt-symbols.s b/bolt/test/X86/register-fragments-bolt-symbols.s
index 90c402b2234d7..d4f39b7acf134 100644
--- a/bolt/test/X86/register-fragments-bolt-symbols.s
+++ b/bolt/test/X86/register-fragments-bolt-symbols.s
@@ -3,8 +3,20 @@
# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %S/cdsplit-symbol-names.s -o %t.main.o
# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.chain.o
# RUN: link_fdata %S/cdsplit-symbol-names.s %t.main.o %t.fdata
-# RUN: sed -i 's|chain|chain/2|g' %t.fdata
# RUN: llvm-strip --strip-unneeded %t.main.o
+
+## Check warm fragment name matching (produced by cdsplit)
+# RUN: %clang %cflags %t.main.o -o %t.warm.exe -Wl,-q
+# RUN: llvm-bolt %t.warm.exe -o %t.warm.bolt --split-functions --split-strategy=cdsplit \
+# RUN: --call-scale=2 --data=%t.fdata --reorder-blocks=ext-tsp --enable-bat
+# RUN: link_fdata %s %t.warm.bolt %t.preagg.warm PREAGGWARM
+# PREAGGWARM: B X:0 #chain.warm# 1 0
+# RUN: perf2bolt %t.warm.bolt -p %t.preagg.warm --pa -o %t.warm.fdata -w %t.warm.yaml \
+# RUN: -v=1 | FileCheck %s --check-prefix=CHECK-BOLT-WARM
+
+# CHECK-BOLT-WARM: marking chain.warm/1(*2) as a fragment of chain
+
+# RUN: sed -i 's|chain|chain/2|g' %t.fdata
# RUN: llvm-objcopy --localize-symbol=chain %t.main.o
# RUN: %clang %cflags %t.chain.o %t.main.o -o %t.exe -Wl,-q
# RUN: llvm-bolt %t.exe -o %t.bolt --split-functions --split-strategy=randomN \
``````````
</details>
https://github.com/llvm/llvm-project/pull/93759
More information about the llvm-branch-commits
mailing list