llvm.org GIT mirror llvm / 217a569
MachineScheduler/ScheduleDAG: Add support for GetSubGraph Patch by Axel Davy (axel.davy@normalesup.org) Differential revision: https://reviews.llvm.org/D30626 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298896 91177308-0d34-0410-b5e6-96231b3b80d8 Valery Pykhtin 3 years ago
2 changed file(s) with 89 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
714714 /// Creates the initial topological ordering from the DAG to be scheduled.
715715 void InitDAGTopologicalSorting();
716716
717 /// Returns an array of SUs that are both in the successor
718 /// subtree of StartSU and in the predecessor subtree of TargetSU.
719 /// StartSU and TargetSU are not in the array.
720 /// Success is false if TargetSU is not in the successor subtree of
721 /// StartSU, else it is true.
722 std::vector GetSubGraph(const SUnit &StartSU, const SUnit &TargetSU,
723 bool &Success);
724
717725 /// Checks if \p SU is reachable from \p TargetSU.
718726 bool IsReachable(const SUnit *SU, const SUnit *TargetSU);
719727
547547 } while (!WorkList.empty());
548548 }
549549
550 std::vector ScheduleDAGTopologicalSort::GetSubGraph(const SUnit &StartSU,
551 const SUnit &TargetSU,
552 bool &Success) {
553 std::vector WorkList;
554 int LowerBound = Node2Index[StartSU.NodeNum];
555 int UpperBound = Node2Index[TargetSU.NodeNum];
556 bool Found = false;
557 BitVector VisitedBack;
558 std::vector Nodes;
559
560 if (LowerBound > UpperBound) {
561 Success = false;
562 return Nodes;
563 }
564
565 WorkList.reserve(SUnits.size());
566 Visited.reset();
567
568 // Starting from StartSU, visit all successors up
569 // to UpperBound.
570 WorkList.push_back(&StartSU);
571 do {
572 const SUnit *SU = WorkList.back();
573 WorkList.pop_back();
574 for (int I = SU->Succs.size()-1; I >= 0; --I) {
575 const SUnit *Succ = SU->Succs[I].getSUnit();
576 unsigned s = Succ->NodeNum;
577 // Edges to non-SUnits are allowed but ignored (e.g. ExitSU).
578 if (Succ->isBoundaryNode())
579 continue;
580 if (Node2Index[s] == UpperBound) {
581 Found = true;
582 continue;
583 }
584 // Visit successors if not already and in affected region.
585 if (!Visited.test(s) && Node2Index[s] < UpperBound) {
586 Visited.set(s);
587 WorkList.push_back(Succ);
588 }
589 }
590 } while (!WorkList.empty());
591
592 if (!Found) {
593 Success = false;
594 return Nodes;
595 }
596
597 WorkList.clear();
598 VisitedBack.resize(SUnits.size());
599 Found = false;
600
601 // Starting from TargetSU, visit all predecessors up
602 // to LowerBound. SUs that are visited by the two
603 // passes are added to Nodes.
604 WorkList.push_back(&TargetSU);
605 do {
606 const SUnit *SU = WorkList.back();
607 WorkList.pop_back();
608 for (int I = SU->Preds.size()-1; I >= 0; --I) {
609 const SUnit *Pred = SU->Preds[I].getSUnit();
610 unsigned s = Pred->NodeNum;
611 // Edges to non-SUnits are allowed but ignored (e.g. EntrySU).
612 if (Pred->isBoundaryNode())
613 continue;
614 if (Node2Index[s] == LowerBound) {
615 Found = true;
616 continue;
617 }
618 if (!VisitedBack.test(s) && Visited.test(s)) {
619 VisitedBack.set(s);
620 WorkList.push_back(Pred);
621 Nodes.push_back(s);
622 }
623 }
624 } while (!WorkList.empty());
625
626 assert(Found && "Error in SUnit Graph!");
627 Success = true;
628 return Nodes;
629 }
630
550631 void ScheduleDAGTopologicalSort::Shift(BitVector& Visited, int LowerBound,
551632 int UpperBound) {
552633 std::vector L;