[llvm] [NFC][InstrProf]Factor out getCanonicalName to compute the canonical name given a pgo name. (PR #81547)

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 08:30:07 PST 2024


================
@@ -544,11 +544,12 @@ StringRef InstrProfSymtab::getCanonicalName(StringRef PGOName) {
 }
 
 Error InstrProfSymtab::addFuncWithName(Function &F, StringRef PGOFuncName) {
-  StringSet<> Names;
-  Names.insert(PGOFuncName);
-  Names.insert(InstrProfSymtab::getCanonicalName(PGOFuncName));
-  for (const auto &NameEntry : Names) {
-    StringRef Name = NameEntry.getKey();
+  SmallVector<StringRef, 2> Names;
+  Names.push_back(PGOFuncName);
+  StringRef CanonicalFuncName = getCanonicalName(PGOFuncName);
+  if (CanonicalFuncName != PGOFuncName)
----------------
teresajohnson wrote:

Since you are doing this check explicitly here, rather than add to a vector and iterating it, suggest putting the handling currently within the loop body into a lambda and simply calling it twice (with the second call guarded by this if).

https://github.com/llvm/llvm-project/pull/81547


More information about the llvm-commits mailing list