Optimize ScheduleDAG's ComputeDepths and ComputeHeights to not need

a scratch std::vector.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55420 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2008-08-27 16:27:25 +00:00
parent a8b8332e81
commit 3a09d891a4

View File

@ -250,17 +250,15 @@ void ScheduleDAG::ComputeLatency(SUnit *SU) {
/// paths in the DAG /// paths in the DAG
void ScheduleDAG::CalculateDepths() { void ScheduleDAG::CalculateDepths() {
unsigned DAGSize = SUnits.size(); unsigned DAGSize = SUnits.size();
std::vector<unsigned> InDegree(DAGSize);
std::vector<SUnit*> WorkList; std::vector<SUnit*> WorkList;
WorkList.reserve(DAGSize); WorkList.reserve(DAGSize);
// Initialize the data structures // Initialize the data structures
for (unsigned i = 0, e = DAGSize; i != e; ++i) { for (unsigned i = 0, e = DAGSize; i != e; ++i) {
SUnit *SU = &SUnits[i]; SUnit *SU = &SUnits[i];
int NodeNum = SU->NodeNum;
unsigned Degree = SU->Preds.size(); unsigned Degree = SU->Preds.size();
InDegree[NodeNum] = Degree; // Temporarily use the Depth field as scratch space for the degree count.
SU->Depth = 0; SU->Depth = Degree;
// Is it a node without dependencies? // Is it a node without dependencies?
if (Degree == 0) { if (Degree == 0) {
@ -274,7 +272,7 @@ void ScheduleDAG::CalculateDepths() {
while (!WorkList.empty()) { while (!WorkList.empty()) {
SUnit *SU = WorkList.back(); SUnit *SU = WorkList.back();
WorkList.pop_back(); WorkList.pop_back();
unsigned &SUDepth = SU->Depth; unsigned SUDepth = 0;
// Use dynamic programming: // Use dynamic programming:
// When current node is being processed, all of its dependencies // When current node is being processed, all of its dependencies
@ -288,11 +286,13 @@ void ScheduleDAG::CalculateDepths() {
} }
} }
// Update InDegrees of all nodes depending on current SUnit SU->Depth = SUDepth;
// Update degrees of all nodes depending on current SUnit
for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
I != E; ++I) { I != E; ++I) {
SUnit *SU = I->Dep; SUnit *SU = I->Dep;
if (!--InDegree[SU->NodeNum]) if (!--SU->Depth)
// If all dependencies of the node are processed already, // If all dependencies of the node are processed already,
// then the longest path for the node can be computed now // then the longest path for the node can be computed now
WorkList.push_back(SU); WorkList.push_back(SU);
@ -304,17 +304,15 @@ void ScheduleDAG::CalculateDepths() {
/// paths in the DAG /// paths in the DAG
void ScheduleDAG::CalculateHeights() { void ScheduleDAG::CalculateHeights() {
unsigned DAGSize = SUnits.size(); unsigned DAGSize = SUnits.size();
std::vector<unsigned> InDegree(DAGSize);
std::vector<SUnit*> WorkList; std::vector<SUnit*> WorkList;
WorkList.reserve(DAGSize); WorkList.reserve(DAGSize);
// Initialize the data structures // Initialize the data structures
for (unsigned i = 0, e = DAGSize; i != e; ++i) { for (unsigned i = 0, e = DAGSize; i != e; ++i) {
SUnit *SU = &SUnits[i]; SUnit *SU = &SUnits[i];
int NodeNum = SU->NodeNum;
unsigned Degree = SU->Succs.size(); unsigned Degree = SU->Succs.size();
InDegree[NodeNum] = Degree; // Temporarily use the Height field as scratch space for the degree count.
SU->Height = 0; SU->Height = Degree;
// Is it a node without dependencies? // Is it a node without dependencies?
if (Degree == 0) { if (Degree == 0) {
@ -329,7 +327,7 @@ void ScheduleDAG::CalculateHeights() {
while (!WorkList.empty()) { while (!WorkList.empty()) {
SUnit *SU = WorkList.back(); SUnit *SU = WorkList.back();
WorkList.pop_back(); WorkList.pop_back();
unsigned &SUHeight = SU->Height; unsigned SUHeight = 0;
// Use dynamic programming: // Use dynamic programming:
// When current node is being processed, all of its dependencies // When current node is being processed, all of its dependencies
@ -343,11 +341,13 @@ void ScheduleDAG::CalculateHeights() {
} }
} }
// Update InDegrees of all nodes depending on current SUnit SU->Height = SUHeight;
// Update degrees of all nodes depending on current SUnit
for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
I != E; ++I) { I != E; ++I) {
SUnit *SU = I->Dep; SUnit *SU = I->Dep;
if (!--InDegree[SU->NodeNum]) if (!--SU->Height)
// If all dependencies of the node are processed already, // If all dependencies of the node are processed already,
// then the longest path for the node can be computed now // then the longest path for the node can be computed now
WorkList.push_back(SU); WorkList.push_back(SU);