LLVM API Documentation

LatencyPriorityQueue.h

Go to the documentation of this file.
00001 //===---- LatencyPriorityQueue.h - A latency-oriented priority queue ------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares the LatencyPriorityQueue class, which is a
00011 // SchedulingPriorityQueue that schedules using latency information to
00012 // reduce the length of the critical path through the basic block.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LATENCY_PRIORITY_QUEUE_H
00017 #define LATENCY_PRIORITY_QUEUE_H
00018 
00019 #include "llvm/CodeGen/ScheduleDAG.h"
00020 #include "llvm/ADT/PriorityQueue.h"
00021 
00022 namespace llvm {
00023   class LatencyPriorityQueue;
00024   
00025   /// Sorting functions for the Available queue.
00026   struct latency_sort : public std::binary_function<SUnit*, SUnit*, bool> {
00027     LatencyPriorityQueue *PQ;
00028     explicit latency_sort(LatencyPriorityQueue *pq) : PQ(pq) {}
00029     
00030     bool operator()(const SUnit* left, const SUnit* right) const;
00031   };
00032 
00033   class LatencyPriorityQueue : public SchedulingPriorityQueue {
00034     // SUnits - The SUnits for the current graph.
00035     std::vector<SUnit> *SUnits;
00036     
00037     /// NumNodesSolelyBlocking - This vector contains, for every node in the
00038     /// Queue, the number of nodes that the node is the sole unscheduled
00039     /// predecessor for.  This is used as a tie-breaker heuristic for better
00040     /// mobility.
00041     std::vector<unsigned> NumNodesSolelyBlocking;
00042 
00043     PriorityQueue<SUnit*, std::vector<SUnit*>, latency_sort> Queue;
00044 public:
00045     LatencyPriorityQueue() : Queue(latency_sort(this)) {
00046     }
00047     
00048     void initNodes(std::vector<SUnit> &sunits) {
00049       SUnits = &sunits;
00050       NumNodesSolelyBlocking.resize(SUnits->size(), 0);
00051     }
00052 
00053     void addNode(const SUnit *SU) {
00054       NumNodesSolelyBlocking.resize(SUnits->size(), 0);
00055     }
00056 
00057     void updateNode(const SUnit *SU) {
00058     }
00059 
00060     void releaseState() {
00061       SUnits = 0;
00062     }
00063     
00064     unsigned getLatency(unsigned NodeNum) const {
00065       assert(NodeNum < (*SUnits).size());
00066       return (*SUnits)[NodeNum].getHeight();
00067     }
00068     
00069     unsigned getNumSolelyBlockNodes(unsigned NodeNum) const {
00070       assert(NodeNum < NumNodesSolelyBlocking.size());
00071       return NumNodesSolelyBlocking[NodeNum];
00072     }
00073     
00074     unsigned size() const { return Queue.size(); }
00075 
00076     bool empty() const { return Queue.empty(); }
00077     
00078     virtual void push(SUnit *U) {
00079       push_impl(U);
00080     }
00081     void push_impl(SUnit *U);
00082     
00083     void push_all(const std::vector<SUnit *> &Nodes) {
00084       for (unsigned i = 0, e = Nodes.size(); i != e; ++i)
00085         push_impl(Nodes[i]);
00086     }
00087     
00088     SUnit *pop() {
00089       if (empty()) return NULL;
00090       SUnit *V = Queue.top();
00091       Queue.pop();
00092       return V;
00093     }
00094 
00095     void remove(SUnit *SU) {
00096       assert(!Queue.empty() && "Not in queue!");
00097       Queue.erase_one(SU);
00098     }
00099 
00100     // ScheduledNode - As nodes are scheduled, we look to see if there are any
00101     // successor nodes that have a single unscheduled predecessor.  If so, that
00102     // single predecessor has a higher priority, since scheduling it will make
00103     // the node available.
00104     void ScheduledNode(SUnit *Node);
00105 
00106 private:
00107     void AdjustPriorityOfUnscheduledPreds(SUnit *SU);
00108     SUnit *getSingleUnscheduledPred(SUnit *SU);
00109   };
00110 }
00111 
00112 #endif