[llvm] [BOLT][NFCI] Strip suffix in getLTOCommonName (PR #106243)

Amir Ayupov via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 27 09:28:39 PDT 2024


https://github.com/aaupov created https://github.com/llvm/llvm-project/pull/106243

Also provide a mechanism to override the list of suffixes to consider.


>From 1f2e9a33d80616e7acdc68f1956a37f82abecd9e Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Tue, 27 Aug 2024 09:28:19 -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/Utils.h | 6 +++++-
 bolt/lib/Utils/Utils.cpp        | 7 ++++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/bolt/include/bolt/Utils/Utils.h b/bolt/include/bolt/Utils/Utils.h
index 3886c5f8757c08..63de3c5ee8f123 100644
--- a/bolt/include/bolt/Utils/Utils.h
+++ b/bolt/include/bolt/Utils/Utils.h
@@ -64,8 +64,12 @@ std::string getUnescapedName(const StringRef &Name);
 /// of functions. Later, out of all matching profiles we pick the one with the
 /// best match.
 ///
+static SmallVector<StringRef, 4> LTOSuffixes({".__uniq.", ".lto_priv.",
+                                              ".constprop.", ".llvm."});
 /// Return a common part of LTO name for a given \p Name.
-std::optional<StringRef> getLTOCommonName(const StringRef Name);
+std::optional<StringRef>
+getLTOCommonName(const StringRef Name,
+                 ArrayRef<StringRef> Suffixes = LTOSuffixes);
 
 // Determines which register a given DWARF expression is being assigned to.
 // If the expression is defining the CFA, return std::nullopt.
diff --git a/bolt/lib/Utils/Utils.cpp b/bolt/lib/Utils/Utils.cpp
index 718e97535fd22a..a4b6a6a317e2cb 100644
--- a/bolt/lib/Utils/Utils.cpp
+++ b/bolt/lib/Utils/Utils.cpp
@@ -66,11 +66,12 @@ std::string getUnescapedName(const StringRef &Name) {
   return Output;
 }
 
-std::optional<StringRef> getLTOCommonName(const StringRef Name) {
-  for (StringRef Suffix : {".__uniq.", ".lto_priv.", ".constprop.", ".llvm."}) {
+std::optional<StringRef> getLTOCommonName(const StringRef Name,
+                                          ArrayRef<StringRef> Suffixes) {
+  for (StringRef Suffix : Suffixes) {
     size_t LTOSuffixPos = Name.find(Suffix);
     if (LTOSuffixPos != StringRef::npos)
-      return Name.substr(0, LTOSuffixPos + Suffix.size());
+      return Name.substr(0, LTOSuffixPos);
   }
   return std::nullopt;
 }



More information about the llvm-commits mailing list