LLVM 20.0.0git
RegAllocPriorityAdvisor.cpp
Go to the documentation of this file.
1//===- RegAllocPriorityAdvisor.cpp - live ranges priority advisor ---------===//
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// Implementation of the default priority advisor and of the Analysis pass.
10//
11//===----------------------------------------------------------------------===//
12
14#include "RegAllocGreedy.h"
17#include "llvm/IR/Module.h"
19#include "llvm/Pass.h"
20
21using namespace llvm;
22
24 "regalloc-enable-priority-advisor", cl::Hidden,
25 cl::init(RegAllocPriorityAdvisorAnalysis::AdvisorMode::Default),
26 cl::desc("Enable regalloc advisor mode"),
28 clEnumValN(RegAllocPriorityAdvisorAnalysis::AdvisorMode::Default,
29 "default", "Default"),
30 clEnumValN(RegAllocPriorityAdvisorAnalysis::AdvisorMode::Release,
31 "release", "precompiled"),
32 clEnumValN(RegAllocPriorityAdvisorAnalysis::AdvisorMode::Development,
33 "development", "for training")));
34
37 "Regalloc priority policy", false, true)
38
39namespace {
40class DefaultPriorityAdvisorAnalysis final
42public:
43 DefaultPriorityAdvisorAnalysis(bool NotAsRequested)
44 : RegAllocPriorityAdvisorAnalysis(AdvisorMode::Default),
45 NotAsRequested(NotAsRequested) {}
46
47 // support for isa<> and dyn_cast.
48 static bool classof(const RegAllocPriorityAdvisorAnalysis *R) {
49 return R->getAdvisorMode() == AdvisorMode::Default;
50 }
51
52private:
53 void getAnalysisUsage(AnalysisUsage &AU) const override {
56 }
57 std::unique_ptr<RegAllocPriorityAdvisor>
58 getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override {
59 return std::make_unique<DefaultPriorityAdvisor>(
60 MF, RA, &getAnalysis<SlotIndexesWrapperPass>().getSI());
61 }
62 bool doInitialization(Module &M) override {
63 if (NotAsRequested)
64 M.getContext().emitError("Requested regalloc priority advisor analysis "
65 "could be created. Using default");
67 }
68 const bool NotAsRequested;
69};
70} // namespace
71
73 Pass *Ret = nullptr;
74 switch (Mode) {
75 case RegAllocPriorityAdvisorAnalysis::AdvisorMode::Default:
76 Ret = new DefaultPriorityAdvisorAnalysis(/*NotAsRequested*/ false);
77 break;
78 case RegAllocPriorityAdvisorAnalysis::AdvisorMode::Development:
79#if defined(LLVM_HAVE_TFLITE)
81#endif
82 break;
83 case RegAllocPriorityAdvisorAnalysis::AdvisorMode::Release:
85 break;
86 }
87 if (Ret)
88 return Ret;
89 return new DefaultPriorityAdvisorAnalysis(/*NotAsRequested*/ true);
90}
91
92StringRef RegAllocPriorityAdvisorAnalysis::getPassName() const {
93 switch (getAdvisorMode()) {
95 return "Default Regalloc Priority Advisor";
97 return "Release mode Regalloc Priority Advisor";
99 return "Development mode Regalloc Priority Advisor";
100 }
101 llvm_unreachable("Unknown advisor kind");
102}
103
105 const RAGreedy &RA,
106 SlotIndexes *const Indexes)
107 : RA(RA), LIS(RA.getLiveIntervals()), VRM(RA.getVirtRegMap()),
108 MRI(&VRM->getRegInfo()), TRI(MF.getSubtarget().getRegisterInfo()),
109 RegClassInfo(RA.getRegClassInfo()), Indexes(Indexes),
110 RegClassPriorityTrumpsGlobalness(
111 RA.getRegClassPriorityTrumpsGlobalness()),
112 ReverseLocalAssignment(RA.getReverseLocalAssignment()) {}
unsigned const MachineRegisterInfo * MRI
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:686
unsigned const TargetRegisterInfo * TRI
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
static cl::opt< RegAllocPriorityAdvisorAnalysis::AdvisorMode > Mode("regalloc-enable-priority-advisor", cl::Hidden, cl::init(RegAllocPriorityAdvisorAnalysis::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocPriorityAdvisorAnalysis::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocPriorityAdvisorAnalysis::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocPriorityAdvisorAnalysis::AdvisorMode::Development, "development", "for training")))
SI optimize exec mask operations pre RA
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:94
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:119
virtual std::unique_ptr< RegAllocPriorityAdvisor > getAdvisor(const MachineFunction &MF, const RAGreedy &RA)=0
Get an advisor for the given context (i.e. machine function, etc)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
RegAllocPriorityAdvisor(const RegAllocPriorityAdvisor &)=delete
SlotIndexes pass.
Definition: SlotIndexes.h:297
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:711
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
RegAllocPriorityAdvisorAnalysis * createReleaseModePriorityAdvisor()
RegAllocPriorityAdvisorAnalysis * createDevelopmentModePriorityAdvisor()
Pass * callDefaultCtor< RegAllocPriorityAdvisorAnalysis >()
Specialization for the API used by the analysis infrastructure to create an instance of the priority ...