[llvm] [MachinePipeliner] Add an abstract layer to manipulate Data Dependenc… (PR #109918)

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 3 03:47:58 PST 2025


================
@@ -114,10 +115,123 @@ class MachinePipeliner : public MachineFunctionPass {
   bool useWindowScheduler(bool Changed);
 };
 
+/// Represents a dependence between two instruction.
+class SwingSchedulerDDGEdge {
+  SUnit *Dst = nullptr;
+  SDep Pred;
+  unsigned Distance = 0;
+
+public:
+  /// Creates an edge corresponding to an edge represented by \p PredOrSucc and
+  /// \p Dep in the original DAG. This pair has no information about the
+  /// direction of the edge, so we need to pass an additional argument \p
+  /// IsSucc.
+  SwingSchedulerDDGEdge(SUnit *PredOrSucc, const SDep &Dep, bool IsSucc)
+      : Dst(PredOrSucc), Pred(Dep), Distance(0u) {
+    SUnit *Src = Dep.getSUnit();
+
+    if (IsSucc) {
+      std::swap(Src, Dst);
+      Pred.setSUnit(Src);
+    }
+
+    // An anti-dependence to PHI means loop-carried dependence.
+    if (Pred.getKind() == SDep::Anti && Src->getInstr()->isPHI()) {
+      Distance = 1;
+      std::swap(Src, Dst);
+      auto Reg = Pred.getReg();
+      Pred = SDep(Src, SDep::Kind::Data, Reg);
----------------
kasuga-fj wrote:

Thanks for your investigation. I see, so there are actual cases where the compiler crashes. Hmm, but I'm not sure what the root cause is.

- A dependence type is changed from `anti` to `data` only if the **source** instruction is PHI. So, in your example, the dependence type is not intended to be replaced unless the `some_instr` is PHI.
- When the dependence is replaced with `data`, the source and the destination is swapped at the same time. In your case, the `DDG` behaves as if there is an edge from the `phi` to the `some_instr`. Therefore, this edge should be handled in the previous loop `for (const auto &OE : DDG->getOutEdges(SU)) { ... }`.

So I'm not sure why your fix changes the behavior. Could you give me more details of your case (e.g., what exactly are `phi` and `some_instr`)?

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


More information about the llvm-commits mailing list