[llvm] 6b64c66 - [GreedyRA ORE] Extract computeNumberOfSplillsReloads to use in different places. NFC.
Serguei Katkov via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 8 00:53:08 PDT 2021
Author: Serguei Katkov
Date: 2021-04-08T14:40:45+07:00
New Revision: 6b64c662c79524a2ec5f5b1bc10ce4c2a1e3ff37
URL: https://github.com/llvm/llvm-project/commit/6b64c662c79524a2ec5f5b1bc10ce4c2a1e3ff37
DIFF: https://github.com/llvm/llvm-project/commit/6b64c662c79524a2ec5f5b1bc10ce4c2a1e3ff37.diff
LOG: [GreedyRA ORE] Extract computeNumberOfSplillsReloads to use in different places. NFC.
Extract one basic block handling to introduce stat computation for method scope.
Reviewers: reames, MatzeB, anemet, thegameg
Reviewed By: reames, thegameg
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D100013
Added:
Modified:
llvm/lib/CodeGen/RegAllocGreedy.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp
index 7385f18e1bfc..bd004cdad3ce 100644
--- a/llvm/lib/CodeGen/RegAllocGreedy.cpp
+++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp
@@ -567,7 +567,10 @@ class RAGreedy : public MachineFunctionPass,
void report(MachineOptimizationRemarkMissed &R);
};
- /// Compute and report the number of spills and reloads for a loop.
+ /// Compute the number of spills and reloads for a basic block.
+ RAGreedyStats computeNumberOfSplillsReloads(MachineBasicBlock &MBB);
+
+ /// Compute and report the number of spills through a remark.
RAGreedyStats reportNumberOfSplillsReloads(MachineLoop *L);
/// Report the number of spills and reloads for each loop.
@@ -3137,6 +3140,33 @@ void RAGreedy::RAGreedyStats::report(MachineOptimizationRemarkMissed &R) {
R << NV("NumFoldedReloads", FoldedReloads) << " folded reloads ";
}
+RAGreedy::RAGreedyStats
+RAGreedy::computeNumberOfSplillsReloads(MachineBasicBlock &MBB) {
+ RAGreedyStats Stats;
+ const MachineFrameInfo &MFI = MF->getFrameInfo();
+ int FI;
+
+ for (MachineInstr &MI : MBB) {
+ SmallVector<const MachineMemOperand *, 2> Accesses;
+ auto isSpillSlotAccess = [&MFI](const MachineMemOperand *A) {
+ return MFI.isSpillSlotObjectIndex(cast<FixedStackPseudoSourceValue>(
+ A->getPseudoValue())->getFrameIndex());
+ };
+
+ if (TII->isLoadFromStackSlot(MI, FI) && MFI.isSpillSlotObjectIndex(FI))
+ ++Stats.Reloads;
+ else if (TII->hasLoadFromStackSlot(MI, Accesses) &&
+ llvm::any_of(Accesses, isSpillSlotAccess))
+ ++Stats.FoldedReloads;
+ else if (TII->isStoreToStackSlot(MI, FI) && MFI.isSpillSlotObjectIndex(FI))
+ ++Stats.Spills;
+ else if (TII->hasStoreToStackSlot(MI, Accesses) &&
+ llvm::any_of(Accesses, isSpillSlotAccess))
+ ++Stats.FoldedSpills;
+ }
+ return Stats;
+}
+
RAGreedy::RAGreedyStats RAGreedy::reportNumberOfSplillsReloads(MachineLoop *L) {
RAGreedyStats Stats;
@@ -3144,32 +3174,10 @@ RAGreedy::RAGreedyStats RAGreedy::reportNumberOfSplillsReloads(MachineLoop *L) {
for (MachineLoop *SubLoop : *L)
Stats.add(reportNumberOfSplillsReloads(SubLoop));
- const MachineFrameInfo &MFI = MF->getFrameInfo();
- int FI;
-
for (MachineBasicBlock *MBB : L->getBlocks())
// Handle blocks that were not included in subloops.
if (Loops->getLoopFor(MBB) == L)
- for (MachineInstr &MI : *MBB) {
- SmallVector<const MachineMemOperand *, 2> Accesses;
- auto isSpillSlotAccess = [&MFI](const MachineMemOperand *A) {
- return MFI.isSpillSlotObjectIndex(
- cast<FixedStackPseudoSourceValue>(A->getPseudoValue())
- ->getFrameIndex());
- };
-
- if (TII->isLoadFromStackSlot(MI, FI) && MFI.isSpillSlotObjectIndex(FI))
- ++Stats.Reloads;
- else if (TII->hasLoadFromStackSlot(MI, Accesses) &&
- llvm::any_of(Accesses, isSpillSlotAccess))
- ++Stats.FoldedReloads;
- else if (TII->isStoreToStackSlot(MI, FI) &&
- MFI.isSpillSlotObjectIndex(FI))
- ++Stats.Spills;
- else if (TII->hasStoreToStackSlot(MI, Accesses) &&
- llvm::any_of(Accesses, isSpillSlotAccess))
- ++Stats.FoldedSpills;
- }
+ Stats.add(computeNumberOfSplillsReloads(*MBB));
if (!Stats.isEmpty()) {
using namespace ore;
More information about the llvm-commits
mailing list