aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData
diff options
context:
space:
mode:
authorMingming Liu <mingmingl@google.com>2024-02-13 10:49:35 -0800
committerGitHub <noreply@github.com>2024-02-13 10:49:35 -0800
commit2422e969bf0a05b9b5cb4a6233a5f8dd335c2de5 (patch)
treec482f762668840968732c013fd1b65f3f316837a /llvm/lib/ProfileData
parentc830c1205dc164b645edb9c40cccbe768d5b337c (diff)
downloadllvm-2422e969bf0a05b9b5cb4a6233a5f8dd335c2de5.zip
llvm-2422e969bf0a05b9b5cb4a6233a5f8dd335c2de5.tar.gz
llvm-2422e969bf0a05b9b5cb4a6233a5f8dd335c2de5.tar.bz2
[NFC][InstrProf]Factor out getCanonicalName to compute the canonical name given a pgo name. (#81547)
- Also update the `InstrProf::addFuncWithName` to call the newly added `getCanonicalName`.
Diffstat (limited to 'llvm/lib/ProfileData')
-rw-r--r--llvm/lib/ProfileData/InstrProf.cpp49
1 files changed, 30 insertions, 19 deletions
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index d26004e..2eeeff9 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -517,35 +517,46 @@ Error InstrProfSymtab::create(StringRef NameStrings) {
std::bind(&InstrProfSymtab::addFuncName, this, std::placeholders::_1));
}
-Error InstrProfSymtab::addFuncWithName(Function &F, StringRef PGOFuncName) {
- if (Error E = addFuncName(PGOFuncName))
- return E;
- MD5FuncMap.emplace_back(Function::getGUID(PGOFuncName), &F);
+StringRef InstrProfSymtab::getCanonicalName(StringRef PGOName) {
// In ThinLTO, local function may have been promoted to global and have
// suffix ".llvm." added to the function name. We need to add the
// stripped function name to the symbol table so that we can find a match
// from profile.
//
- // We may have other suffixes similar as ".llvm." which are needed to
- // be stripped before the matching, but ".__uniq." suffix which is used
- // to differentiate internal linkage functions in different modules
- // should be kept. Now this is the only suffix with the pattern ".xxx"
- // which is kept before matching.
+ // ".__uniq." suffix is used to differentiate internal linkage functions in
+ // different modules and should be kept. This is the only suffix with the
+ // pattern ".xxx" which is kept before matching, other suffixes similar as
+ // ".llvm." will be stripped.
const std::string UniqSuffix = ".__uniq.";
- auto pos = PGOFuncName.find(UniqSuffix);
- // Search '.' after ".__uniq." if ".__uniq." exists, otherwise
- // search '.' from the beginning.
- if (pos != std::string::npos)
+ size_t pos = PGOName.find(UniqSuffix);
+ if (pos != StringRef::npos)
pos += UniqSuffix.length();
else
pos = 0;
- pos = PGOFuncName.find('.', pos);
- if (pos != std::string::npos && pos != 0) {
- StringRef OtherFuncName = PGOFuncName.substr(0, pos);
- if (Error E = addFuncName(OtherFuncName))
+
+ // Search '.' after ".__uniq." if ".__uniq." exists, otherwise search '.' from
+ // the beginning.
+ pos = PGOName.find('.', pos);
+ if (pos != StringRef::npos && pos != 0)
+ return PGOName.substr(0, pos);
+
+ return PGOName;
+}
+
+Error InstrProfSymtab::addFuncWithName(Function &F, StringRef PGOFuncName) {
+ auto mapName = [&](StringRef Name) -> Error {
+ if (Error E = addFuncName(Name))
return E;
- MD5FuncMap.emplace_back(Function::getGUID(OtherFuncName), &F);
- }
+ MD5FuncMap.emplace_back(Function::getGUID(Name), &F);
+ return Error::success();
+ };
+ if (Error E = mapName(PGOFuncName))
+ return E;
+
+ StringRef CanonicalFuncName = getCanonicalName(PGOFuncName);
+ if (CanonicalFuncName != PGOFuncName)
+ return mapName(CanonicalFuncName);
+
return Error::success();
}