2008-11-15 00:23:40 +00:00
|
|
|
//===---- LatencyPriorityQueue.h - A latency-oriented priority queue ------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the LatencyPriorityQueue class, which is a
|
|
|
|
// SchedulingPriorityQueue that schedules using latency information to
|
|
|
|
// reduce the length of the critical path through the basic block.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LATENCY_PRIORITY_QUEUE_H
|
|
|
|
#define LATENCY_PRIORITY_QUEUE_H
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/ScheduleDAG.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class LatencyPriorityQueue;
|
|
|
|
|
|
|
|
/// Sorting functions for the Available queue.
|
|
|
|
struct latency_sort : public std::binary_function<SUnit*, SUnit*, bool> {
|
|
|
|
LatencyPriorityQueue *PQ;
|
|
|
|
explicit latency_sort(LatencyPriorityQueue *pq) : PQ(pq) {}
|
|
|
|
|
|
|
|
bool operator()(const SUnit* left, const SUnit* right) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LatencyPriorityQueue : public SchedulingPriorityQueue {
|
|
|
|
// SUnits - The SUnits for the current graph.
|
|
|
|
std::vector<SUnit> *SUnits;
|
|
|
|
|
|
|
|
/// NumNodesSolelyBlocking - This vector contains, for every node in the
|
|
|
|
/// Queue, the number of nodes that the node is the sole unscheduled
|
|
|
|
/// predecessor for. This is used as a tie-breaker heuristic for better
|
|
|
|
/// mobility.
|
|
|
|
std::vector<unsigned> NumNodesSolelyBlocking;
|
2009-11-03 20:57:50 +00:00
|
|
|
|
|
|
|
/// Queue - The queue.
|
2010-05-26 18:52:00 +00:00
|
|
|
std::vector<SUnit*> Queue;
|
|
|
|
latency_sort Picker;
|
2009-11-03 20:57:50 +00:00
|
|
|
|
2010-05-26 18:37:48 +00:00
|
|
|
public:
|
2010-05-26 18:52:00 +00:00
|
|
|
LatencyPriorityQueue() : Picker(this) {
|
2009-11-03 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
2008-11-15 00:23:40 +00:00
|
|
|
void initNodes(std::vector<SUnit> &sunits) {
|
|
|
|
SUnits = &sunits;
|
2008-12-16 03:25:46 +00:00
|
|
|
NumNodesSolelyBlocking.resize(SUnits->size(), 0);
|
2008-11-15 00:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void addNode(const SUnit *SU) {
|
|
|
|
NumNodesSolelyBlocking.resize(SUnits->size(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateNode(const SUnit *SU) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void releaseState() {
|
|
|
|
SUnits = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getLatency(unsigned NodeNum) const {
|
2008-12-16 03:25:46 +00:00
|
|
|
assert(NodeNum < (*SUnits).size());
|
2009-11-20 19:32:48 +00:00
|
|
|
return (*SUnits)[NodeNum].getHeight();
|
2008-11-15 00:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getNumSolelyBlockNodes(unsigned NodeNum) const {
|
|
|
|
assert(NodeNum < NumNodesSolelyBlocking.size());
|
|
|
|
return NumNodesSolelyBlocking[NodeNum];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool empty() const { return Queue.empty(); }
|
|
|
|
|
2010-05-26 01:10:55 +00:00
|
|
|
virtual void push(SUnit *U);
|
2008-11-15 00:23:40 +00:00
|
|
|
|
2010-05-26 18:52:00 +00:00
|
|
|
virtual SUnit *pop();
|
2008-11-15 00:23:40 +00:00
|
|
|
|
2010-05-26 18:52:00 +00:00
|
|
|
virtual void remove(SUnit *SU);
|
2008-11-15 00:23:40 +00:00
|
|
|
|
|
|
|
// ScheduledNode - As nodes are scheduled, we look to see if there are any
|
|
|
|
// successor nodes that have a single unscheduled predecessor. If so, that
|
|
|
|
// single predecessor has a higher priority, since scheduling it will make
|
|
|
|
// the node available.
|
|
|
|
void ScheduledNode(SUnit *Node);
|
|
|
|
|
2008-11-19 23:18:57 +00:00
|
|
|
private:
|
2008-11-15 00:23:40 +00:00
|
|
|
void AdjustPriorityOfUnscheduledPreds(SUnit *SU);
|
|
|
|
SUnit *getSingleUnscheduledPred(SUnit *SU);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|