[PATCH] D142269: [BOLT] Use LTO fuzzy name matching in function-order=user

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 19:39:55 PST 2023


Amir updated this revision to Diff 491589.
Amir added a comment.

Augment the list of functions to process with those that match common LTO
prefix of -function-order functions.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142269/new/

https://reviews.llvm.org/D142269

Files:
  bolt/lib/Passes/ReorderFunctions.cpp
  bolt/lib/Rewrite/RewriteInstance.cpp


Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -2756,10 +2756,14 @@
       LiteThresholdExecCount, static_cast<uint64_t>(opts::LiteThresholdCount));
 
   StringSet<> ReorderFunctionsUserSet;
+  StringSet<> ReorderFunctionsLTOCommonSet;
   if (opts::ReorderFunctions == ReorderFunctions::RT_USER) {
     for (const std::string &Function :
-         ReorderFunctions::readFunctionOrderFile())
+         ReorderFunctions::readFunctionOrderFile()) {
       ReorderFunctionsUserSet.insert(Function);
+      if (std::optional<StringRef> LTOCommonName = getLTOCommonName(Function))
+        ReorderFunctionsLTOCommonSet.insert(*LTOCommonName);
+    }
   }
 
   uint64_t NumFunctionsToProcess = 0;
@@ -2795,6 +2799,10 @@
             });
         if (Match.has_value())
           return true;
+        for (const StringRef Name : Function.getNames())
+          if (std::optional<StringRef> LTOCommonName = getLTOCommonName(Name))
+            if (ReorderFunctionsLTOCommonSet.contains(*LTOCommonName))
+              return true;
       }
 
       if (ProfileReader && !ProfileReader->mayHaveProfileData(Function))
Index: bolt/lib/Passes/ReorderFunctions.cpp
===================================================================
--- bolt/lib/Passes/ReorderFunctions.cpp
+++ bolt/lib/Passes/ReorderFunctions.cpp
@@ -12,6 +12,8 @@
 
 #include "bolt/Passes/ReorderFunctions.h"
 #include "bolt/Passes/HFSort.h"
+#include "bolt/Utils/Utils.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/CommandLine.h"
 #include <fstream>
 
@@ -332,6 +334,13 @@
     break;
   case RT_USER:
     {
+      // Build LTOCommonNameMap
+      StringMap<std::vector<uint64_t>> LTOCommonNameMap;
+      for (const BinaryFunction &BF : llvm::make_second_range(BFs))
+        for (StringRef Name : BF.getNames())
+          if (std::optional<StringRef> LTOCommonName = getLTOCommonName(Name))
+            LTOCommonNameMap[*LTOCommonName].push_back(BF.getAddress());
+
       uint32_t Index = 0;
       uint32_t InvalidEntries = 0;
       for (const std::string &Function : readFunctionOrderFile()) {
@@ -339,9 +348,9 @@
 
         BinaryData *BD = BC.getBinaryDataByName(Function);
         if (!BD) {
+          // If we can't find the main symbol name, look for alternates.
           uint32_t LocalID = 1;
           while (true) {
-            // If we can't find the main symbol name, look for alternates.
             const std::string FuncName =
                 Function + "/" + std::to_string(LocalID);
             BD = BC.getBinaryDataByName(FuncName);
@@ -351,6 +360,10 @@
               break;
             LocalID++;
           }
+          // Strip LTO suffixes
+          if (std::optional<StringRef> CommonName = getLTOCommonName(Function))
+            if (LTOCommonNameMap.find(*CommonName) != LTOCommonNameMap.end())
+              llvm::append_range(FuncAddrs, LTOCommonNameMap[*CommonName]);
         } else {
           FuncAddrs.push_back(BD->getAddress());
         }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142269.491589.patch
Type: text/x-patch
Size: 3118 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230124/9a75a82a/attachment.bin>


More information about the llvm-commits mailing list