[llvm] [BOLT] Use the last local parent name in fragment matching (PR #88437)
Amir Ayupov via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 11 13:54:22 PDT 2024
https://github.com/aaupov created https://github.com/llvm/llvm-project/pull/88437
Test Plan: TBD
>From a4bc4d479c4c6959873eb9548ece8a37b3c967c5 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Thu, 11 Apr 2024 13:54:09 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
---
bolt/include/bolt/Utils/NameResolver.h | 7 +++++++
bolt/lib/Rewrite/RewriteInstance.cpp | 5 ++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/bolt/include/bolt/Utils/NameResolver.h b/bolt/include/bolt/Utils/NameResolver.h
index 2e3ac20a532d76..1cebbe3ea990c5 100644
--- a/bolt/include/bolt/Utils/NameResolver.h
+++ b/bolt/include/bolt/Utils/NameResolver.h
@@ -28,6 +28,13 @@ class NameResolver {
static constexpr char Sep = '/';
public:
+ /// Return the number of registered duplicate names for a given original name.
+ uint64_t getNumDuplicates(StringRef Name) const {
+ if (Counters.contains(Name))
+ return Counters.at(Name);
+ return 0;
+ }
+
/// Return unique version of the \p Name in the form "Name<Sep><Number>".
std::string uniquify(StringRef Name) {
const uint64_t ID = ++Counters[Name];
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index eea66454b289c2..cc766d845345ac 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1430,10 +1430,13 @@ void RewriteInstance::registerFragments() {
continue;
// For cold function with local (foo.cold/1) symbol, prefer a parent with
// local symbol as well (foo/1) over global symbol (foo).
+ // As a heuristic, use the last registered local name since BOLT processes
+ // the last instance.
std::string ParentName = BaseName.substr(0, ColdSuffixPos).str();
const BinaryData *BD = BC->getBinaryDataByName(ParentName);
if (Suffix != "") {
- ParentName.append(Twine("/", Suffix).str());
+ ParentName.append(
+ formatv("/{0}", NR.getNumDuplicates(ParentName)).str());
const BinaryData *BDLocal = BC->getBinaryDataByName(ParentName);
if (BDLocal || !BD)
BD = BDLocal;
More information about the llvm-commits
mailing list