ResourcePriorityQueue.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //===----- ResourcePriorityQueue.h - A DFA-oriented priority queue -------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the ResourcePriorityQueue class, which is a
  11. // SchedulingPriorityQueue that schedules using DFA state to
  12. // reduce the length of the critical path through the basic block
  13. // on VLIW platforms.
  14. //
  15. //===----------------------------------------------------------------------===//
  16. #ifndef LLVM_CODEGEN_RESOURCEPRIORITYQUEUE_H
  17. #define LLVM_CODEGEN_RESOURCEPRIORITYQUEUE_H
  18. #include "llvm/CodeGen/DFAPacketizer.h"
  19. #include "llvm/CodeGen/ScheduleDAG.h"
  20. #include "llvm/CodeGen/SelectionDAGISel.h"
  21. #include "llvm/MC/MCInstrItineraries.h"
  22. #include "llvm/Target/TargetInstrInfo.h"
  23. #include "llvm/Target/TargetRegisterInfo.h"
  24. namespace llvm {
  25. class ResourcePriorityQueue;
  26. /// Sorting functions for the Available queue.
  27. struct resource_sort : public std::binary_function<SUnit*, SUnit*, bool> {
  28. ResourcePriorityQueue *PQ;
  29. explicit resource_sort(ResourcePriorityQueue *pq) : PQ(pq) {}
  30. bool operator()(const SUnit* left, const SUnit* right) const;
  31. };
  32. class ResourcePriorityQueue : public SchedulingPriorityQueue {
  33. /// SUnits - The SUnits for the current graph.
  34. std::vector<SUnit> *SUnits;
  35. /// NumNodesSolelyBlocking - This vector contains, for every node in the
  36. /// Queue, the number of nodes that the node is the sole unscheduled
  37. /// predecessor for. This is used as a tie-breaker heuristic for better
  38. /// mobility.
  39. std::vector<unsigned> NumNodesSolelyBlocking;
  40. /// Queue - The queue.
  41. std::vector<SUnit*> Queue;
  42. /// RegPressure - Tracking current reg pressure per register class.
  43. ///
  44. std::vector<unsigned> RegPressure;
  45. /// RegLimit - Tracking the number of allocatable registers per register
  46. /// class.
  47. std::vector<unsigned> RegLimit;
  48. resource_sort Picker;
  49. const TargetRegisterInfo *TRI;
  50. const TargetLowering *TLI;
  51. const TargetInstrInfo *TII;
  52. const InstrItineraryData* InstrItins;
  53. /// ResourcesModel - Represents VLIW state.
  54. /// Not limited to VLIW targets per say, but assumes
  55. /// definition of DFA by a target.
  56. std::unique_ptr<DFAPacketizer> ResourcesModel;
  57. /// Resource model - packet/bundle model. Purely
  58. /// internal at the time.
  59. std::vector<SUnit*> Packet;
  60. /// Heuristics for estimating register pressure.
  61. unsigned ParallelLiveRanges;
  62. signed HorizontalVerticalBalance;
  63. public:
  64. ResourcePriorityQueue(SelectionDAGISel *IS);
  65. bool isBottomUp() const override { return false; }
  66. void initNodes(std::vector<SUnit> &sunits) override;
  67. void addNode(const SUnit *SU) override {
  68. NumNodesSolelyBlocking.resize(SUnits->size(), 0);
  69. }
  70. void updateNode(const SUnit *SU) override {}
  71. void releaseState() override {
  72. SUnits = nullptr;
  73. }
  74. unsigned getLatency(unsigned NodeNum) const {
  75. assert(NodeNum < (*SUnits).size());
  76. return (*SUnits)[NodeNum].getHeight();
  77. }
  78. unsigned getNumSolelyBlockNodes(unsigned NodeNum) const {
  79. assert(NodeNum < NumNodesSolelyBlocking.size());
  80. return NumNodesSolelyBlocking[NodeNum];
  81. }
  82. /// Single cost function reflecting benefit of scheduling SU
  83. /// in the current cycle.
  84. signed SUSchedulingCost (SUnit *SU);
  85. /// InitNumRegDefsLeft - Determine the # of regs defined by this node.
  86. ///
  87. void initNumRegDefsLeft(SUnit *SU);
  88. void updateNumRegDefsLeft(SUnit *SU);
  89. signed regPressureDelta(SUnit *SU, bool RawPressure = false);
  90. signed rawRegPressureDelta (SUnit *SU, unsigned RCId);
  91. bool empty() const override { return Queue.empty(); }
  92. void push(SUnit *U) override;
  93. SUnit *pop() override;
  94. void remove(SUnit *SU) override;
  95. /// scheduledNode - Main resource tracking point.
  96. void scheduledNode(SUnit *Node) override;
  97. bool isResourceAvailable(SUnit *SU);
  98. void reserveResources(SUnit *SU);
  99. private:
  100. void adjustPriorityOfUnscheduledPreds(SUnit *SU);
  101. SUnit *getSingleUnscheduledPred(SUnit *SU);
  102. unsigned numberRCValPredInSU (SUnit *SU, unsigned RCId);
  103. unsigned numberRCValSuccInSU (SUnit *SU, unsigned RCId);
  104. };
  105. }
  106. #endif