[PATCH] D75918: [MachinePipeliner] Refine the RecMII calculation

Lama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 10 06:24:19 PDT 2020


lsaba created this revision.
lsaba added reviewers: bcahoon, kparzysz, jsji.
Herald added a subscriber: steven.zhang.
Herald added a project: LLVM.

In the case of more than one SDep  between two successor SUnits in the Nodeset, the current implementation sums the latencies of the dependencies, which could create a larger RecMII than necessary.

for example, in case there is both a data dependency and an output dependency (with latency > 0) between successor nodes:
SU(1) inst1:

  successors:
    SU(2): out  latency = 1
    SU(2): data latency = 1

SU(2) inst2:

  successors:
    SU(3): out  latency = 1
    SU(3): data latency = 1

SU(3) inst3:

  successors:
    SU(1): out  latency = 1
    SU(1): data latency = 1

the NodeSet latency returned would be 6, whereas it could be 3 if we take the max for each successor SUnit.
In general this can be extended to finding the shortest path in the recurrence..
thoughts?

Unfortunately I had a hard time creating a test for this in Hexagon/PowerPC, so help would be appreciated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75918

Files:
  llvm/include/llvm/CodeGen/MachinePipeliner.h


Index: llvm/include/llvm/CodeGen/MachinePipeliner.h
===================================================================
--- llvm/include/llvm/CodeGen/MachinePipeliner.h
+++ llvm/include/llvm/CodeGen/MachinePipeliner.h
@@ -330,10 +330,22 @@
   NodeSet() = default;
   NodeSet(iterator S, iterator E) : Nodes(S, E), HasRecurrence(true) {
     Latency = 0;
-    for (unsigned i = 0, e = Nodes.size(); i < e; ++i)
-      for (const SDep &Succ : Nodes[i]->Succs)
-        if (Nodes.count(Succ.getSUnit()))
-          Latency += Succ.getLatency();
+    for (unsigned i = 0, e = Nodes.size(); i < e; ++i) {
+      DenseMap<SUnit *, unsigned> SuccSUnitLatency;
+      for (const SDep &Succ : Nodes[i]->Succs) {
+        auto SuccSUnit = Succ.getSUnit();
+        if (!Nodes.count(SuccSUnit))
+          continue;
+        unsigned CurLatency = Succ.getLatency();
+        unsigned MaxLatency = 0;
+        if (SuccSUnitLatency.count(SuccSUnit))
+          MaxLatency = SuccSUnitLatency[SuccSUnit];
+        if (CurLatency > MaxLatency)
+          SuccSUnitLatency[SuccSUnit] = CurLatency;
+      }
+      for (auto SUnitLatency : SuccSUnitLatency)
+        Latency += SUnitLatency.second;
+    }
   }
 
   bool insert(SUnit *SU) { return Nodes.insert(SU); }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75918.249349.patch
Type: text/x-patch
Size: 1250 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200310/5f5c9d21/attachment.bin>


More information about the llvm-commits mailing list