[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
diff --git a/llvm/include/llvm/ProfileData/SampleProfReader.h b/llvm/include/llvm/ProfileData/SampleProfReader.h
index de85a5a..94ac079 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 @@
   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 6621684..d3aec9d 100644
--- a/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
@@ -771,9 +771,7 @@
   // 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 @@
     // 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