https://github.com/minglotus-6 updated https://github.com/llvm/llvm-project/pull/81051
>From a3cb7002be9d7efe9f7678911da9dd68b561b785 Mon Sep 17 00:00:00 2001 From: mingmingl <mingmi...@google.com> Date: Wed, 7 Feb 2024 22:18:50 -0800 Subject: [PATCH] fixup --- llvm/include/llvm/ProfileData/InstrProf.h | 11 +---- llvm/lib/ProfileData/InstrProf.cpp | 42 ++++++++++---------- llvm/tools/llvm-profdata/llvm-profdata.cpp | 2 +- llvm/unittests/ProfileData/InstrProfTest.cpp | 10 ++--- 4 files changed, 27 insertions(+), 38 deletions(-) diff --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h index d5d3c7f6b4b34..6e799cf8aa273 100644 --- a/llvm/include/llvm/ProfileData/InstrProf.h +++ b/llvm/include/llvm/ProfileData/InstrProf.h @@ -198,18 +198,9 @@ std::string getPGOFuncName(StringRef RawFuncName, /// called from LTO optimization passes. std::string getIRPGOFuncName(const Function &F, bool InLTO = false); -/// Returns the PGO object name. This function has some special handling -/// when called in LTO optimization: -/// - In LTO mode, returns the name in `PGONameMetadata` if exists, otherwise -/// returns the IRPGO name as if the GO has non-local linkage. -/// - In non-LTO mode, returns the IRPGO name as it is. -/// More rationale in the comment of function implementation. -std::string getIRPGOObjectName(const GlobalObject &GO, bool InLTO = false, - MDNode *PGONameMetadata = nullptr); - /// \return the filename and the function name parsed from the output of /// \c getIRPGOFuncName() -std::pair<StringRef, StringRef> getParsedIRPGOFuncName(StringRef IRPGOFuncName); +std::pair<StringRef, StringRef> getParsedIRPGOName(StringRef IRPGOName); /// Return the name of the global variable used to store a function /// name in PGO instrumentation. \c FuncName is the IRPGO function name diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp index 3b05faf0cc5d3..c280454fdeb1e 100644 --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -325,20 +325,21 @@ static std::optional<std::string> lookupPGONameFromMetadata(MDNode *MD) { return {}; } -std::string getIRPGOObjectName(const GlobalObject &GO, bool InLTO, - MDNode *PGONameMetadata) { - // The following only applies when calling in - // LTO passes (when \c InLTO is true): LTO's internalization privatizes many - // global linkage symbols. This happens after value profile annotation, but - // those internal linkage functions should not have a source prefix. - // Additionally, for ThinLTO mode, exported internal functions are promoted - // and renamed. We need to ensure that the original internal PGO name is - // used when computing the GUID that is compared against the profiled GUIDs. - // To differentiate compiler generated internal symbols from original ones, - // PGOFuncName meta data are created and attached to the original internal - // symbols in the value profile annotation step - // (PGOUseFunc::annotateIndirectCallSites). If a symbol does not have the meta - // data, its original linkage must be non-internal. +// Returns the PGO object name. This function has some special handling +// when called in LTO optimization. The following only applies when calling in +// LTO passes (when \c InLTO is true): LTO's internalization privatizes many +// global linkage symbols. This happens after value profile annotation, but +// those internal linkage functions should not have a source prefix. +// Additionally, for ThinLTO mode, exported internal functions are promoted +// and renamed. We need to ensure that the original internal PGO name is +// used when computing the GUID that is compared against the profiled GUIDs. +// To differentiate compiler generated internal symbols from original ones, +// PGOFuncName meta data are created and attached to the original internal +// symbols in the value profile annotation step +// (PGOUseFunc::annotateIndirectCallSites). If a symbol does not have the meta +// data, its original linkage must be non-internal. +static std::string getIRPGOObjectName(const GlobalObject &GO, bool InLTO, + MDNode *PGONameMetadata) { if (!InLTO) { auto FileName = getStrippedSourceFileName(GO); return getIRPGONameForGlobalObject(GO, GO.getLinkage(), FileName); @@ -390,13 +391,12 @@ std::string getPGOName(const GlobalVariable &V, bool InLTO) { return getIRPGOObjectName(V, InLTO, nullptr /* PGONameMetadata */); } -// See getIRPGOFuncName() for a discription of the format. -std::pair<StringRef, StringRef> -getParsedIRPGOFuncName(StringRef IRPGOFuncName) { - auto [FileName, FuncName] = IRPGOFuncName.split(';'); - if (FuncName.empty()) - return std::make_pair(StringRef(), IRPGOFuncName); - return std::make_pair(FileName, FuncName); +// See getIRPGOObjectName() for a discription of the format. +std::pair<StringRef, StringRef> getParsedIRPGOName(StringRef IRPGOName) { + auto [FileName, MangledName] = IRPGOName.split(kGlobalIdentifierDelimiter); + if (MangledName.empty()) + return std::make_pair(StringRef(), IRPGOName); + return std::make_pair(FileName, MangledName); } StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName) { diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp index 9fb56b8e2647e..804bc93e7dee8 100644 --- a/llvm/tools/llvm-profdata/llvm-profdata.cpp +++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -3257,7 +3257,7 @@ static int order_main(int argc, const char *argv[]) { "-order_file.\n"; for (auto &N : Nodes) { auto [Filename, ParsedFuncName] = - getParsedIRPGOFuncName(Reader->getSymtab().getFuncOrVarName(N.Id)); + getParsedIRPGOName(Reader->getSymtab().getFuncOrVarName(N.Id)); if (!Filename.empty()) OS << "# " << Filename << "\n"; OS << ParsedFuncName << "\n"; diff --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp index f0281bdf1525d..e858c5e2d1c62 100644 --- a/llvm/unittests/ProfileData/InstrProfTest.cpp +++ b/llvm/unittests/ProfileData/InstrProfTest.cpp @@ -562,8 +562,7 @@ TEST_F(InstrProfTest, test_irpgo_function_name) { auto IRPGOFuncName = getIRPGOFuncName(*F); EXPECT_EQ(IRPGOFuncName, ExpectedIRPGOFuncName); - auto [Filename, ParsedIRPGOFuncName] = - getParsedIRPGOFuncName(IRPGOFuncName); + auto [Filename, ParsedIRPGOFuncName] = getParsedIRPGOName(IRPGOFuncName); StringRef ExpectedParsedIRPGOFuncName = IRPGOFuncName; if (ExpectedParsedIRPGOFuncName.consume_front("MyModule.cpp;")) { EXPECT_EQ(Filename, "MyModule.cpp"); @@ -1655,8 +1654,7 @@ TEST(SymtabTest, instr_prof_symtab_module_test) { auto IRPGOFuncName = ProfSymtab.getFuncOrVarName(IndexedInstrProf::ComputeHash(IRPGOName)); EXPECT_EQ(StringRef(IRPGOName), IRPGOFuncName); - EXPECT_EQ(StringRef(Funcs[I]), - getParsedIRPGOFuncName(IRPGOFuncName).second); + EXPECT_EQ(StringRef(Funcs[I]), getParsedIRPGOName(IRPGOFuncName).second); // Ensure we can still read this old record name. std::string PGOName = getPGOFuncName(*F); auto PGOFuncName = @@ -1670,10 +1668,10 @@ TEST(SymtabTest, instr_prof_symtab_module_test) { GlobalVariable *GV = M->getGlobalVariable(VTables[I], /* AllowInternal=*/true); - std::string IRPGOName = getIRPGOObjectName(*GV); + std::string IRPGOName = getPGOName(*GV); EXPECT_EQ(IRPGOName, ProfSymtab.getFuncOrVarName( IndexedInstrProf::ComputeHash(IRPGOName))); - EXPECT_EQ(VTables[I], getParsedIRPGOFuncName(IRPGOName).second); + EXPECT_EQ(VTables[I], getParsedIRPGOName(IRPGOName).second); } } _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits