ResourcePriorityQueue.h 4.3 KB

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