[llvm] [InstrProf] Adding utility weights to BalancedPartitioning (PR #72717)

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 20 09:30:10 PST 2023


================
@@ -167,37 +176,38 @@ void BalancedPartitioning::runIterations(const FunctionNodeRange Nodes,
                                          unsigned RightBucket,
                                          std::mt19937 &RNG) const {
   unsigned NumNodes = std::distance(Nodes.begin(), Nodes.end());
-  DenseMap<BPFunctionNode::UtilityNodeT, unsigned> UtilityNodeDegree;
+  DenseMap<uint32_t, unsigned> UtilityNodeDegree;
   for (auto &N : Nodes)
     for (auto &UN : N.UtilityNodes)
-      ++UtilityNodeDegree[UN];
+      ++UtilityNodeDegree[UN.id];
   // Remove utility nodes if they have just one edge or are connected to all
   // functions
   for (auto &N : Nodes)
     llvm::erase_if(N.UtilityNodes, [&](auto &UN) {
-      return UtilityNodeDegree[UN] <= 1 || UtilityNodeDegree[UN] >= NumNodes;
+      return UtilityNodeDegree[UN.id] <= 1 ||
+             UtilityNodeDegree[UN.id] >= NumNodes;
     });
 
   // Renumber utility nodes so they can be used to index into Signatures
-  DenseMap<BPFunctionNode::UtilityNodeT, unsigned> UtilityNodeIndex;
+  DenseMap<uint32_t, unsigned> UtilityNodeIndex;
   for (auto &N : Nodes)
     for (auto &UN : N.UtilityNodes)
-      if (!UtilityNodeIndex.count(UN))
-        UtilityNodeIndex[UN] = UtilityNodeIndex.size();
+      if (!UtilityNodeIndex.count(UN.id))
+        UtilityNodeIndex[UN.id] = UtilityNodeIndex.size();
   for (auto &N : Nodes)
     for (auto &UN : N.UtilityNodes)
-      UN = UtilityNodeIndex[UN];
+      UN.id = UtilityNodeIndex[UN.id];
 
   // Initialize signatures
   SignaturesT Signatures(/*Size=*/UtilityNodeIndex.size());
   for (auto &N : Nodes) {
     for (auto &UN : N.UtilityNodes) {
-      assert(UN < Signatures.size());
-      if (N.Bucket == LeftBucket) {
-        Signatures[UN].LeftCount++;
-      } else {
-        Signatures[UN].RightCount++;
-      }
+      assert(UN.id < Signatures.size());
+      if (N.Bucket == LeftBucket)
+        Signatures[UN.id].LeftCount++;
+      else
+        Signatures[UN.id].RightCount++;
+      Signatures[UN.id].Weight = UN.weight;
----------------
ellishg wrote:

I think a signature could be affected by multiple utility nodes, each of which could have different weights. So I'm not sure this is exactly correct. In fact, I think with this change `CachedGainLR` is now dependent on which utility node moves between buckets, so we can no longer cache this value.

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


More information about the llvm-commits mailing list