LLVM 23.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 const RAGreedy &RA,
38 SlotIndexes *const Indexes);
39
40protected:
41 const RAGreedy &RA;
45 const TargetRegisterInfo *const TRI;
50};
51
53public:
57
58private:
59 unsigned getPriority(const LiveInterval &LI) const override;
60};
61
62/// Stupid priority advisor which just enqueues in virtual register number
63/// order, for debug purposes only.
65public:
69
70private:
71 unsigned getPriority(const LiveInterval &LI) const override;
72};
73
74/// Common provider for getting the priority advisor and logging rewards.
75/// Legacy analysis forwards all calls to this provider.
76/// New analysis serves the provider as the analysis result.
77/// Expensive setup is done in the constructor, so that the advisor can be
78/// created quickly for every machine function.
79/// TODO: Remove once legacy PM support is dropped.
81public:
82 enum class AdvisorMode : int { Default, Release, Development, Dummy };
83
85
87
88 virtual void logRewardIfNeeded(const MachineFunction &MF,
89 function_ref<float()> GetReward) {};
90
91 virtual std::unique_ptr<RegAllocPriorityAdvisor>
93 SlotIndexes &SI) = 0;
94
95 AdvisorMode getAdvisorMode() const { return Mode; }
96
97private:
98 const AdvisorMode Mode;
99};
100
102 : public AnalysisInfoMixin<RegAllocPriorityAdvisorAnalysis> {
103 static AnalysisKey Key;
105
106public:
107 struct Result {
108 // Owned by this analysis.
110
112 MachineFunctionAnalysisManager::Invalidator &Inv) {
114 return !PAC.preservedWhenStateless() ||
115 Inv.invalidate<SlotIndexesAnalysis>(MF, PA);
116 }
117 };
118
119 LLVM_ABI Result run(MachineFunction &MF,
121
122private:
123 void initializeProvider(LLVMContext &Ctx);
124 void initializeMLProvider(RegAllocPriorityAdvisorProvider::AdvisorMode Mode,
125 LLVMContext &Ctx);
126 std::unique_ptr<RegAllocPriorityAdvisorProvider> Provider;
127};
128
130public:
134 static char ID;
135
136 /// Get an advisor for the given context (i.e. machine function, etc)
138 AdvisorMode getAdvisorMode() const { return Mode; }
139 virtual void logRewardIfNeeded(const MachineFunction &MF,
140 llvm::function_ref<float()> GetReward) {};
141
142protected:
143 // This analysis preserves everything, and subclasses may have additional
144 // requirements.
145 void getAnalysisUsage(AnalysisUsage &AU) const override {
146 AU.setPreservesAll();
147 }
148
149 std::unique_ptr<RegAllocPriorityAdvisorProvider> Provider;
150
151private:
152 StringRef getPassName() const override;
153 const AdvisorMode Mode;
154};
155
156/// Specialization for the API used by the analysis infrastructure to create
157/// an instance of the priority advisor.
158template <>
160
163
166
169
172
173} // namespace llvm
174
175#endif // LLVM_CODEGEN_REGALLOCPRIORITYADVISOR_H
#define LLVM_ABI
Definition Compiler.h:213
#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
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)
DummyPriorityAdvisor(const MachineFunction &MF, const RAGreedy &RA, SlotIndexes *const Indexes)
ImmutablePass(char &pid)
Definition Pass.h:287
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.
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)
RegAllocPriorityAdvisorProvider::AdvisorMode AdvisorMode
virtual void logRewardIfNeeded(const MachineFunction &MF, llvm::function_ref< float()> GetReward)
std::unique_ptr< RegAllocPriorityAdvisorProvider > Provider
LLVM_ABI 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
const RegisterClassInfo & RegClassInfo
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.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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.
LLVM_ABI RegAllocPriorityAdvisorAnalysisLegacy * createReleaseModePriorityAdvisorAnalysis()
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI Pass * callDefaultCtor< RegAllocPriorityAdvisorAnalysisLegacy >()
Specialization for the API used by the analysis infrastructure to create an instance of the priority ...
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ABI RegAllocPriorityAdvisorProvider * createReleaseModePriorityAdvisorProvider()
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ABI RegAllocPriorityAdvisorProvider * createDevelopmentModePriorityAdvisorProvider(LLVMContext &Ctx)
LLVM_ABI RegAllocPriorityAdvisorAnalysisLegacy * createDevelopmentModePriorityAdvisorAnalysis()
A CRTP mix-in that provides informational APIs needed for analysis passes.
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)