/// Compute an ILP metric for all nodes in the subDAG reachable via depth-first /// search from this root. void ScheduleDAGILP::computeILP(const SUnit *Root) { if (!IsBottomUp) llvm_unreachable("Top-down ILP metric is unimplemnted"); SchedDAGReverseDFS DFS; // Mark a node visited by validating it. ILPValues[Root->NodeNum] = initILP(Root); DFS.follow(Root); for (;;) { // Traverse the leftmost path as far as possible. while (DFS.getPred() != DFS.getPredEnd()) { const SUnit *PredSU = DFS.getPred()->getSUnit(); DFS.advance(); // If the pred is already valid, skip it. if (ILPValues[PredSU->NodeNum].isValid()) continue; ILPValues[PredSU->NodeNum] = initILP(PredSU); DFS.follow(PredSU); } // Visit the top of the stack in postorder and backtrack. unsigned PredCount = ILPValues[DFS.getCurr()->NodeNum].InstrCount; DFS.backtrack(); if (DFS.isComplete()) break; // Add the recently finished predecessor's bottom-up descendent count. ILPValues[DFS.getCurr()->NodeNum].InstrCount += PredCount; } }
/// Compute an ILP metric for all nodes in the subDAG reachable via depth-first /// search from this root. void SchedDFSResult::compute(ArrayRef<SUnit *> Roots) { if (!IsBottomUp) llvm_unreachable("Top-down ILP metric is unimplemnted"); SchedDFSImpl Impl(*this); for (ArrayRef<const SUnit*>::const_iterator RootI = Roots.begin(), RootE = Roots.end(); RootI != RootE; ++RootI) { SchedDAGReverseDFS DFS; Impl.visitPreorder(*RootI); DFS.follow(*RootI); for (;;) { // Traverse the leftmost path as far as possible. while (DFS.getPred() != DFS.getPredEnd()) { const SDep &PredDep = *DFS.getPred(); DFS.advance(); // If the pred is already valid, skip it. We may preorder visit a node // with InstrCount==0 more than once, but it won't affect heuristics // because we don't care about cross edges to leaf copies. if (Impl.isVisited(PredDep.getSUnit())) { Impl.visitCross(PredDep, DFS.getCurr()); continue; } Impl.visitPreorder(PredDep.getSUnit()); DFS.follow(PredDep.getSUnit()); } // Visit the top of the stack in postorder and backtrack. const SUnit *Child = DFS.getCurr(); const SDep *PredDep = DFS.backtrack(); Impl.visitPostorder(Child, PredDep, PredDep ? DFS.getCurr() : 0); if (DFS.isComplete()) break; } } Impl.finalize(); }