Index: llvm/lib/CodeGen/RegAllocGreedy.cpp =================================================================== --- llvm/lib/CodeGen/RegAllocGreedy.cpp +++ llvm/lib/CodeGen/RegAllocGreedy.cpp @@ -553,10 +553,11 @@ unsigned ZeroCostFoldedReloads = 0; unsigned Spills = 0; unsigned FoldedSpills = 0; + unsigned Copies = 0; bool isEmpty() { return !(Reloads || FoldedReloads || Spills || FoldedSpills || - ZeroCostFoldedReloads); + ZeroCostFoldedReloads || Copies); } void add(RAGreedyStats other) { @@ -565,19 +566,20 @@ ZeroCostFoldedReloads += other.ZeroCostFoldedReloads; Spills += other.Spills; FoldedSpills += other.FoldedSpills; + Copies += other.Copies; } void report(MachineOptimizationRemarkMissed &R); }; - /// Compute the number of spills and reloads for a basic block. - RAGreedyStats computeNumberOfSplillsReloads(MachineBasicBlock &MBB); + /// Compute statistic for a basic block. + RAGreedyStats computeStats(MachineBasicBlock &MBB); - /// Compute and report the number of spills and reloads for a loop. - RAGreedyStats reportNumberOfSplillsReloads(MachineLoop *L); + /// Compute and report statistic for a loop. + RAGreedyStats reportStats(MachineLoop *L); - /// Report the number of spills and reloads for each loop. - void reportNumberOfSplillsReloads(); + /// Report the statistic for each loop. + void reportStats(); }; } // end anonymous namespace @@ -3144,10 +3146,11 @@ if (ZeroCostFoldedReloads) R << NV("NumZeroCostFoldedReloads", ZeroCostFoldedReloads) << " zero cost folded reloads "; + if (Copies) + R << NV("NumVRCopies", Copies) << " virtual registers copies "; } -RAGreedy::RAGreedyStats -RAGreedy::computeNumberOfSplillsReloads(MachineBasicBlock &MBB) { +RAGreedy::RAGreedyStats RAGreedy::computeStats(MachineBasicBlock &MBB) { RAGreedyStats Stats; const MachineFrameInfo &MFI = MF->getFrameInfo(); int FI; @@ -3184,27 +3187,34 @@ else if (TII->hasStoreToStackSlot(MI, Accesses) && llvm::any_of(Accesses, isSpillSlotAccess)) ++Stats.FoldedSpills; + if (MI.isCopy()) { + MachineOperand &Dest = MI.getOperand(0); + MachineOperand &Src = MI.getOperand(1); + if (Dest.isReg() && Src.isReg() && Dest.getReg().isVirtual() && + Src.getReg().isVirtual()) + ++Stats.Copies; + } } return Stats; } -RAGreedy::RAGreedyStats RAGreedy::reportNumberOfSplillsReloads(MachineLoop *L) { +RAGreedy::RAGreedyStats RAGreedy::reportStats(MachineLoop *L) { RAGreedyStats Stats; // Sum up the spill and reloads in subloops. for (MachineLoop *SubLoop : *L) - Stats.add(reportNumberOfSplillsReloads(SubLoop)); + Stats.add(reportStats(SubLoop)); for (MachineBasicBlock *MBB : L->getBlocks()) // Handle blocks that were not included in subloops. if (Loops->getLoopFor(MBB) == L) - Stats.add(computeNumberOfSplillsReloads(*MBB)); + Stats.add(computeStats(*MBB)); if (!Stats.isEmpty()) { using namespace ore; ORE->emit([&]() { - MachineOptimizationRemarkMissed R(DEBUG_TYPE, "LoopSpillReload", + MachineOptimizationRemarkMissed R(DEBUG_TYPE, "LoopSpillReloadCopies", L->getStartLoc(), L->getHeader()); Stats.report(R); R << "generated in loop"; @@ -3214,22 +3224,22 @@ return Stats; } -void RAGreedy::reportNumberOfSplillsReloads() { +void RAGreedy::reportStats() { if (!ORE->allowExtraAnalysis(DEBUG_TYPE)) return; RAGreedyStats Stats; for (MachineLoop *L : *Loops) - Stats.add(reportNumberOfSplillsReloads(L)); + Stats.add(reportStats(L)); // Process non-loop blocks. for (MachineBasicBlock &MBB : *MF) if (!Loops->getLoopFor(&MBB)) - Stats.add(computeNumberOfSplillsReloads(MBB)); + Stats.add(computeStats(MBB)); if (!Stats.isEmpty()) { using namespace ore; ORE->emit([&]() { - MachineOptimizationRemarkMissed R(DEBUG_TYPE, "SpillReload", DebugLoc(), - &MF->front()); + MachineOptimizationRemarkMissed R(DEBUG_TYPE, "SpillReloadCopies", + DebugLoc(), &MF->front()); Stats.report(R); R << "generated in function"; return R; @@ -3298,7 +3308,7 @@ if (VerifyEnabled) MF->verify(this, "Before post optimization"); postOptimization(); - reportNumberOfSplillsReloads(); + reportStats(); releaseMemory(); return true;