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