LatencyPriorityQueue.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===---- LatencyPriorityQueue.h - A latency-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 declares the LatencyPriorityQueue class, which is a
  15. // SchedulingPriorityQueue that schedules using latency information to
  16. // reduce the length of the critical path through the basic block.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_CODEGEN_LATENCYPRIORITYQUEUE_H
  20. #define LLVM_CODEGEN_LATENCYPRIORITYQUEUE_H
  21. #include "llvm/CodeGen/ScheduleDAG.h"
  22. #include "llvm/Config/llvm-config.h"
  23. namespace llvm {
  24. class LatencyPriorityQueue;
  25. /// Sorting functions for the Available queue.
  26. struct latency_sort {
  27. LatencyPriorityQueue *PQ;
  28. explicit latency_sort(LatencyPriorityQueue *pq) : PQ(pq) {}
  29. bool operator()(const SUnit* LHS, const SUnit* RHS) const;
  30. };
  31. class LatencyPriorityQueue : 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. latency_sort Picker;
  42. public:
  43. LatencyPriorityQueue() : Picker(this) {
  44. }
  45. bool isBottomUp() const override { return false; }
  46. void initNodes(std::vector<SUnit> &sunits) override {
  47. SUnits = &sunits;
  48. NumNodesSolelyBlocking.resize(SUnits->size(), 0);
  49. }
  50. void addNode(const SUnit *SU) override {
  51. NumNodesSolelyBlocking.resize(SUnits->size(), 0);
  52. }
  53. void updateNode(const SUnit *SU) override {
  54. }
  55. void releaseState() override {
  56. SUnits = nullptr;
  57. }
  58. unsigned getLatency(unsigned NodeNum) const {
  59. assert(NodeNum < (*SUnits).size());
  60. return (*SUnits)[NodeNum].getHeight();
  61. }
  62. unsigned getNumSolelyBlockNodes(unsigned NodeNum) const {
  63. assert(NodeNum < NumNodesSolelyBlocking.size());
  64. return NumNodesSolelyBlocking[NodeNum];
  65. }
  66. bool empty() const override { return Queue.empty(); }
  67. void push(SUnit *U) override;
  68. SUnit *pop() override;
  69. void remove(SUnit *SU) override;
  70. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  71. LLVM_DUMP_METHOD void dump(ScheduleDAG *DAG) const override;
  72. #endif
  73. // scheduledNode - As nodes are scheduled, we look to see if there are any
  74. // successor nodes that have a single unscheduled predecessor. If so, that
  75. // single predecessor has a higher priority, since scheduling it will make
  76. // the node available.
  77. void scheduledNode(SUnit *SU) override;
  78. private:
  79. void AdjustPriorityOfUnscheduledPreds(SUnit *SU);
  80. SUnit *getSingleUnscheduledPred(SUnit *SU);
  81. };
  82. }
  83. #endif
  84. #ifdef __GNUC__
  85. #pragma GCC diagnostic pop
  86. #endif