diff --git a/llvm/include/llvm/CodeGen/ScheduleDAG.h b/llvm/include/llvm/CodeGen/ScheduleDAG.h --- a/llvm/include/llvm/CodeGen/ScheduleDAG.h +++ b/llvm/include/llvm/CodeGen/ScheduleDAG.h @@ -713,6 +713,10 @@ public: ScheduleDAGTopologicalSort(std::vector &SUnits, SUnit *ExitSU); + /// Add a SUnit without predecessors to the end of the topological order. It + /// also must be the first new node added to the DAG. + void AddSUnitWithoutPredecessors(const SUnit *SU); + /// Creates the initial topological ordering from the DAG to be scheduled. void InitDAGTopologicalSorting(); diff --git a/llvm/lib/CodeGen/ScheduleDAG.cpp b/llvm/lib/CodeGen/ScheduleDAG.cpp --- a/llvm/lib/CodeGen/ScheduleDAG.cpp +++ b/llvm/lib/CodeGen/ScheduleDAG.cpp @@ -674,6 +674,14 @@ return false; } +void ScheduleDAGTopologicalSort::AddSUnitWithoutPredecessors(const SUnit *SU) { + assert(SU->NodeNum == Index2Node.size() && "Node cannot be added at the end"); + assert(SU->NumPreds == 0 && "Can only add SU's with no predecessors"); + Node2Index.push_back(Index2Node.size()); + Index2Node.push_back(SU->NodeNum); + Visited.resize(Node2Index.size()); +} + bool ScheduleDAGTopologicalSort::IsReachable(const SUnit *SU, const SUnit *TargetSU) { // If insertion of the edge SU->TargetSU would create a cycle diff --git a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp --- a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp @@ -272,7 +272,7 @@ SUnit *NewNode = newSUnit(N); // Update the topological ordering. if (NewNode->NodeNum >= NumSUnits) - Topo.InitDAGTopologicalSorting(); + Topo.AddSUnitWithoutPredecessors(NewNode); return NewNode; } @@ -283,7 +283,7 @@ SUnit *NewNode = Clone(N); // Update the topological ordering. if (NewNode->NodeNum >= NumSUnits) - Topo.InitDAGTopologicalSorting(); + Topo.AddSUnitWithoutPredecessors(NewNode); return NewNode; }