LLVM 22.0.0git
RegAllocPriorityAdvisor.h
Go to the documentation of this file.
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
9#ifndef LLVM_CODEGEN_REGALLOCPRIORITYADVISOR_H
10#define LLVM_CODEGEN_REGALLOCPRIORITYADVISOR_H
11
15#include "llvm/IR/PassManager.h"
16#include "llvm/Pass.h"
17
18namespace llvm {
19
20class MachineFunction;
21class VirtRegMap;
22class RAGreedy;
23
24/// Interface to the priority advisor, which is responsible for prioritizing
25/// live ranges.
27public:
30 virtual ~RegAllocPriorityAdvisor() = default;
31
32 /// Find the priority value for a live range. A float value is used since ML
33 /// prefers it.
34 virtual unsigned getPriority(const LiveInterval &LI) const = 0;
35
37 SlotIndexes *const Indexes);
38
39protected:
40 const RAGreedy &RA;
44 const TargetRegisterInfo *const TRI;
49};
50
52public:
54 SlotIndexes *const Indexes)
56
57private:
58 unsigned getPriority(const LiveInterval &LI) const override;
59};
60
61/// Stupid priority advisor which just enqueues in virtual register number
62/// order, for debug purposes only.
64public:
66 SlotIndexes *const Indexes)
68
69private:
70 unsigned getPriority(const LiveInterval &LI) const override;
71};
72
73/// Common provider for getting the priority advisor and logging rewards.
74/// Legacy analysis forwards all calls to this provider.
75/// New analysis serves the provider as the analysis result.
76/// Expensive setup is done in the constructor, so that the advisor can be
77/// created quickly for every machine function.
78/// TODO: Remove once legacy PM support is dropped.
80public:
81 enum class AdvisorMode : int { Default, Release, Development, Dummy };
82
84
86
87 virtual void logRewardIfNeeded(const MachineFunction &MF,
88 function_ref<float()> GetReward) {};
89
90 virtual std::unique_ptr<RegAllocPriorityAdvisor>
92 SlotIndexes &SI) = 0;
93
94 AdvisorMode getAdvisorMode() const { return Mode; }
95
96private:
97 const AdvisorMode Mode;
98};
99
101 : public AnalysisInfoMixin<RegAllocPriorityAdvisorAnalysis> {
102 static AnalysisKey Key;
104
105public:
106 struct Result {
107 // Owned by this analysis.
109
113 return !PAC.preservedWhenStateless() ||
114 Inv.invalidate<SlotIndexesAnalysis>(MF, PA);
115 }
116 };
117
119
120private:
121 void initializeProvider(LLVMContext &Ctx);
122 void initializeMLProvider(RegAllocPriorityAdvisorProvider::AdvisorMode Mode,
123 LLVMContext &Ctx);
124 std::unique_ptr<RegAllocPriorityAdvisorProvider> Provider;
125};
126
128public:
131 : ImmutablePass(ID), Mode(Mode) {};
132 static char ID;
133
134 /// Get an advisor for the given context (i.e. machine function, etc)
136 AdvisorMode getAdvisorMode() const { return Mode; }
137 virtual void logRewardIfNeeded(const MachineFunction &MF,
138 llvm::function_ref<float()> GetReward) {};
139
140protected:
141 // This analysis preserves everything, and subclasses may have additional
142 // requirements.
143 void getAnalysisUsage(AnalysisUsage &AU) const override {
144 AU.setPreservesAll();
145 }
146
147 std::unique_ptr<RegAllocPriorityAdvisorProvider> Provider;
148
149private:
150 StringRef getPassName() const override;
151 const AdvisorMode Mode;
152};
153
154/// Specialization for the API used by the analysis infrastructure to create
155/// an instance of the priority advisor.
157
160
163
166
169
170} // namespace llvm
171
172#endif // LLVM_CODEGEN_REGALLOCPRIORITYADVISOR_H
#define LLVM_ATTRIBUTE_RETURNS_NONNULL
Definition: Compiler.h:373
This header defines various interfaces for pass management in LLVM.
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
SI optimize exec mask operations pre RA
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:294
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Trigger the invalidation of some other analysis pass if not already handled and return whether it was...
Definition: PassManager.h:312
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:255
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
DefaultPriorityAdvisor(const MachineFunction &MF, const RAGreedy &RA, SlotIndexes *const Indexes)
Stupid priority advisor which just enqueues in virtual register number order, for debug purposes only...
DummyPriorityAdvisor(const MachineFunction &MF, const RAGreedy &RA, SlotIndexes *const Indexes)
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:285
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
LiveInterval - This class represents the liveness of a register, or stack slot.
Definition: LiveInterval.h:690
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:99
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:112
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Definition: Analysis.h:275
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
RegAllocPriorityAdvisorProvider & getProvider()
Get an advisor for the given context (i.e. machine function, etc)
virtual void logRewardIfNeeded(const MachineFunction &MF, llvm::function_ref< float()> GetReward)
std::unique_ptr< RegAllocPriorityAdvisorProvider > Provider
Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Common provider for getting the priority advisor and logging rewards.
virtual ~RegAllocPriorityAdvisorProvider()=default
virtual void logRewardIfNeeded(const MachineFunction &MF, function_ref< float()> GetReward)
virtual std::unique_ptr< RegAllocPriorityAdvisor > getAdvisor(const MachineFunction &MF, const RAGreedy &RA, SlotIndexes &SI)=0
Interface to the priority advisor, which is responsible for prioritizing live ranges.
const RegisterClassInfo & RegClassInfo
MachineRegisterInfo *const MRI
RegAllocPriorityAdvisor(const RegAllocPriorityAdvisor &)=delete
RegAllocPriorityAdvisor(RegAllocPriorityAdvisor &&)=delete
virtual ~RegAllocPriorityAdvisor()=default
virtual unsigned getPriority(const LiveInterval &LI) const =0
Find the priority value for a live range.
const TargetRegisterInfo *const TRI
SlotIndexes pass.
Definition: SlotIndexes.h:298
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
RegAllocPriorityAdvisorAnalysisLegacy * createReleaseModePriorityAdvisorAnalysis()
RegAllocPriorityAdvisorAnalysisLegacy * createDevelopmentModePriorityAdvisorAnalysis()
Pass * callDefaultCtor< RegAllocPriorityAdvisorAnalysisLegacy >()
Specialization for the API used by the analysis infrastructure to create an instance of the priority ...
LLVM_ATTRIBUTE_RETURNS_NONNULL RegAllocPriorityAdvisorProvider * createDevelopmentModePriorityAdvisorProvider(LLVMContext &Ctx)
LLVM_ATTRIBUTE_RETURNS_NONNULL RegAllocPriorityAdvisorProvider * createReleaseModePriorityAdvisorProvider()
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:93
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:29
bool invalidate(MachineFunction &MF, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &Inv)