[llvm] [CGData][MachineOutliner] Global Outlining (PR #90074)

Amara Emerson via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 28 13:46:43 PDT 2024


================
@@ -695,6 +859,39 @@ void MachineOutliner::findCandidates(
   }
 }
 
+void MachineOutliner::computeAndPublishHashSequence(MachineFunction &MF,
+                                                    unsigned CandSize) {
+  // Compute the hash sequence for the outlined function.
+  SmallVector<stable_hash> OutlinedHashSequence;
+  for (auto &MBB : MF) {
+    for (auto &NewMI : MBB) {
+      stable_hash Hash = stableHashValue(NewMI);
+      if (!Hash) {
+        OutlinedHashSequence.clear();
+        break;
+      }
+      OutlinedHashSequence.push_back(Hash);
+    }
+  }
+
+  // Append a unique name based on the non-empty hash sequence.
+  if (AppendContentHashToOutlinedName && !OutlinedHashSequence.empty()) {
+    auto CombinedHash = stable_hash_combine(OutlinedHashSequence);
+    auto NewName =
+        MF.getName().str() + ".content." + std::to_string(CombinedHash);
+    MF.getFunction().setName(NewName);
+  }
+
+  // Publish the non-empty hash sequence to the local hash tree.
+  if (OutlinerMode == CGDataMode::Write) {
+    StableHashAttempts++;
+    if (!OutlinedHashSequence.empty())
+      LocalHashTree->insert({OutlinedHashSequence, CandSize});
----------------
aemerson wrote:

> This count helps us decide which candidates are most important to outline based on their frequency across all modules.

This is I guess the core of my question. As long as you have a size saving, surely you would outline *all* profitable candidate functions rather so ordering them seems redundant? I'm probably missing something.

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


More information about the llvm-commits mailing list