Skip to content

Commit

Permalink
Apply suggestions and remove setAnalyses
Browse files Browse the repository at this point in the history
  • Loading branch information
optimisan committed Jan 1, 2025
1 parent 32cd5dd commit 9c2ca75
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 deletions.
13 changes: 6 additions & 7 deletions llvm/include/llvm/CodeGen/RegAllocPriorityAdvisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,15 @@ class RegAllocPriorityAdvisorProvider {
virtual ~RegAllocPriorityAdvisorProvider() = default;

virtual void logRewardIfNeeded(const MachineFunction &MF,
llvm::function_ref<float()> GetReward) {};
function_ref<float()> GetReward) {};

virtual std::unique_ptr<RegAllocPriorityAdvisor>
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) = 0;

void setAnalyses(SlotIndexes *SI) { this->SI = SI; }
getAdvisor(const MachineFunction &MF, const RAGreedy &RA,
SlotIndexes *SI) = 0;

AdvisorMode getAdvisorMode() const { return Mode; }

protected:
SlotIndexes *SI;

private:
const AdvisorMode Mode;
};
Expand Down Expand Up @@ -125,7 +122,9 @@ class RegAllocPriorityAdvisorAnalysisLegacy : public ImmutablePass {
static char ID;

/// Get an advisor for the given context (i.e. machine function, etc)
virtual std::unique_ptr<RegAllocPriorityAdvisorProvider> &getProvider() = 0;
std::unique_ptr<RegAllocPriorityAdvisorProvider> &getProvider() {
return Provider;
}
AdvisorMode getAdvisorMode() const { return Mode; }
virtual void logRewardIfNeeded(const MachineFunction &MF,
llvm::function_ref<float()> GetReward) {};
Expand Down
16 changes: 4 additions & 12 deletions llvm/lib/CodeGen/MLRegAllocPriorityAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ class ReleaseModePriorityAdvisorProvider final
ReleaseModePriorityAdvisorProvider()
: RegAllocPriorityAdvisorProvider(AdvisorMode::Release) {}
std::unique_ptr<RegAllocPriorityAdvisor>
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override {
getAdvisor(const MachineFunction &MF, const RAGreedy &RA,
SlotIndexes *SI) override {
if (!Runner) {
if (InteractiveChannelBaseName.empty())
Runner = std::make_unique<ReleaseModeModelRunner<CompiledModelType>>(
Expand Down Expand Up @@ -163,11 +164,6 @@ class ReleaseModePriorityAdvisorAnalysisLegacy final
RegAllocPriorityAdvisorAnalysisLegacy::getAnalysisUsage(AU);
}

std::unique_ptr<RegAllocPriorityAdvisorProvider> &getProvider() override {
Provider->setAnalyses(&getAnalysis<SlotIndexesWrapperPass>().getSI());
return Provider;
}

bool doInitialization(Module &M) override {
Provider = std::make_unique<ReleaseModePriorityAdvisorProvider>();
return false;
Expand Down Expand Up @@ -262,7 +258,8 @@ class DevelopmentModePriorityAdvisorProvider final
}

std::unique_ptr<RegAllocPriorityAdvisor>
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override {
getAdvisor(const MachineFunction &MF, const RAGreedy &RA,
SlotIndexes *SI) override {
if (!Runner)
return nullptr;
if (Log) {
Expand Down Expand Up @@ -307,11 +304,6 @@ class DevelopmentModePriorityAdvisorAnalysisLegacy final
return false;
;
}

std::unique_ptr<RegAllocPriorityAdvisorProvider> &getProvider() override {
Provider->setAnalyses(&getAnalysis<SlotIndexesWrapperPass>().getSI());
return Provider;
}
};
#endif //#ifdef LLVM_HAVE_TFLITE

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/RegAllocGreedy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2754,7 +2754,7 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {

PriorityAdvisor = getAnalysis<RegAllocPriorityAdvisorAnalysisLegacy>()
.getProvider()
->getAdvisor(*MF, *this);
->getAdvisor(*MF, *this, Indexes);

VRAI = std::make_unique<VirtRegAuxInfo>(*MF, *LIS, *VRM, *Loops, *MBFI);
SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM, *VRAI));
Expand Down
11 changes: 2 additions & 9 deletions llvm/lib/CodeGen/RegAllocPriorityAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class DefaultPriorityAdvisorProvider final
}

std::unique_ptr<RegAllocPriorityAdvisor>
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override {
getAdvisor(const MachineFunction &MF, const RAGreedy &RA,
SlotIndexes *SI) override {
assert(SI && "SlotIndexes result must be set");
return std::make_unique<DefaultPriorityAdvisor>(MF, RA, SI);
}
Expand All @@ -78,19 +79,13 @@ class DefaultPriorityAdvisorAnalysisLegacy final
RegAllocPriorityAdvisorAnalysisLegacy::getAnalysisUsage(AU);
}

std::unique_ptr<RegAllocPriorityAdvisorProvider> &getProvider() override {
Provider->setAnalyses(&getAnalysis<SlotIndexesWrapperPass>().getSI());
return Provider;
}

bool doInitialization(Module &M) override {
Provider.reset(
new DefaultPriorityAdvisorProvider(NotAsRequested, M.getContext()));
return false;
}

const bool NotAsRequested;
// std::unique_ptr<DefaultPriorityAdvisorProvider> Provider;
};
} // namespace

Expand All @@ -114,8 +109,6 @@ RegAllocPriorityAdvisorAnalysis::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
// Lazily initialize the provider.
initializeProvider(MF.getFunction().getContext());
// On each run, update the analysis for the provider.
Provider->setAnalyses(&MFAM.getResult<SlotIndexesAnalysis>(MF));
// The requiring analysis will construct the advisor.
return Result{Provider.get()};
}
Expand Down

0 comments on commit 9c2ca75

Please sign in to comment.