@@ -139,9 +139,6 @@ class SchedGroup {
139139 // Count of the number of created SchedGroups, used to initialize SGID.
140140 static unsigned NumSchedGroups;
141141
142- // Try to add and edge from SU A to SU B.
143- bool tryAddEdge (SUnit *A, SUnit *B);
144-
145142 // Use SGMask to determine whether we can classify MI as a member of this
146143 // SchedGroup object.
147144 bool canAddMI (const MachineInstr &MI) const ;
@@ -153,6 +150,9 @@ class SchedGroup {
153150 ScheduleDAGInstrs *DAG;
154151 const SIInstrInfo *TII;
155152
153+ // Try to add and edge from SU A to SU B.
154+ bool tryAddEdge (SUnit *A, SUnit *B);
155+
156156 // Returns true if SU can be added to this SchedGroup.
157157 bool canAddSU (SUnit &SU) const ;
158158
@@ -164,7 +164,7 @@ class SchedGroup {
164164 // Add DAG dependencies and track which edges are added, and the count of
165165 // missed edges
166166 int link (SUnit &SU, bool MakePred,
167- std::vector <std::pair<SUnit *, SUnit *>> &AddedEdges);
167+ std::list <std::pair<SUnit *, SUnit *>> &AddedEdges);
168168
169169 // Add DAG dependencies from all SUnits in this SchedGroup and this SU.
170170 // Use the predicate to determine whether SU should be a predecessor (P =
@@ -305,8 +305,7 @@ class PipelineSolver {
305305 // current information. One step in the greedy algorithm. Templated against
306306 // the SchedGroup iterator (either reverse or forward).
307307 template <typename T>
308- void greedyFind (std::vector<std::pair<SUnit *, SUnit *>> &AddedEdges, T I,
309- T E);
308+ void greedyFind (std::list<std::pair<SUnit *, SUnit *>> &AddedEdges, T I, T E);
310309 // Whether or not the current solution is optimal
311310 bool checkOptimal ();
312311 // Populate the ready list, prioiritizing fewest missed edges first
@@ -322,15 +321,15 @@ class PipelineSolver {
322321 // Add the edges from the SU to the other SchedGroups in pipeline, and
323322 // return the number of edges missed.
324323 int addEdges (SmallVectorImpl<SchedGroup> &SyncPipeline, SUnit *SU, int SGID,
325- std::vector <std::pair<SUnit *, SUnit *>> &AddedEdges);
324+ std::list <std::pair<SUnit *, SUnit *>> &AddedEdges);
326325 // / Link the pipeline as if \p SU was in the SchedGroup with ID \p SGID. It
327326 // / returns the cost (in terms of missed pipeline edges), and tracks the edges
328327 // / added in \p AddedEdges
329328 template <typename T>
330329 int linkSUnit (SUnit *SU, int SGID,
331- std::vector <std::pair<SUnit *, SUnit *>> &AddedEdges, T I, T E);
330+ std::list <std::pair<SUnit *, SUnit *>> &AddedEdges, T I, T E);
332331 // / Remove the edges passed via \p AddedEdges
333- void removeEdges (const std::vector <std::pair<SUnit *, SUnit *>> &AddedEdges);
332+ void removeEdges (const std::list <std::pair<SUnit *, SUnit *>> &AddedEdges);
334333 // Convert the passed in maps to arrays for bidirectional iterators
335334 void convertSyncMapsToArrays ();
336335
@@ -454,7 +453,7 @@ void PipelineSolver::makePipeline() {
454453
455454template <typename T>
456455int PipelineSolver::linkSUnit (
457- SUnit *SU, int SGID, std::vector <std::pair<SUnit *, SUnit *>> &AddedEdges,
456+ SUnit *SU, int SGID, std::list <std::pair<SUnit *, SUnit *>> &AddedEdges,
458457 T I, T E) {
459458 bool MakePred = false ;
460459 int AddedCost = 0 ;
@@ -472,7 +471,7 @@ int PipelineSolver::linkSUnit(
472471
473472int PipelineSolver::addEdges (
474473 SmallVectorImpl<SchedGroup> &SyncPipeline, SUnit *SU, int SGID,
475- std::vector <std::pair<SUnit *, SUnit *>> &AddedEdges) {
474+ std::list <std::pair<SUnit *, SUnit *>> &AddedEdges) {
476475
477476 // For IsBottomUp, the first SchedGroup in SyncPipeline contains the
478477 // instructions that are the ultimate successors in the resultant mutation.
@@ -489,7 +488,7 @@ int PipelineSolver::addEdges(
489488}
490489
491490void PipelineSolver::removeEdges (
492- const std::vector <std::pair<SUnit *, SUnit *>> &EdgesToRemove) {
491+ const std::list <std::pair<SUnit *, SUnit *>> &EdgesToRemove) {
493492 // Only remove the edges that we have added when testing
494493 // the fit.
495494 for (auto &PredSuccPair : EdgesToRemove) {
@@ -568,7 +567,7 @@ void PipelineSolver::populateReadyList(
568567 assert (CurrSU.second .size () >= 1 );
569568
570569 for (; I != E; ++I) {
571- std::vector <std::pair<SUnit *, SUnit *>> AddedEdges;
570+ std::list <std::pair<SUnit *, SUnit *>> AddedEdges;
572571 int CandSGID = *I;
573572 SchedGroup *Match = llvm::find_if (SyncPipeline, [CandSGID](SchedGroup &SG) {
574573 return SG.getSGID () == CandSGID;
@@ -627,7 +626,7 @@ bool PipelineSolver::solveExact() {
627626
628627 int CandSGID = I->first ;
629628 int AddedCost = 0 ;
630- std::vector <std::pair<SUnit *, SUnit *>> AddedEdges;
629+ std::list <std::pair<SUnit *, SUnit *>> AddedEdges;
631630 auto &SyncPipeline = CurrPipeline[CurrSyncGroupIdx];
632631 SchedGroup *Match;
633632 for (auto &SG : SyncPipeline) {
@@ -694,12 +693,13 @@ bool PipelineSolver::solveExact() {
694693
695694template <typename T>
696695void PipelineSolver::greedyFind (
697- std::vector <std::pair<SUnit *, SUnit *>> &AddedEdges, T I, T E) {
696+ std::list <std::pair<SUnit *, SUnit *>> &AddedEdges, T I, T E) {
698697 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
699698 int BestNodeCost = -1 ;
700699 int TempCost;
701700 SchedGroup *BestGroup = nullptr ;
702701 int BestGroupID = -1 ;
702+ std::list<std::pair<SUnit *, SUnit *>> BestEdges;
703703 auto &SyncPipeline = CurrPipeline[CurrSyncGroupIdx];
704704 LLVM_DEBUG (dbgs () << " Fitting SU(" << CurrSU.first ->NodeNum
705705 << " ) in Pipeline # " << CurrSyncGroupIdx << " \n " );
@@ -709,7 +709,6 @@ void PipelineSolver::greedyFind(
709709 // first. If we fail to do this for the greedy algorithm, the solution will
710710 // likely not be good in more complex cases.
711711 for (; I != E; ++I) {
712- std::vector<std::pair<SUnit *, SUnit *>> AddedEdges;
713712 int CandSGID = *I;
714713 SchedGroup *Match = llvm::find_if (SyncPipeline, [CandSGID](SchedGroup &SG) {
715714 return SG.getSGID () == CandSGID;
@@ -727,21 +726,36 @@ void PipelineSolver::greedyFind(
727726 LLVM_DEBUG (dbgs () << " SGID # " << CandSGID << " has conflicting rule\n " );
728727 continue ;
729728 }
730- TempCost = addEdges (SyncPipeline, CurrSU.first , CandSGID, AddedEdges);
729+
730+ std::list<std::pair<SUnit *, SUnit *>> TempEdges;
731+ TempCost = addEdges (SyncPipeline, CurrSU.first , CandSGID, TempEdges);
731732 LLVM_DEBUG (dbgs () << " Cost of Group " << TempCost << " \n " );
733+
732734 if (TempCost < BestNodeCost || BestNodeCost == -1 ) {
735+ BestEdges = TempEdges;
733736 BestGroup = Match;
734737 BestNodeCost = TempCost;
735738 BestGroupID = CandSGID;
739+
740+ if (BestNodeCost == 0 )
741+ break ;
736742 }
737- removeEdges (AddedEdges);
738- if (BestNodeCost == 0 )
739- break ;
743+
744+ removeEdges (TempEdges);
740745 }
741746
742747 if (BestGroupID != -1 ) {
743748 BestGroup->add (*CurrSU.first );
744- addEdges (SyncPipeline, CurrSU.first , BestGroupID, AddedEdges);
749+ if (AddedEdges.empty ())
750+ AddedEdges = BestEdges;
751+ else
752+ AddedEdges.splice (std::prev (AddedEdges.cend ()), BestEdges);
753+
754+ for (const std::pair<SUnit *, SUnit *> &E : BestEdges) {
755+ if (!BestGroup->tryAddEdge (E.first , E.second ))
756+ llvm_unreachable (" Edges known to be insertable." );
757+ }
758+
745759 LLVM_DEBUG (dbgs () << " Best Group has ID: " << BestGroupID << " and Mask"
746760 << (int )BestGroup->getMask () << " \n " );
747761 BestCost += TempCost;
@@ -753,7 +767,7 @@ void PipelineSolver::greedyFind(
753767
754768bool PipelineSolver::solveGreedy () {
755769 BestCost = 0 ;
756- std::vector <std::pair<SUnit *, SUnit *>> AddedEdges;
770+ std::list <std::pair<SUnit *, SUnit *>> AddedEdges;
757771
758772 while (static_cast <size_t >(CurrSyncGroupIdx) < PipelineInstrs.size ()) {
759773 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
@@ -2379,11 +2393,7 @@ class IGroupLPDAGMutation : public ScheduleDAGMutation {
23792393unsigned SchedGroup::NumSchedGroups = 0 ;
23802394
23812395bool SchedGroup::tryAddEdge (SUnit *A, SUnit *B) {
2382- if (A != B && DAG->canAddEdge (B, A)) {
2383- DAG->addEdge (B, SDep (A, SDep::Artificial));
2384- return true ;
2385- }
2386- return false ;
2396+ return A != B && DAG->addEdge (B, SDep (A, SDep::Artificial));
23872397}
23882398
23892399bool SchedGroup::canAddMI (const MachineInstr &MI) const {
@@ -2448,7 +2458,7 @@ bool SchedGroup::canAddMI(const MachineInstr &MI) const {
24482458}
24492459
24502460int SchedGroup::link (SUnit &SU, bool MakePred,
2451- std::vector <std::pair<SUnit *, SUnit *>> &AddedEdges) {
2461+ std::list <std::pair<SUnit *, SUnit *>> &AddedEdges) {
24522462 int MissedEdges = 0 ;
24532463 for (auto *A : Collection) {
24542464 SUnit *B = &SU;
0 commit comments