[llvm] 720d986 - [SampleProfile] Introduce SampleProfileNameSet (NFC) (#208114)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 8 19:51:21 PDT 2026
Author: Kazu Hirata
Date: 2026-07-08T19:51:17-07:00
New Revision: 720d986d66a0a437fd7f9b0d5dd0fa155dcb27f5
URL: https://github.com/llvm/llvm-project/commit/720d986d66a0a437fd7f9b0d5dd0fa155dcb27f5
DIFF: https://github.com/llvm/llvm-project/commit/720d986d66a0a437fd7f9b0d5dd0fa155dcb27f5.diff
LOG: [SampleProfile] Introduce SampleProfileNameSet (NFC) (#208114)
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
Added:
Modified:
llvm/include/llvm/ProfileData/SampleProfReader.h
llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/SampleProfReader.h b/llvm/include/llvm/ProfileData/SampleProfReader.h
index de85a5aeeaa6e..94ac079882582 100644
--- a/llvm/include/llvm/ProfileData/SampleProfReader.h
+++ b/llvm/include/llvm/ProfileData/SampleProfReader.h
@@ -227,6 +227,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/ProfileSummary.h"
@@ -1163,6 +1164,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
More information about the llvm-commits
mailing list