-namespace {
-
-/// SUnit - Scheduling unit. It's an wrapper around either a single SDNode or a
-/// group of nodes flagged together.
-struct SUnit {
- SDNode *Node; // Representative node.
- std::vector<SDNode*> FlaggedNodes; // All nodes flagged to Node.
- std::vector<SDNode*> Preds; // All real predecessors.
- std::vector<SDNode*> ChainPreds; // All chain predecessors.
- std::vector<SDNode*> Succs; // All real successors.
- std::vector<SDNode*> ChainSuccs; // All chain successors.
- int NumPredsLeft; // # of preds not scheduled.
- int NumSuccsLeft; // # of succs not scheduled.
- int Priority1; // Scheduling priority 1.
- int Priority2; // Scheduling priority 2.
- unsigned Latency; // Node latency.
- unsigned CycleBound; // Upper/lower cycle to be scheduled at.
- unsigned Slot; // Cycle node is scheduled at.
-
- SUnit(SDNode *node)
- : Node(node), NumPredsLeft(0), NumSuccsLeft(0),
- Priority1(INT_MIN), Priority2(INT_MIN), Latency(0),
- CycleBound(0), Slot(0) {}
-
- void dump(const SelectionDAG *G, bool All=true) const;
-};
-
-void SUnit::dump(const SelectionDAG *G, bool All) const {
- std::cerr << "SU: ";
- Node->dump(G);
- std::cerr << "\n";
- if (All) {
- std::cerr << "# preds left : " << NumPredsLeft << "\n";
- std::cerr << "# succs left : " << NumSuccsLeft << "\n";
- std::cerr << "Latency : " << Latency << "\n";
- std::cerr << "Priority : " << Priority1 << " , " << Priority2 << "\n";
- }
-
- if (FlaggedNodes.size() != 0) {
- if (All)
- std::cerr << "Flagged nodes :\n";
- for (unsigned i = 0, e = FlaggedNodes.size(); i != e; i++) {
- std::cerr << " ";
- FlaggedNodes[i]->dump(G);
- std::cerr << "\n";
- }
- }
-
- if (All) {
- if (Preds.size() != 0) {
- std::cerr << "Predecessors :\n";
- for (unsigned i = 0, e = Preds.size(); i != e; i++) {
- std::cerr << " ";
- Preds[i]->dump(G);
- std::cerr << "\n";
- }
- }
- if (ChainPreds.size() != 0) {
- std::cerr << "Chained Preds :\n";
- for (unsigned i = 0, e = ChainPreds.size(); i != e; i++) {
- std::cerr << " ";
- ChainPreds[i]->dump(G);
- std::cerr << "\n";
- }
- }
- if (Succs.size() != 0) {
- std::cerr << "Successors :\n";
- for (unsigned i = 0, e = Succs.size(); i != e; i++) {
- std::cerr << " ";
- Succs[i]->dump(G);
- std::cerr << "\n";
- }
- }
- if (ChainSuccs.size() != 0) {
- std::cerr << "Chained succs :\n";
- for (unsigned i = 0, e = ChainSuccs.size(); i != e; i++) {
- std::cerr << " ";
- ChainSuccs[i]->dump(G);
- std::cerr << "\n";
- }
- }
- }
-}
-
-/// Sorting functions for the Available queue.
-struct ls_rr_sort : public std::binary_function<SUnit*, SUnit*, bool> {
- bool operator()(const SUnit* left, const SUnit* right) const {
- if (left->Priority1 > right->Priority1) {
- return true;
- } else if (left->Priority1 == right->Priority1) {
- unsigned lf = left->FlaggedNodes.size();
- unsigned rf = right->FlaggedNodes.size();
- if (lf > rf)
- return true;
- else if (lf == rf) {
- if (left->Priority2 > right->Priority2)
- return true;
- else if (left->Priority2 == right->Priority2) {
- if (left->CycleBound > right->CycleBound)
- return true;
- else
- return left->Node->getNodeDepth() < right->Node->getNodeDepth();
- }
- }
- }
-
- return false;
- }
-};