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) { @@ -3219,6 +3249,7 @@ Stats.FoldedSpills += Accesses.size(); } } + 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,25 +17,25 @@ ; 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{{$}} ; (func:) -; REMARK: remark: :0:0: 3 spills 3 reloads generated in function{{$}} +; REMARK: remark: :0:0: 3 spills 1.020000e+04 spills location cost 3 reloads 1.020000e+04 reloads location cost generated in function ; (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 Index: llvm/test/CodeGen/X86/statepoint-ra.ll =================================================================== --- llvm/test/CodeGen/X86/statepoint-ra.ll +++ llvm/test/CodeGen/X86/statepoint-ra.ll @@ -12,12 +12,18 @@ ;YAML: Args: ;YAML: - NumSpills: '10' ;YAML: - String: ' spills ' +;YAML: - SpillsLocationCost: '7.000000e+00' +;YAML: - String: ' spills location cost ' ;YAML: - NumReloads: '7' ;YAML: - String: ' reloads ' +;YAML: - ReloadsLocationCost: '3.109004e-15' +;YAML: - String: ' reloads location cost ' ;YAML: - NumZeroCostFoldedReloads: '7' ;YAML: - String: ' zero cost folded reloads ' -;YAML: - NumVRCopies: '10' -;YAML: - String: ' virtual registers copies ' +;YAML: - NumVRCopies: '10' +;YAML: - String: ' virtual registers copies ' +;YAML: - CopiesLocationCost: '4.000000e+00' +;YAML: - String: ' copies location cost ' ;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 {