diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp --- a/llvm/lib/CodeGen/RegAllocGreedy.cpp +++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp @@ -554,10 +554,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) { @@ -566,19 +567,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 through a remark. - RAGreedyStats reportNumberOfSplillsReloads(MachineLoop *L); + /// Compute and report statistic through a remark. + 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 @@ -3145,10 +3147,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; @@ -3163,8 +3166,16 @@ MI.getOpcode() == TargetOpcode::STATEPOINT; }; for (MachineInstr &MI : MBB) { - SmallVector Accesses; + 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; + continue; + } + SmallVector Accesses; if (TII->isLoadFromStackSlot(MI, FI) && MFI.isSpillSlotObjectIndex(FI)) { ++Stats.Reloads; continue; @@ -3209,23 +3220,23 @@ 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"; @@ -3235,16 +3246,16 @@ 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; @@ -3252,7 +3263,7 @@ DebugLoc Loc; if (auto *SP = MF->getFunction().getSubprogram()) Loc = DILocation::get(SP->getContext(), SP->getLine(), 1, SP); - MachineOptimizationRemarkMissed R(DEBUG_TYPE, "SpillReload", Loc, + MachineOptimizationRemarkMissed R(DEBUG_TYPE, "SpillReloadCopies", Loc, &MF->front()); Stats.report(R); R << "generated in function"; @@ -3322,7 +3333,7 @@ if (VerifyEnabled) MF->verify(this, "Before post optimization"); postOptimization(); - reportNumberOfSplillsReloads(); + reportStats(); releaseMemory(); return true; diff --git a/llvm/test/CodeGen/AArch64/arm64-spill-remarks.ll b/llvm/test/CodeGen/AArch64/arm64-spill-remarks.ll --- a/llvm/test/CodeGen/AArch64/arm64-spill-remarks.ll +++ b/llvm/test/CodeGen/AArch64/arm64-spill-remarks.ll @@ -39,7 +39,7 @@ ; YAML: --- !Missed ; YAML: Pass: regalloc -; YAML: Name: LoopSpillReload +; YAML: Name: LoopSpillReloadCopies ; YAML: DebugLoc: { File: '/tmp/kk.c', Line: 3, Column: 20 } ; YAML: Function: fpr128 ; YAML: Hotness: 300 @@ -52,7 +52,7 @@ ; YAML: ... ; YAML: --- !Missed ; YAML: Pass: regalloc -; YAML: Name: LoopSpillReload +; YAML: Name: LoopSpillReloadCopies ; YAML: DebugLoc: { File: '/tmp/kk.c', Line: 2, Column: 20 } ; YAML: Function: fpr128 ; YAML: Hotness: 30000 @@ -65,7 +65,7 @@ ; YAML: ... ; YAML: --- !Missed ; YAML: Pass: regalloc -; YAML: Name: LoopSpillReload +; YAML: Name: LoopSpillReloadCopies ; YAML: DebugLoc: { File: '/tmp/kk.c', Line: 1, Column: 20 } ; YAML: Function: fpr128 ; YAML: Hotness: 300 @@ -78,7 +78,7 @@ ; YAML: ... ; YAML: --- !Missed ; YAML: Pass: regalloc -; YAML: Name: SpillReload +; YAML: Name: SpillReloadCopies ; YAML: DebugLoc: { File: '/tmp/kk.c', Line: 1, Column: 1 } ; YAML: Function: fpr128 ; YAML: Hotness: 3 @@ -93,7 +93,7 @@ ; THRESHOLD_YAML-NOT: Hotness: 300{{$}} ; THRESHOLD_YAML: --- !Missed ; THRESHOLD_YAML: Pass: regalloc -; THRESHOLD_YAML: Name: LoopSpillReload +; THRESHOLD_YAML: Name: LoopSpillReloadCopies ; THRESHOLD_YAML: DebugLoc: { File: '/tmp/kk.c', Line: 2, Column: 20 } ; THRESHOLD_YAML: Function: fpr128 ; THRESHOLD_YAML: Hotness: 30000 diff --git a/llvm/test/CodeGen/X86/statepoint-ra.ll b/llvm/test/CodeGen/X86/statepoint-ra.ll --- a/llvm/test/CodeGen/X86/statepoint-ra.ll +++ b/llvm/test/CodeGen/X86/statepoint-ra.ll @@ -7,7 +7,7 @@ ;YAML: --- !Missed ;YAML: Pass: regalloc -;YAML: Name: SpillReload +;YAML: Name: SpillReloadCopies ;YAML: Function: barney ;YAML: Args: ;YAML: - NumSpills: '10' @@ -16,6 +16,8 @@ ;YAML: - String: ' reloads ' ;YAML: - NumZeroCostFoldedReloads: '20' ;YAML: - String: ' zero cost folded reloads ' +;YAML: - NumVRCopies: '2' +;YAML: - String: ' virtual registers copies ' ;YAML: - String: generated in function define void @barney(i8 addrspace(1)* %arg, double %arg1, double %arg2, double %arg3, double %arg4, double %arg5, double %arg6, double %arg7, double %arg8, double %arg9, double %arg10, double %arg11, double %arg12) gc "statepoint-example" personality i32* ()* @widget {