1*bdd1243dSDimitry Andric //===- RegAllocPriorityAdvisor.h - live ranges priority advisor -*- C++ -*-===// 2*bdd1243dSDimitry Andric // 3*bdd1243dSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*bdd1243dSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*bdd1243dSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*bdd1243dSDimitry Andric // 7*bdd1243dSDimitry Andric //===----------------------------------------------------------------------===// 8*bdd1243dSDimitry Andric 9*bdd1243dSDimitry Andric #ifndef LLVM_CODEGEN_REGALLOCPRIORITYADVISOR_H 10*bdd1243dSDimitry Andric #define LLVM_CODEGEN_REGALLOCPRIORITYADVISOR_H 11*bdd1243dSDimitry Andric 12*bdd1243dSDimitry Andric #include "RegAllocEvictionAdvisor.h" 13*bdd1243dSDimitry Andric #include "llvm/CodeGen/SlotIndexes.h" 14*bdd1243dSDimitry Andric #include "llvm/Pass.h" 15*bdd1243dSDimitry Andric 16*bdd1243dSDimitry Andric namespace llvm { 17*bdd1243dSDimitry Andric 18*bdd1243dSDimitry Andric class MachineFunction; 19*bdd1243dSDimitry Andric class VirtRegMap; 20*bdd1243dSDimitry Andric class RAGreedy; 21*bdd1243dSDimitry Andric 22*bdd1243dSDimitry Andric /// Interface to the priority advisor, which is responsible for prioritizing 23*bdd1243dSDimitry Andric /// live ranges. 24*bdd1243dSDimitry Andric class RegAllocPriorityAdvisor { 25*bdd1243dSDimitry Andric public: 26*bdd1243dSDimitry Andric RegAllocPriorityAdvisor(const RegAllocPriorityAdvisor &) = delete; 27*bdd1243dSDimitry Andric RegAllocPriorityAdvisor(RegAllocPriorityAdvisor &&) = delete; 28*bdd1243dSDimitry Andric virtual ~RegAllocPriorityAdvisor() = default; 29*bdd1243dSDimitry Andric 30*bdd1243dSDimitry Andric /// Find the priority value for a live range. A float value is used since ML 31*bdd1243dSDimitry Andric /// prefers it. 32*bdd1243dSDimitry Andric virtual unsigned getPriority(const LiveInterval &LI) const = 0; 33*bdd1243dSDimitry Andric 34*bdd1243dSDimitry Andric RegAllocPriorityAdvisor(const MachineFunction &MF, const RAGreedy &RA, 35*bdd1243dSDimitry Andric SlotIndexes *const Indexes); 36*bdd1243dSDimitry Andric 37*bdd1243dSDimitry Andric protected: 38*bdd1243dSDimitry Andric const RAGreedy &RA; 39*bdd1243dSDimitry Andric LiveIntervals *const LIS; 40*bdd1243dSDimitry Andric VirtRegMap *const VRM; 41*bdd1243dSDimitry Andric MachineRegisterInfo *const MRI; 42*bdd1243dSDimitry Andric const TargetRegisterInfo *const TRI; 43*bdd1243dSDimitry Andric const RegisterClassInfo &RegClassInfo; 44*bdd1243dSDimitry Andric SlotIndexes *const Indexes; 45*bdd1243dSDimitry Andric const bool RegClassPriorityTrumpsGlobalness; 46*bdd1243dSDimitry Andric const bool ReverseLocalAssignment; 47*bdd1243dSDimitry Andric }; 48*bdd1243dSDimitry Andric 49*bdd1243dSDimitry Andric class DefaultPriorityAdvisor : public RegAllocPriorityAdvisor { 50*bdd1243dSDimitry Andric public: DefaultPriorityAdvisor(const MachineFunction & MF,const RAGreedy & RA,SlotIndexes * const Indexes)51*bdd1243dSDimitry Andric DefaultPriorityAdvisor(const MachineFunction &MF, const RAGreedy &RA, 52*bdd1243dSDimitry Andric SlotIndexes *const Indexes) 53*bdd1243dSDimitry Andric : RegAllocPriorityAdvisor(MF, RA, Indexes) {} 54*bdd1243dSDimitry Andric 55*bdd1243dSDimitry Andric private: 56*bdd1243dSDimitry Andric unsigned getPriority(const LiveInterval &LI) const override; 57*bdd1243dSDimitry Andric }; 58*bdd1243dSDimitry Andric 59*bdd1243dSDimitry Andric class RegAllocPriorityAdvisorAnalysis : public ImmutablePass { 60*bdd1243dSDimitry Andric public: 61*bdd1243dSDimitry Andric enum class AdvisorMode : int { Default, Release, Development }; 62*bdd1243dSDimitry Andric RegAllocPriorityAdvisorAnalysis(AdvisorMode Mode)63*bdd1243dSDimitry Andric RegAllocPriorityAdvisorAnalysis(AdvisorMode Mode) 64*bdd1243dSDimitry Andric : ImmutablePass(ID), Mode(Mode){}; 65*bdd1243dSDimitry Andric static char ID; 66*bdd1243dSDimitry Andric 67*bdd1243dSDimitry Andric /// Get an advisor for the given context (i.e. machine function, etc) 68*bdd1243dSDimitry Andric virtual std::unique_ptr<RegAllocPriorityAdvisor> 69*bdd1243dSDimitry Andric getAdvisor(const MachineFunction &MF, const RAGreedy &RA) = 0; getAdvisorMode()70*bdd1243dSDimitry Andric AdvisorMode getAdvisorMode() const { return Mode; } logRewardIfNeeded(const MachineFunction & MF,llvm::function_ref<float ()> GetReward)71*bdd1243dSDimitry Andric virtual void logRewardIfNeeded(const MachineFunction &MF, 72*bdd1243dSDimitry Andric llvm::function_ref<float()> GetReward){}; 73*bdd1243dSDimitry Andric 74*bdd1243dSDimitry Andric protected: 75*bdd1243dSDimitry Andric // This analysis preserves everything, and subclasses may have additional 76*bdd1243dSDimitry Andric // requirements. getAnalysisUsage(AnalysisUsage & AU)77*bdd1243dSDimitry Andric void getAnalysisUsage(AnalysisUsage &AU) const override { 78*bdd1243dSDimitry Andric AU.setPreservesAll(); 79*bdd1243dSDimitry Andric } 80*bdd1243dSDimitry Andric 81*bdd1243dSDimitry Andric private: 82*bdd1243dSDimitry Andric StringRef getPassName() const override; 83*bdd1243dSDimitry Andric const AdvisorMode Mode; 84*bdd1243dSDimitry Andric }; 85*bdd1243dSDimitry Andric 86*bdd1243dSDimitry Andric /// Specialization for the API used by the analysis infrastructure to create 87*bdd1243dSDimitry Andric /// an instance of the priority advisor. 88*bdd1243dSDimitry Andric template <> Pass *callDefaultCtor<RegAllocPriorityAdvisorAnalysis>(); 89*bdd1243dSDimitry Andric 90*bdd1243dSDimitry Andric RegAllocPriorityAdvisorAnalysis *createReleaseModePriorityAdvisor(); 91*bdd1243dSDimitry Andric 92*bdd1243dSDimitry Andric RegAllocPriorityAdvisorAnalysis *createDevelopmentModePriorityAdvisor(); 93*bdd1243dSDimitry Andric 94*bdd1243dSDimitry Andric } // namespace llvm 95*bdd1243dSDimitry Andric 96*bdd1243dSDimitry Andric #endif // LLVM_CODEGEN_REGALLOCPRIORITYADVISOR_H 97