diff --git a/lib/CodeGen/SelectionDAG/ScheduleDAGList.cpp b/lib/CodeGen/SelectionDAG/ScheduleDAGList.cpp index ae7efef0a8c..d09622fd6bf 100644 --- a/lib/CodeGen/SelectionDAG/ScheduleDAGList.cpp +++ b/lib/CodeGen/SelectionDAG/ScheduleDAGList.cpp @@ -51,7 +51,6 @@ namespace { short NumSuccsLeft; // # of succs not scheduled. short NumChainPredsLeft; // # of chain preds not scheduled. short NumChainSuccsLeft; // # of chain succs not scheduled. - bool isStore : 1; // Is a store. bool isTwoAddress : 1; // Is a two-address instruction. bool isDefNUseOperand : 1; // Is a def&use operand. bool isPending : 1; // True once pending. @@ -64,7 +63,7 @@ namespace { SUnit(SDNode *node, unsigned nodenum) : Node(node), NumPredsLeft(0), NumSuccsLeft(0), - NumChainPredsLeft(0), NumChainSuccsLeft(0), isStore(false), + NumChainPredsLeft(0), NumChainSuccsLeft(0), isTwoAddress(false), isDefNUseOperand(false), isPending(false), isAvailable(false), isScheduled(false), Latency(0), CycleBound(0), Cycle(0), NodeNum(nodenum) {} @@ -316,13 +315,9 @@ void ScheduleDAGList::BuildSchedUnits() { SUnit *SU = &SUnits[su]; SDNode *MainNode = SU->Node; - if (MainNode->isTargetOpcode()) { - unsigned Opc = MainNode->getTargetOpcode(); - if (TII->isTwoAddrInstr(Opc)) - SU->isTwoAddress = true; - if (TII->isStore(Opc)) - SU->isStore = true; - } + if (MainNode->isTargetOpcode() && + TII->isTwoAddrInstr(MainNode->getTargetOpcode())) + SU->isTwoAddress = true; // Find all predecessors and successors of the group. // Temporarily add N to make code simpler. @@ -363,9 +358,9 @@ void ScheduleDAGList::BuildSchedUnits() { SU->FlaggedNodes.pop_back(); } + return; DEBUG(for (unsigned su = 0, e = SUnits.size(); su != e; ++su) SUnits[su].dumpAll(&DAG)); - return; } /// EmitSchedule - Emit the machine code in scheduled order. @@ -740,7 +735,7 @@ namespace { const std::vector *SUnits; // SethiUllmanNumbers - The SethiUllman number for each node. - std::vector SethiUllmanNumbers; + std::vector SethiUllmanNumbers; std::priority_queue, ls_rr_sort> Queue; public: @@ -779,7 +774,7 @@ namespace { } private: void CalculatePriorities(); - unsigned CalcNodePriority(const SUnit *SU); + int CalcNodePriority(const SUnit *SU); }; } @@ -789,7 +784,7 @@ bool ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const { int LBonus = (int)left ->isDefNUseOperand; int RBonus = (int)right->isDefNUseOperand; - + // Special tie breaker: if two nodes share a operand, the one that // use it as a def&use operand is preferred. if (left->isTwoAddress && !right->isTwoAddress) { @@ -803,20 +798,6 @@ bool ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const { RBonus++; } - // Push stores up as much as possible. This really help code like this: - // load - // compute - // store - // load - // compute - // store - // This would make sure the scheduled code completed all computations and - // the stores before the next series of computation starts. - if (!left->isStore && right->isStore) - LBonus += 2; - if (left->isStore && !right->isStore) - RBonus += 2; - // Priority1 is just the number of live range genned. int LPriority1 = left ->NumPredsLeft - LBonus; int RPriority1 = right->NumPredsLeft - RBonus; @@ -838,9 +819,9 @@ bool ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const { /// CalcNodePriority - Priority is the Sethi Ullman number. /// Smaller number is the higher priority. -unsigned RegReductionPriorityQueue::CalcNodePriority(const SUnit *SU) { - unsigned &SethiUllmanNumber = SethiUllmanNumbers[SU->NodeNum]; - if (SethiUllmanNumber != 0) +int RegReductionPriorityQueue::CalcNodePriority(const SUnit *SU) { + int &SethiUllmanNumber = SethiUllmanNumbers[SU->NodeNum]; + if (SethiUllmanNumber != INT_MIN) return SethiUllmanNumber; if (SU->Preds.size() == 0) { @@ -851,7 +832,7 @@ unsigned RegReductionPriorityQueue::CalcNodePriority(const SUnit *SU) { I = SU->Preds.begin(), E = SU->Preds.end(); I != E; ++I) { if (I->second) continue; // ignore chain preds. SUnit *PredSU = I->first; - unsigned PredSethiUllman = CalcNodePriority(PredSU); + int PredSethiUllman = CalcNodePriority(PredSU); if (PredSethiUllman > SethiUllmanNumber) { SethiUllmanNumber = PredSethiUllman; Extra = 0; @@ -859,7 +840,10 @@ unsigned RegReductionPriorityQueue::CalcNodePriority(const SUnit *SU) { Extra++; } - SethiUllmanNumber += Extra; + if (SU->Node->getOpcode() != ISD::TokenFactor) + SethiUllmanNumber += Extra; + else + SethiUllmanNumber = (Extra == 1) ? 0 : Extra-1; } return SethiUllmanNumber; @@ -867,7 +851,7 @@ unsigned RegReductionPriorityQueue::CalcNodePriority(const SUnit *SU) { /// CalculatePriorities - Calculate priorities of all scheduling units. void RegReductionPriorityQueue::CalculatePriorities() { - SethiUllmanNumbers.assign(SUnits->size(), 0); + SethiUllmanNumbers.assign(SUnits->size(), INT_MIN); for (unsigned i = 0, e = SUnits->size(); i != e; ++i) CalcNodePriority(&(*SUnits)[i]);