Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
4.3 KiB

  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. 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. ~ResourcePriorityQueue() {
  66. delete ResourcesModel;
  67. }
  68. bool isBottomUp() const { return false; }
  69. void initNodes(std::vector<SUnit> &sunits);
  70. void addNode(const SUnit *SU) {
  71. NumNodesSolelyBlocking.resize(SUnits->size(), 0);
  72. }
  73. void updateNode(const SUnit *SU) {}
  74. void releaseState() {
  75. SUnits = 0;
  76. }
  77. unsigned getLatency(unsigned NodeNum) const {
  78. assert(NodeNum < (*SUnits).size());
  79. return (*SUnits)[NodeNum].getHeight();
  80. }
  81. unsigned getNumSolelyBlockNodes(unsigned NodeNum) const {
  82. assert(NodeNum < NumNodesSolelyBlocking.size());
  83. return NumNodesSolelyBlocking[NodeNum];
  84. }
  85. /// Single cost function reflecting benefit of scheduling SU
  86. /// in the current cycle.
  87. signed SUSchedulingCost (SUnit *SU);
  88. /// InitNumRegDefsLeft - Determine the # of regs defined by this node.
  89. ///
  90. void initNumRegDefsLeft(SUnit *SU);
  91. void updateNumRegDefsLeft(SUnit *SU);
  92. signed regPressureDelta(SUnit *SU, bool RawPressure = false);
  93. signed rawRegPressureDelta (SUnit *SU, unsigned RCId);
  94. bool empty() const { return Queue.empty(); }
  95. virtual void push(SUnit *U);
  96. virtual SUnit *pop();
  97. virtual void remove(SUnit *SU);
  98. virtual void dump(ScheduleDAG* DAG) const;
  99. /// scheduledNode - Main resource tracking point.
  100. void scheduledNode(SUnit *Node);
  101. bool isResourceAvailable(SUnit *SU);
  102. void reserveResources(SUnit *SU);
  103. private:
  104. void adjustPriorityOfUnscheduledPreds(SUnit *SU);
  105. SUnit *getSingleUnscheduledPred(SUnit *SU);
  106. unsigned numberRCValPredInSU (SUnit *SU, unsigned RCId);
  107. unsigned numberRCValSuccInSU (SUnit *SU, unsigned RCId);
  108. };
  109. }
  110. #endif