-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NFC] In InstrProf, generalize helper functions to take 'GlobalObject'. They currently take 'Functions' as function parameters or have 'Func' in the name. #70287
Conversation
…ings - Do the rename in a standalone patch since the method is used in non-llvm codebase. It's easier to rollback this NFC in case rename in that codebase takes longer.
@llvm/pr-subscribers-pgo Author: Mingming Liu (minglotus-6) Changes
Full diff: https://github.com/llvm/llvm-project/pull/70287.diff 3 Files Affected:
diff --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h
index f9096b46157200b..7832b4fbf35cc71 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -220,8 +220,8 @@ StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar);
StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName,
StringRef FileName = "<unknown>");
-/// Given a vector of strings (function PGO names) \c NameStrs, the
-/// method generates a combined string \c Result that is ready to be
+/// Given a vector of strings (names of global variables) \c NameStrs,
+/// the method generates a combined string \c Result that is ready to be
/// serialized. The \c Result string is comprised of three fields:
/// The first field is the length of the uncompressed strings, and the
/// the second field is the length of the zlib-compressed string.
@@ -229,8 +229,8 @@ StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName,
/// third field is the uncompressed strings; otherwise it is the
/// compressed string. When the string compression is off, the
/// second field will have value zero.
-Error collectPGOFuncNameStrings(ArrayRef<std::string> NameStrs,
- bool doCompression, std::string &Result);
+Error collectGlobalVariableNameStrings(ArrayRef<std::string> NameStrs,
+ bool doCompression, std::string &Result);
/// Produce \c Result string with the same format described above. The input
/// is vector of PGO function name variables that are referenced.
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index e82cb5c535f1f5a..963d4703395b35b 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -545,7 +545,7 @@ Error collectPGOFuncNameStrings(ArrayRef<GlobalVariable *> NameVars,
for (auto *NameVar : NameVars) {
NameStrs.push_back(std::string(getPGOFuncNameVarInitializer(NameVar)));
}
- return collectPGOFuncNameStrings(
+ return collectGlobalVariableNameStrings(
NameStrs, compression::zlib::isAvailable() && doCompression, Result);
}
diff --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp
index 76f88c058424d03..378795bd724b588 100644
--- a/llvm/unittests/ProfileData/InstrProfTest.cpp
+++ b/llvm/unittests/ProfileData/InstrProfTest.cpp
@@ -1368,7 +1368,7 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_compression_test) {
for (bool DoCompression : {false, true}) {
// Compressing:
std::string FuncNameStrings1;
- EXPECT_THAT_ERROR(collectPGOFuncNameStrings(
+ EXPECT_THAT_ERROR(collectGlobalVariableNameStrings(
FuncNames1,
(DoCompression && compression::zlib::isAvailable()),
FuncNameStrings1),
@@ -1376,7 +1376,7 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_compression_test) {
// Compressing:
std::string FuncNameStrings2;
- EXPECT_THAT_ERROR(collectPGOFuncNameStrings(
+ EXPECT_THAT_ERROR(collectGlobalVariableNameStrings(
FuncNames2,
(DoCompression && compression::zlib::isAvailable()),
FuncNameStrings2),
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since both Function and GlobalVariable are subclasses of GlobalObject, perhaps name it collectGlobalObjectNameStrings?
…cpp) that calls this function.
done. |
@@ -220,17 +220,17 @@ StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar); | |||
StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, | |||
StringRef FileName = "<unknown>"); | |||
|
|||
/// Given a vector of strings (function PGO names) \c NameStrs, the | |||
/// method generates a combined string \c Result that is ready to be | |||
/// Given a vector of strings (names of global variables) \c NameStrs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variable --> object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variable --> object
done.
/// third field is the uncompressed strings; otherwise it is the | ||
/// compressed string. When the string compression is off, the | ||
/// second field will have value zero. | ||
Error collectPGOFuncNameStrings(ArrayRef<std::string> NameStrs, | ||
bool doCompression, std::string &Result); | ||
Error collectGlobalObjectNameStrings(ArrayRef<std::string> NameStrs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a bunch of other PGOFuncName functions in this header file. Is this the only one that will be used for vtable profiling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good question. I'll need to record the PGO name of vtables (i.e., just variable name if the vtable is external, and variable name with file path prefix if the vtable is local) jus like we record PGO name of functions (e.g., guid computed from global identifier is used for LTO) so a few other methods (with Func
in function name, or Function
as function paremeter type) needs to be generalized.
In this patch, added two small rename for static functions. The other collectPGOFuncNameStrings currently takes the global variable that consisting of a string literal (@__profn__Z4funcP4BaseP14FuncPtrWrapper = private constant [30 x i8] c"_Z4funcP4BaseP14FuncPtrWrapper"
in the per-pass output of pgo-instr-gen
in https://gcc.godbolt.org/z/97b6rzvvx) so I'll keep them there.
If more renames are needed later, I'm thinking of keeping the name getIRPGOFuncName
since it's clearer for callers to know the callee is what they want (which reduces brain teasers to correlate 'Func' with 'Object' at least for me), and let it forward to an internal static function getIRPGONameForObject
).
…gument type) to use them for general global objects (functions, vtable objects) 2. In InstrProf.h, add a function comment around the element in NameVars.
Per offline chat,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm with comment fix
llvm/lib/ProfileData/InstrProf.cpp
Outdated
} | ||
|
||
// This is similar to `getIRPGOFuncName` except that this function calls | ||
// 'getIRPGOFuncName' to get a name and `getIRPGOFuncName` calls 'getIRPGOName'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should say "this function calls 'getPGOFuncName' to get a name and getIRPGOFuncName
calls 'getIRPGONameForGlobalObject'? (note changes to both mentioned callees)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the catch. Updated it.
Local branch amd-gfx e08414e Merged main:0cbaff815cf2 into amd-gfx:ec3fdb3aaad4 Remote branch main a1e9777 [NFC] In InstrProf, generalize helper functions to take GlobalObject. They currently take Functions as function parameters or have Func in the name. (llvm#70287)
collectPGOFuncNameStrings
is reused a lot in pr/66825 to collect vtable names; and in some added callsites it's just weird to see 'func' since context clearly shows it's not. This function currently just takes a list of strings as input so name it tocollectGlobalObjectNameStrings