Skip to content
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

Merged
merged 7 commits into from
Oct 26, 2023

Conversation

minglotus-6
Copy link
Contributor

@minglotus-6 minglotus-6 commented Oct 26, 2023

  • For instance, 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 to collectGlobalObjectNameStrings
  • 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.

…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.
@llvmbot llvmbot added the PGO Profile Guided Optimizations label Oct 26, 2023
@llvmbot
Copy link

llvmbot commented Oct 26, 2023

@llvm/pr-subscribers-pgo

Author: Mingming Liu (minglotus-6)

Changes
  • collectPGOFuncNameStrings is reused a lot in pr/66825 to collect vtable names. This function currently just takes a list of strings as input so name it to collectGlobalVariableNameStrings
  • 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.

Full diff: https://github.com/llvm/llvm-project/pull/70287.diff

3 Files Affected:

  • (modified) llvm/include/llvm/ProfileData/InstrProf.h (+4-4)
  • (modified) llvm/lib/ProfileData/InstrProf.cpp (+1-1)
  • (modified) llvm/unittests/ProfileData/InstrProfTest.cpp (+2-2)
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),

Copy link
Contributor

@david-xl david-xl left a 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?

@minglotus-6 minglotus-6 changed the title [NFC]Rename collectPGOFuncNameStrings to collectGlobalVariableNameStrings [NFC]Rename collectPGOFuncNameStrings to collectGlobalObjectNameStrings Oct 26, 2023
@minglotus-6
Copy link
Contributor Author

Since both Function and GlobalVariable are subclasses of GlobalObject, perhaps name it collectGlobalObjectNameStrings?

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable --> object

Copy link
Contributor Author

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,
Copy link
Contributor

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?

Copy link
Contributor Author

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.
@minglotus-6 minglotus-6 changed the title [NFC]Rename collectPGOFuncNameStrings to collectGlobalObjectNameStrings [NFC] In InstrProf, generalize helper functions to take 'GlobalObject'. They currently take 'Functions' as function parameters or have 'Func' in the name. Oct 26, 2023
@minglotus-6
Copy link
Contributor Author

Per offline chat,

  • Added a static function getIRPGOObjectName and forwards getIRPGOFuncName to it. This way existing callers of getIRPGOFuncName remains unchanged, and the semantic (func vs object) is clearer at callsite.
  • Updated the comment of getPGOFuncName.

Copy link
Contributor

@teresajohnson teresajohnson left a 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

}

// This is similar to `getIRPGOFuncName` except that this function calls
// 'getIRPGOFuncName' to get a name and `getIRPGOFuncName` calls 'getIRPGOName'.
Copy link
Contributor

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)

Copy link
Contributor Author

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.

@minglotus-6 minglotus-6 merged commit a1e9777 into llvm:main Oct 26, 2023
1 of 3 checks passed
Guzhu-AMD pushed a commit to GPUOpen-Drivers/llvm-project that referenced this pull request Nov 2, 2023
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants