[llvm] [NFC] In InstrProf, generalize helper functions to take 'GlobalObject'. They currently take 'Functions' as function parameters or have 'Func' in the name. (PR #70287)
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 26 14:01:22 PDT 2023
================
@@ -289,64 +289,74 @@ static StringRef getStrippedSourceFileName(const Function &F) {
// mangled, they cannot be passed to Mach-O linkers via -order_file. We still
// need to compute this name to lookup functions from profiles built by older
// compilers.
-static std::string getIRPGOFuncName(const Function &F,
- GlobalValue::LinkageTypes Linkage,
- StringRef FileName) {
+static std::string
+getIRPGONameForGlobalObject(const GlobalObject &GO,
+ GlobalValue::LinkageTypes Linkage,
+ StringRef FileName) {
SmallString<64> Name;
if (llvm::GlobalValue::isLocalLinkage(Linkage)) {
Name.append(FileName.empty() ? "<unknown>" : FileName);
Name.append(";");
}
- Mangler().getNameWithPrefix(Name, &F, /*CannotUsePrivateLabel=*/true);
+ Mangler().getNameWithPrefix(Name, &GO, /*CannotUsePrivateLabel=*/true);
return Name.str().str();
}
-static std::optional<std::string> lookupPGOFuncName(const Function &F) {
- if (MDNode *MD = getPGOFuncNameMetadata(F)) {
+static std::optional<std::string> lookupPGONameFromMetadata(MDNode *MD) {
+ if (MD != nullptr) {
StringRef S = cast<MDString>(MD->getOperand(0))->getString();
return S.str();
}
return {};
}
-// See getPGOFuncName()
-std::string getIRPGOFuncName(const Function &F, bool InLTO) {
+// 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(F);
- return getIRPGOFuncName(F, F.getLinkage(), FileName);
+ auto FileName = getStrippedSourceFileName(GO);
+ return getIRPGONameForGlobalObject(GO, GO.getLinkage(), FileName);
}
// In LTO mode (when InLTO is true), first check if there is a meta data.
- if (auto IRPGOFuncName = lookupPGOFuncName(F))
+ if (auto IRPGOFuncName = lookupPGONameFromMetadata(PGONameMetadata))
return *IRPGOFuncName;
// If there is no meta data, the function must be a global before the value
// profile annotation pass. Its current linkage may be internal if it is
// internalized in LTO mode.
- return getIRPGOFuncName(F, GlobalValue::ExternalLinkage, "");
+ return getIRPGONameForGlobalObject(GO, GlobalValue::ExternalLinkage, "");
}
-// Return the PGOFuncName. 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.
+// Returns the IRPGO function name and does special handling when called
+// in LTO optimization. See the comments of `getIRPGOObjectName` for details.
+std::string getIRPGOFuncName(const Function &F, bool InLTO) {
+ return getIRPGOObjectName(F, InLTO, getPGOFuncNameMetadata(F));
+}
+
+// This is similar to `getIRPGOFuncName` except that this function calls
+// 'getIRPGOFuncName' to get a name and `getIRPGOFuncName` calls 'getIRPGOName'.
----------------
teresajohnson wrote:
I think this should say "this function calls 'getPGOFuncName' to get a name and `getIRPGOFuncName` calls 'getIRPGONameForGlobalObject'? (note changes to both mentioned callees)
https://github.com/llvm/llvm-project/pull/70287
More information about the llvm-commits
mailing list