diff --git a/bolt/include/bolt/Profile/ProfileReaderBase.h b/bolt/include/bolt/Profile/ProfileReaderBase.h --- a/bolt/include/bolt/Profile/ProfileReaderBase.h +++ b/bolt/include/bolt/Profile/ProfileReaderBase.h @@ -23,32 +23,6 @@ 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 --- a/bolt/include/bolt/Utils/Utils.h +++ b/bolt/include/bolt/Utils/Utils.h @@ -41,6 +41,32 @@ /// 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 --- a/bolt/lib/Profile/DataReader.cpp +++ b/bolt/lib/Profile/DataReader.cpp @@ -41,15 +41,6 @@ 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 --- 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 --- a/bolt/lib/Utils/Utils.cpp +++ b/bolt/lib/Utils/Utils.cpp @@ -66,6 +66,15 @@ 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)