LatencyPriorityQueue.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //===---- LatencyPriorityQueue.h - A latency-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 declares the LatencyPriorityQueue class, which is a
  10. // SchedulingPriorityQueue that schedules using latency information to
  11. // reduce the length of the critical path through the basic block.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_CODEGEN_LATENCYPRIORITYQUEUE_H
  15. #define LLVM_CODEGEN_LATENCYPRIORITYQUEUE_H
  16. #include "llvm/CodeGen/ScheduleDAG.h"
  17. #include "llvm/Config/llvm-config.h"
  18. namespace llvm {
  19. class LatencyPriorityQueue;
  20. /// Sorting functions for the Available queue.
  21. struct latency_sort {
  22. LatencyPriorityQueue *PQ;
  23. explicit latency_sort(LatencyPriorityQueue *pq) : PQ(pq) {}
  24. bool operator()(const SUnit* LHS, const SUnit* RHS) const;
  25. };
  26. class LatencyPriorityQueue : public SchedulingPriorityQueue {
  27. // SUnits - The SUnits for the current graph.
  28. std::vector<SUnit> *SUnits;
  29. /// NumNodesSolelyBlocking - This vector contains, for every node in the
  30. /// Queue, the number of nodes that the node is the sole unscheduled
  31. /// predecessor for. This is used as a tie-breaker heuristic for better
  32. /// mobility.
  33. std::vector<unsigned> NumNodesSolelyBlocking;
  34. /// Queue - The queue.
  35. std::vector<SUnit*> Queue;
  36. latency_sort Picker;
  37. public:
  38. LatencyPriorityQueue() : Picker(this) {
  39. }
  40. bool isBottomUp() const override { return false; }
  41. void initNodes(std::vector<SUnit> &sunits) override {
  42. SUnits = &sunits;
  43. NumNodesSolelyBlocking.resize(SUnits->size(), 0);
  44. }
  45. void addNode(const SUnit *SU) override {
  46. NumNodesSolelyBlocking.resize(SUnits->size(), 0);
  47. }
  48. void updateNode(const SUnit *SU) override {
  49. }
  50. void releaseState() override {
  51. SUnits = nullptr;
  52. }
  53. unsigned getLatency(unsigned NodeNum) const {
  54. assert(NodeNum < (*SUnits).size());
  55. return (*SUnits)[NodeNum].getHeight();
  56. }
  57. unsigned getNumSolelyBlockNodes(unsigned NodeNum) const {
  58. assert(NodeNum < NumNodesSolelyBlocking.size());
  59. return NumNodesSolelyBlocking[NodeNum];
  60. }
  61. bool empty() const override { return Queue.empty(); }
  62. void push(SUnit *U) override;
  63. SUnit *pop() override;
  64. void remove(SUnit *SU) override;
  65. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  66. LLVM_DUMP_METHOD void dump(ScheduleDAG *DAG) const override;
  67. #endif
  68. // scheduledNode - As nodes are scheduled, we look to see if there are any
  69. // successor nodes that have a single unscheduled predecessor. If so, that
  70. // single predecessor has a higher priority, since scheduling it will make
  71. // the node available.
  72. void scheduledNode(SUnit *SU) override;
  73. private:
  74. void AdjustPriorityOfUnscheduledPreds(SUnit *SU);
  75. SUnit *getSingleUnscheduledPred(SUnit *SU);
  76. };
  77. }
  78. #endif