Index: llvm/lib/CodeGen/RegAllocGreedy.cpp =================================================================== --- llvm/lib/CodeGen/RegAllocGreedy.cpp +++ llvm/lib/CodeGen/RegAllocGreedy.cpp @@ -554,6 +554,11 @@ unsigned Spills = 0; unsigned FoldedSpills = 0; unsigned Copies = 0; + float ReloadsCost = 0.0f; + float FoldedReloadsCost = 0.0f; + float SpillsCost = 0.0f; + float FoldedSpillsCost = 0.0f; + float CopiesCost = 0.0f; bool isEmpty() { return !(Reloads || FoldedReloads || Spills || FoldedSpills || @@ -567,6 +572,19 @@ Spills += other.Spills; FoldedSpills += other.FoldedSpills; Copies += other.Copies; + ReloadsCost += other.ReloadsCost; + FoldedReloadsCost += other.FoldedReloadsCost; + SpillsCost += other.SpillsCost; + FoldedSpillsCost += other.FoldedSpillsCost; + CopiesCost += other.CopiesCost; + } + + void addCost(float freq) { + ReloadsCost += freq * Reloads; + FoldedReloadsCost += freq * FoldedReloads; + SpillsCost += freq * Spills; + FoldedSpillsCost += freq * FoldedSpills; + CopiesCost += freq * Copies; } void report(MachineOptimizationRemarkMissed &R); @@ -3135,19 +3153,31 @@ void RAGreedy::RAGreedyStats::report(MachineOptimizationRemarkMissed &R) { using namespace ore; - if (Spills) + if (Spills) { R << NV("NumSpills", Spills) << " spills "; - if (FoldedSpills) + R << NV("SpillsLocationCost", SpillsCost) << " spills location cost "; + } + if (FoldedSpills) { R << NV("NumFoldedSpills", FoldedSpills) << " folded spills "; - if (Reloads) + R << NV("FoldedSpillsLocationCost", FoldedSpillsCost) + << " folded spills location cost "; + } + if (Reloads) { R << NV("NumReloads", Reloads) << " reloads "; - if (FoldedReloads) + R << NV("ReloadsLocationCost", ReloadsCost) << " reloads location cost "; + } + if (FoldedReloads) { R << NV("NumFoldedReloads", FoldedReloads) << " folded reloads "; + R << NV("FoldedReloadsLocationCost", FoldedReloadsCost) + << " folded reloads location cost "; + } if (ZeroCostFoldedReloads) R << NV("NumZeroCostFoldedReloads", ZeroCostFoldedReloads) << " zero cost folded reloads "; - if (Copies) + if (Copies) { R << NV("NumVRCopies", Copies) << " virtual registers copies "; + R << NV("CopiesLocationCost", CopiesCost) << " copies location cost "; + } } RAGreedy::RAGreedyStats RAGreedy::computeStats(MachineBasicBlock &MBB) { @@ -3195,6 +3225,7 @@ ++Stats.Copies; } } + Stats.addCost(MBFI->getBlockFreqRelativeToEntryBlock(&MBB)); return Stats; } Index: llvm/test/CodeGen/AArch64/arm64-spill-remarks-treshold-hotness.ll =================================================================== --- llvm/test/CodeGen/AArch64/arm64-spill-remarks-treshold-hotness.ll +++ llvm/test/CodeGen/AArch64/arm64-spill-remarks-treshold-hotness.ll @@ -5,7 +5,7 @@ ; RUN: -pass-remarks-with-hotness -pass-remarks-hotness-threshold=1 \ ; RUN: 2>&1 | FileCheck -check-prefix=THRESHOLD %s -; CHECK: remark: /tmp/kk.c:3:20: 1 spills 1 reloads generated in loop{{$}} +; CHECK: remark: /tmp/kk.c:3:20: 1 spills 3.187500e+01 spills location cost 1 reloads 3.187500e+01 reloads location cost generated in loop{{$}} ; THRESHOLD-NOT: remark define void @fpr128(<4 x float>* %p) nounwind ssp { Index: llvm/test/CodeGen/AArch64/arm64-spill-remarks.ll =================================================================== --- llvm/test/CodeGen/AArch64/arm64-spill-remarks.ll +++ llvm/test/CodeGen/AArch64/arm64-spill-remarks.ll @@ -17,27 +17,27 @@ ; then reloaded. ; (loop3:) -; REMARK: remark: /tmp/kk.c:3:20: 1 spills 1 reloads generated in loop{{$}} +; REMARK: remark: /tmp/kk.c:3:20: 1 spills 1.000000e+02 spills location cost 1 reloads 1.000000e+02 reloads location cost generated in loop{{$}} ; (loop2:) -; REMARK: remark: /tmp/kk.c:2:20: 1 spills 1 reloads generated in loop{{$}} +; REMARK: remark: /tmp/kk.c:2:20: 1 spills 1.000000e+04 spills location cost 1 reloads 1.000000e+04 reloads location cost generated in loop{{$}} ; (loop:) -; REMARK: remark: /tmp/kk.c:1:20: 2 spills 2 reloads generated in loop{{$}} +; REMARK: remark: /tmp/kk.c:1:20: 2 spills 1.010000e+04 spills location cost 2 reloads 1.010000e+04 reloads location cost generated in loop{{$}} ; (loop3:) -; HOTNESS: remark: /tmp/kk.c:3:20: 1 spills 1 reloads generated in loop (hotness: 300) +; HOTNESS: remark: /tmp/kk.c:3:20: 1 spills 1.000000e+02 spills location cost 1 reloads 1.000000e+02 reloads location cost generated in loop (hotness: 300) ; (loop2:) -; HOTNESS: remark: /tmp/kk.c:2:20: 1 spills 1 reloads generated in loop (hotness: 30000) +; HOTNESS: remark: /tmp/kk.c:2:20: 1 spills 1.000000e+04 spills location cost 1 reloads 1.000000e+04 reloads location cost generated in loop (hotness: 30000) ; (loop:) -; HOTNESS: remark: /tmp/kk.c:1:20: 2 spills 2 reloads generated in loop (hotness: 300) +; HOTNESS: remark: /tmp/kk.c:1:20: 2 spills 1.010000e+04 spills location cost 2 reloads 1.010000e+04 reloads location cost generated in loop (hotness: 300) ; NO_REMARK-NOT: remark ; THRESHOLD-NOT: (hotness: 300) -; THRESHOLD: remark: /tmp/kk.c:2:20: 1 spills 1 reloads generated in loop (hotness: 30000) +; THRESHOLD: remark: /tmp/kk.c:2:20: 1 spills 1.000000e+04 spills location cost 1 reloads 1.000000e+04 reloads location cost generated in loop (hotness: 30000) ; 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