ResourcePriorityQueue.h 4.2 KB

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