From dbb7316e029b154d8fff0c8cf31212f07d7b7c8d Mon Sep 17 00:00:00 2001 From: Amir Ayupov Date: Fri, 20 Jan 2023 19:27:38 -0800 Subject: [PATCH] [BOLT][NFC] Move getLTOCommonName to Utils Reuse getLTOCommonName in components other than Profile (to be used in Core) Reviewed By: #bolt, maksfb Differential Revision: https://reviews.llvm.org/D142259 --- bolt/include/bolt/Profile/ProfileReaderBase.h | 26 ------------------- bolt/include/bolt/Utils/Utils.h | 26 +++++++++++++++++++ bolt/lib/Profile/DataReader.cpp | 9 ------- bolt/lib/Rewrite/BoltDiff.cpp | 1 + bolt/lib/Utils/Utils.cpp | 9 +++++++ 5 files changed, 36 insertions(+), 35 deletions(-) diff --git a/bolt/include/bolt/Profile/ProfileReaderBase.h b/bolt/include/bolt/Profile/ProfileReaderBase.h index 7061d8ee219c..511718f3c0ec 100644 --- a/bolt/include/bolt/Profile/ProfileReaderBase.h +++ b/bolt/include/bolt/Profile/ProfileReaderBase.h @@ -23,32 +23,6 @@ class BinaryContext; class BinaryFunction; class BoltAddressTranslation; -/// LTO-generated function names take a form: -/// -/// .lto_priv./... -/// or -/// .constprop./... -/// -/// they can also be: -/// -/// .lto_priv..lto_priv./... -/// -/// The is a global counter used for the whole program. As a -/// result, a tiny change in a program may affect the naming of many LTO -/// functions. For us this means that if we do a precise name matching, then -/// a large set of functions could be left without a profile. -/// -/// To solve this issue, we try to match a function to any profile: -/// -/// .(lto_priv|consprop).* -/// -/// The name before an asterisk above represents a common LTO name for a family -/// of functions. Later, out of all matching profiles we pick the one with the -/// best match. -/// -/// Return a common part of LTO name for a given \p Name. -std::optional getLTOCommonName(const StringRef Name); - class ProfileReaderBase { protected: /// Name of the file with profile. diff --git a/bolt/include/bolt/Utils/Utils.h b/bolt/include/bolt/Utils/Utils.h index 77ab11bab662..3886c5f8757c 100644 --- a/bolt/include/bolt/Utils/Utils.h +++ b/bolt/include/bolt/Utils/Utils.h @@ -41,6 +41,32 @@ std::string getEscapedName(const StringRef &Name); /// Return the unescaped name std::string getUnescapedName(const StringRef &Name); +/// LTO-generated function names take a form: +/// +/// .lto_priv./... +/// or +/// .constprop./... +/// +/// they can also be: +/// +/// .lto_priv..lto_priv./... +/// +/// The is a global counter used for the whole program. As a +/// result, a tiny change in a program may affect the naming of many LTO +/// functions. For us this means that if we do a precise name matching, then +/// a large set of functions could be left without a profile. +/// +/// To solve this issue, we try to match a function to any profile: +/// +/// .(lto_priv|consprop).* +/// +/// The name before an asterisk above represents a common LTO name for a family +/// of functions. Later, out of all matching profiles we pick the one with the +/// best match. +/// +/// Return a common part of LTO name for a given \p Name. +std::optional getLTOCommonName(const StringRef Name); + // Determines which register a given DWARF expression is being assigned to. // If the expression is defining the CFA, return std::nullopt. std::optional readDWARFExpressionTargetReg(StringRef ExprBytes); diff --git a/bolt/lib/Profile/DataReader.cpp b/bolt/lib/Profile/DataReader.cpp index b7f688827121..54e4c309f4a6 100644 --- a/bolt/lib/Profile/DataReader.cpp +++ b/bolt/lib/Profile/DataReader.cpp @@ -41,15 +41,6 @@ DumpData("dump-data", namespace llvm { namespace bolt { -std::optional getLTOCommonName(const StringRef Name) { - for (StringRef Suffix : {".__uniq.", ".lto_priv.", ".constprop.", ".llvm."}) { - size_t LTOSuffixPos = Name.find(Suffix); - if (LTOSuffixPos != StringRef::npos) - return Name.substr(0, LTOSuffixPos + Suffix.size()); - } - return std::nullopt; -} - namespace { /// Return true if the function name can change across compilations. diff --git a/bolt/lib/Rewrite/BoltDiff.cpp b/bolt/lib/Rewrite/BoltDiff.cpp index 9980ffe38320..25b2fad25b3e 100644 --- a/bolt/lib/Rewrite/BoltDiff.cpp +++ b/bolt/lib/Rewrite/BoltDiff.cpp @@ -14,6 +14,7 @@ #include "bolt/Passes/IdenticalCodeFolding.h" #include "bolt/Profile/ProfileReaderBase.h" #include "bolt/Rewrite/RewriteInstance.h" +#include "bolt/Utils/Utils.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/CommandLine.h" diff --git a/bolt/lib/Utils/Utils.cpp b/bolt/lib/Utils/Utils.cpp index ae12f17b0778..718e97535fd2 100644 --- a/bolt/lib/Utils/Utils.cpp +++ b/bolt/lib/Utils/Utils.cpp @@ -66,6 +66,15 @@ std::string getUnescapedName(const StringRef &Name) { return Output; } +std::optional getLTOCommonName(const StringRef Name) { + for (StringRef Suffix : {".__uniq.", ".lto_priv.", ".constprop.", ".llvm."}) { + size_t LTOSuffixPos = Name.find(Suffix); + if (LTOSuffixPos != StringRef::npos) + return Name.substr(0, LTOSuffixPos + Suffix.size()); + } + return std::nullopt; +} + std::optional readDWARFExpressionTargetReg(StringRef ExprBytes) { uint8_t Opcode = ExprBytes[0]; if (Opcode == dwarf::DW_CFA_def_cfa_expression)