RegAllocPriorityAdvisor.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //===- RegAllocPriorityAdvisor.h - live ranges priority advisor -*- C++ -*-===//
  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. #ifndef LLVM_CODEGEN_REGALLOCPRIORITYADVISOR_H
  9. #define LLVM_CODEGEN_REGALLOCPRIORITYADVISOR_H
  10. #include "RegAllocEvictionAdvisor.h"
  11. #include "llvm/CodeGen/SlotIndexes.h"
  12. #include "llvm/Pass.h"
  13. namespace llvm {
  14. class MachineFunction;
  15. class VirtRegMap;
  16. class RAGreedy;
  17. /// Interface to the priority advisor, which is responsible for prioritizing
  18. /// live ranges.
  19. class RegAllocPriorityAdvisor {
  20. public:
  21. RegAllocPriorityAdvisor(const RegAllocPriorityAdvisor &) = delete;
  22. RegAllocPriorityAdvisor(RegAllocPriorityAdvisor &&) = delete;
  23. virtual ~RegAllocPriorityAdvisor() = default;
  24. /// Find the priority value for a live range. A float value is used since ML
  25. /// prefers it.
  26. virtual unsigned getPriority(const LiveInterval &LI) const = 0;
  27. RegAllocPriorityAdvisor(const MachineFunction &MF, const RAGreedy &RA,
  28. SlotIndexes *const Indexes);
  29. protected:
  30. const RAGreedy &RA;
  31. LiveIntervals *const LIS;
  32. VirtRegMap *const VRM;
  33. MachineRegisterInfo *const MRI;
  34. const TargetRegisterInfo *const TRI;
  35. const RegisterClassInfo &RegClassInfo;
  36. SlotIndexes *const Indexes;
  37. const bool RegClassPriorityTrumpsGlobalness;
  38. const bool ReverseLocalAssignment;
  39. };
  40. class DefaultPriorityAdvisor : public RegAllocPriorityAdvisor {
  41. public:
  42. DefaultPriorityAdvisor(const MachineFunction &MF, const RAGreedy &RA,
  43. SlotIndexes *const Indexes)
  44. : RegAllocPriorityAdvisor(MF, RA, Indexes) {}
  45. private:
  46. unsigned getPriority(const LiveInterval &LI) const override;
  47. };
  48. class RegAllocPriorityAdvisorAnalysis : public ImmutablePass {
  49. public:
  50. enum class AdvisorMode : int { Default, Release, Development };
  51. RegAllocPriorityAdvisorAnalysis(AdvisorMode Mode)
  52. : ImmutablePass(ID), Mode(Mode){};
  53. static char ID;
  54. /// Get an advisor for the given context (i.e. machine function, etc)
  55. virtual std::unique_ptr<RegAllocPriorityAdvisor>
  56. getAdvisor(const MachineFunction &MF, const RAGreedy &RA) = 0;
  57. AdvisorMode getAdvisorMode() const { return Mode; }
  58. virtual void logRewardIfNeeded(const MachineFunction &MF,
  59. llvm::function_ref<float()> GetReward){};
  60. protected:
  61. // This analysis preserves everything, and subclasses may have additional
  62. // requirements.
  63. void getAnalysisUsage(AnalysisUsage &AU) const override {
  64. AU.setPreservesAll();
  65. }
  66. private:
  67. StringRef getPassName() const override;
  68. const AdvisorMode Mode;
  69. };
  70. /// Specialization for the API used by the analysis infrastructure to create
  71. /// an instance of the priority advisor.
  72. template <> Pass *callDefaultCtor<RegAllocPriorityAdvisorAnalysis>();
  73. RegAllocPriorityAdvisorAnalysis *createReleaseModePriorityAdvisor();
  74. RegAllocPriorityAdvisorAnalysis *createDevelopmentModePriorityAdvisor();
  75. } // namespace llvm
  76. #endif // LLVM_CODEGEN_REGALLOCPRIORITYADVISOR_H