[llvm] [MachinePipeliner] Add an abstract layer to manipulate Data Dependenc… (PR #109918)
Ryotaro Kasuga via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 12 22:14:42 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:
> "The anti dependence from some_instr to phi becomes the data dependence from phi to some_instr, as I intended."
>
> By looking at this code:
> Src will be some_instr
> Dst will be the phi.
>
> So I believe you meant to tell me that data dep is from some_instr to phi?
Yes, I meant that, but now I think something is incorrect. In your previous comment, you said:
> Input:
> some_instruction -> phi; anti dep
Also
> PredOrSucc: phi
> IsSucc = true,
> Dep: some_instruction; anti dep
This seems to be wrong. IIUIC, `isSucc` should be `false` in this case. This argument doesn't mean the "actual semantics" of the dependency. It just indicates whether the `Dep` is contained in `PredOrSucc->Preds` or `PredOrSucc->Succs`. Inserting some validation code like the following at the top of the ctor might help (I don't check if this code works fine).
```c++
const auto &Edges = (IsSucc ? PredOrSucc->Succs : PredOrSucc->Preds);
bool Valid = false;
for (const SDep &D : Edges)
if (D == Dep)
Valid = true;
assert(Valid && "isSucc may be incorrect");
```
https://github.com/llvm/llvm-project/pull/109918
More information about the llvm-commits
mailing list