[llvm] [SampleProfile] Introduce SampleProfileNameSet (NFC) (PR #208114)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 7 15:52:04 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-pgo
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
This patch introduces a helper class SampleProfileNameSet to
encapsulate the construction of the name set and provide a contains
method.
I'm planning to speed up the membership queries into the name table.
With this patch, changes to the underlying data structure won't affect
use sites.
Assisted-by: Antigravity
---
Full diff: https://github.com/llvm/llvm-project/pull/208114.diff
2 Files Affected:
- (modified) llvm/include/llvm/ProfileData/SampleProfReader.h (+17)
- (modified) llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp (+2-4)
``````````diff
diff --git a/llvm/include/llvm/ProfileData/SampleProfReader.h b/llvm/include/llvm/ProfileData/SampleProfReader.h
index 251e6a8f4843a..aaddd5a5693e0 100644
--- a/llvm/include/llvm/ProfileData/SampleProfReader.h
+++ b/llvm/include/llvm/ProfileData/SampleProfReader.h
@@ -1157,6 +1157,23 @@ class LLVM_ABI SampleProfileReaderGCC : public SampleProfileReader {
static const uint32_t GCOVTagAFDOFunction = 0xac000000;
};
+/// A helper class that wraps a local set of string names from NameTable.
+class SampleProfileNameSet {
+ const SampleProfileReader &Reader;
+ StringSet<> NamesInProfile;
+
+public:
+ explicit SampleProfileNameSet(const SampleProfileReader &R) : Reader(R) {
+ for (FunctionId Name : Reader.getNameTable())
+ NamesInProfile.insert(Name.stringRef());
+ }
+
+ /// Check if a canonical function name exists in the profile name table.
+ bool contains(StringRef CanonName) const {
+ return NamesInProfile.contains(CanonName);
+ }
+};
+
} // end namespace sampleprof
} // end namespace llvm
diff --git a/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp b/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
index 6621684232812..d3aec9d7c363c 100644
--- a/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
@@ -771,9 +771,7 @@ void SampleProfileMatcher::findFunctionsWithoutProfile() {
// TODO: Support MD5 profile.
if (FunctionSamples::UseMD5)
return;
- StringSet<> NamesInProfile;
- for (FunctionId Name : Reader.getNameTable())
- NamesInProfile.insert(Name.stringRef());
+ SampleProfileNameSet NamesInProfile(Reader);
for (auto &F : M) {
// Skip declarations, as even if the function can be matched, we have
@@ -789,7 +787,7 @@ void SampleProfileMatcher::findFunctionsWithoutProfile() {
// For extended binary, functions fully inlined may not be loaded in the
// top-level profile, so check the NameTable which has the all symbol names
// in profile.
- if (NamesInProfile.count(CanonFName))
+ if (NamesInProfile.contains(CanonFName))
continue;
// For extended binary, non-profiled function symbols are in the profile
``````````
</details>
https://github.com/llvm/llvm-project/pull/208114
More information about the llvm-commits
mailing list