[PATCH] D134664: [nfc][mlgo] Lazily compute the regalloc reward
Mircea Trofin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 26 12:23:00 PDT 2022
mtrofin created this revision.
mtrofin added reviewers: jacobhegna, Flpha0830.
Herald added subscribers: hiraditya, qcolombet, MatzeB.
Herald added a project: All.
mtrofin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D134664
Files:
llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
llvm/lib/CodeGen/RegAllocEvictionAdvisor.h
llvm/lib/CodeGen/RegAllocPriorityAdvisor.h
Index: llvm/lib/CodeGen/RegAllocPriorityAdvisor.h
===================================================================
--- llvm/lib/CodeGen/RegAllocPriorityAdvisor.h
+++ llvm/lib/CodeGen/RegAllocPriorityAdvisor.h
@@ -68,7 +68,8 @@
virtual std::unique_ptr<RegAllocPriorityAdvisor>
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) = 0;
AdvisorMode getAdvisorMode() const { return Mode; }
- virtual void logRewardIfNeeded(const MachineFunction &MF, float Reward){};
+ virtual void logRewardIfNeeded(const MachineFunction &MF,
+ llvm::function_ref<float()> GetReward){};
protected:
// This analysis preserves everything, and subclasses may have additional
Index: llvm/lib/CodeGen/RegAllocEvictionAdvisor.h
===================================================================
--- llvm/lib/CodeGen/RegAllocEvictionAdvisor.h
+++ llvm/lib/CodeGen/RegAllocEvictionAdvisor.h
@@ -177,7 +177,8 @@
virtual std::unique_ptr<RegAllocEvictionAdvisor>
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) = 0;
AdvisorMode getAdvisorMode() const { return Mode; }
- virtual void logRewardIfNeeded(const MachineFunction &MF, float Reward){};
+ virtual void logRewardIfNeeded(const MachineFunction &MF,
+ llvm::function_ref<float()> GetReward){};
protected:
// This analysis preserves everything, and subclasses may have additional
Index: llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
===================================================================
--- llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
+++ llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
@@ -461,9 +461,10 @@
return I->second.get();
}
- void logRewardIfNeeded(const MachineFunction &MF, float Reward) override {
+ void logRewardIfNeeded(const MachineFunction &MF,
+ llvm::function_ref<float()> GetReward) override {
if (auto *Log = this->getLogger(MF))
- Log->logFloatFinalReward(Reward);
+ Log->logFloatFinalReward(GetReward());
}
private:
@@ -1067,13 +1068,19 @@
}
bool RegAllocScoring::runOnMachineFunction(MachineFunction &MF) {
- float Reward = static_cast<float>(
- calculateRegAllocScore(MF, getAnalysis<MachineBlockFrequencyInfo>())
- .getScore());
-
- getAnalysis<RegAllocEvictionAdvisorAnalysis>().logRewardIfNeeded(MF, Reward);
- getAnalysis<RegAllocPriorityAdvisorAnalysis>().logRewardIfNeeded(MF, Reward);
-
+ Optional<float> CachedReward;
+ auto GetReward = [&]() {
+ if (!CachedReward)
+ CachedReward = static_cast<float>(
+ calculateRegAllocScore(MF, getAnalysis<MachineBlockFrequencyInfo>())
+ .getScore());
+ return *CachedReward;
+ };
+
+ getAnalysis<RegAllocEvictionAdvisorAnalysis>().logRewardIfNeeded(MF,
+ GetReward);
+ getAnalysis<RegAllocPriorityAdvisorAnalysis>().logRewardIfNeeded(MF,
+ GetReward);
return false;
}
#endif // #ifdef LLVM_HAVE_TF_API
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134664.462994.patch
Type: text/x-patch
Size: 3076 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220926/6248b708/attachment.bin>
More information about the llvm-commits
mailing list