Skip to content

Commit

Permalink
[opt-remarks] If hotness threshold is set, ignore remarks without hot…
Browse files Browse the repository at this point in the history
…ness

These are blocks that haven't not been executed during training.  For large
projects this could make a significant difference.  For the project, I was
looking at, I got an order of magnitude decrease in the size of the total YAML
files with this and r319235.

Differential Revision: https://reviews.llvm.org/D40678

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319556 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
anemet committed Dec 1, 2017
1 parent 54b4cc4 commit 7cb910a
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 9 deletions.
9 changes: 4 additions & 5 deletions lib/Analysis/OptimizationRemarkEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ void OptimizationRemarkEmitter::emit(
DiagnosticInfoOptimizationBase &OptDiagBase) {
auto &OptDiag = cast<DiagnosticInfoIROptimization>(OptDiagBase);
computeHotness(OptDiag);
// If a diagnostic has a hotness value, then only emit it if its hotness
// meets the threshold.
if (OptDiag.getHotness() &&
*OptDiag.getHotness() <
F->getContext().getDiagnosticsHotnessThreshold()) {

// Only emit it if its hotness meets the threshold.
if (OptDiag.getHotness().getValueOr(0) <
F->getContext().getDiagnosticsHotnessThreshold()) {
return;
}

Expand Down
7 changes: 3 additions & 4 deletions lib/CodeGen/MachineOptimizationRemarkEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ void MachineOptimizationRemarkEmitter::emit(

LLVMContext &Ctx = MF.getFunction()->getContext();

// If a diagnostic has a hotness value, then only emit it if its hotness
// meets the threshold.
if (OptDiag.getHotness() &&
*OptDiag.getHotness() < Ctx.getDiagnosticsHotnessThreshold()) {
// Only emit it if its hotness meets the threshold.
if (OptDiag.getHotness().getValueOr(0) <
Ctx.getDiagnosticsHotnessThreshold()) {
return;
}

Expand Down
60 changes: 60 additions & 0 deletions test/CodeGen/AArch64/arm64-spill-remarks-treshold-hotness.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
; RUN: llc < %s -mtriple=arm64-apple-ios7.0 -aarch64-neon-syntax=apple -pass-remarks-missed=regalloc \
; RUN: -pass-remarks-with-hotness 2>&1 | FileCheck %s

; RUN: llc < %s -mtriple=arm64-apple-ios7.0 -aarch64-neon-syntax=apple -pass-remarks-missed=regalloc \
; 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{{$}}
; THRESHOLD-NOT: remark

define void @fpr128(<4 x float>* %p) nounwind ssp {
entry:
br label %loop, !dbg !8

loop:
%i = phi i32 [ 0, %entry], [ %i.2, %end2 ]
br label %loop2, !dbg !9

loop2:
%j = phi i32 [ 0, %loop], [ %j.2, %loop2 ]
call void asm sideeffect "; inlineasm", "~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{q16},~{q17},~{q18},~{q19},~{q20},~{q21},~{q22},~{q23},~{q24},~{q25},~{q26},~{q27},~{q28},~{q29},~{q30},~{q31},~{x0},~{x1},~{x2},~{x3},~{x4},~{x5},~{x6},~{x7},~{x8},~{x9},~{x10},~{x11},~{x12},~{x13},~{x14},~{x15},~{x16},~{x17},~{x18},~{x19},~{x20},~{x21},~{x22},~{x23},~{x24},~{x25},~{x26},~{x27},~{x28},~{fp},~{lr},~{sp},~{memory}"() nounwind
%j.2 = add i32 %j, 1
%c2 = icmp slt i32 %j.2, 100
br i1 %c2, label %loop2, label %end2

end2:
call void asm sideeffect "; inlineasm", "~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{q16},~{q17},~{q18},~{q19},~{q20},~{q21},~{q22},~{q23},~{q24},~{q25},~{q26},~{q27},~{q28},~{q29},~{q30},~{q31},~{x0},~{x1},~{x2},~{x3},~{x4},~{x5},~{x6},~{x7},~{x8},~{x9},~{x10},~{x11},~{x12},~{x13},~{x14},~{x15},~{x16},~{x17},~{x18},~{x19},~{x20},~{x21},~{x22},~{x23},~{x24},~{x25},~{x26},~{x27},~{x28},~{fp},~{lr},~{sp},~{memory}"() nounwind
%i.2 = add i32 %i, 1
%c = icmp slt i32 %i.2, 100
br i1 %c, label %loop, label %end

end:
br label %loop3

loop3:
%k = phi i32 [ 0, %end], [ %k.2, %loop3 ]
call void asm sideeffect "; inlineasm", "~{q0},~{q1},~{q2},~{q3},~{q4},~{q5},~{q6},~{q7},~{q8},~{q9},~{q10},~{q11},~{q12},~{q13},~{q14},~{q15},~{q16},~{q17},~{q18},~{q19},~{q20},~{q21},~{q22},~{q23},~{q24},~{q25},~{q26},~{q27},~{q28},~{q29},~{q30},~{q31},~{x0},~{x1},~{x2},~{x3},~{x4},~{x5},~{x6},~{x7},~{x8},~{x9},~{x10},~{x11},~{x12},~{x13},~{x14},~{x15},~{x16},~{x17},~{x18},~{x19},~{x20},~{x21},~{x22},~{x23},~{x24},~{x25},~{x26},~{x27},~{x28},~{fp},~{lr},~{sp},~{memory}"() nounwind
%k.2 = add i32 %k, 1
%c3 = icmp slt i32 %k.2, 100
br i1 %c3, label %loop3, label %end3, !dbg !10

end3:
ret void
}

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4}
!llvm.ident = !{!5}

!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: NoDebug, enums: !2)
!1 = !DIFile(filename: "/tmp/kk.c", directory: "/tmp")
!2 = !{}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !{i32 1, !"PIC Level", i32 2}
!5 = !{!"clang version 3.9.0 "}
!6 = distinct !DISubprogram(name: "success", scope: !1, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2)
!7 = !DISubroutineType(types: !2)
!8 = !DILocation(line: 1, column: 20, scope: !6)
!9 = !DILocation(line: 2, column: 20, scope: !6)
!10 = !DILocation(line: 3, column: 20, scope: !6)
56 changes: 56 additions & 0 deletions test/Transforms/Inline/optimization-remarks-hotness-threshold.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
; RUN: opt < %s -S -inline -pass-remarks=inline \
; RUN: -pass-remarks-with-hotness 2>&1 | FileCheck %s

; RUN: opt < %s -S -passes=inline -pass-remarks-output=%t -pass-remarks=inline \
; RUN: -pass-remarks-with-hotness -pass-remarks-hotness-threshold=1 2>&1 | \
; RUN: FileCheck -allow-empty -check-prefix=THRESHOLD %s

; Check that when any threshold is specified we ignore remarks with no
; hotness -- these are blocks that have not been executed during training.

; 1 int foo() { return 1; }
; 2
; 3 int bar() {
; 4 return foo();
; 5 }

; CHECK: remark: /tmp/s.c:4:10: foo inlined into bar with cost={{[0-9\-]+}} (threshold={{[0-9]+}})
; THRESHOLD-NOT: remark

; ModuleID = '/tmp/s.c'
source_filename = "/tmp/s.c"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.11.0"

; Function Attrs: nounwind ssp uwtable
define i32 @foo() #0 !dbg !7 {
entry:
ret i32 1, !dbg !9
}

; Function Attrs: nounwind ssp uwtable
define i32 @bar() #0 !dbg !10 {
entry:
%call = call i32 @foo(), !dbg !11
ret i32 %call, !dbg !12
}

attributes #0 = { nounwind ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="core2" "target-features"="+cx16,+fxsr,+mmx,+sse,+sse2,+sse3,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4, !5}
!llvm.ident = !{!6}

!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 4.0.0 (trunk 282540) (llvm/trunk 282542)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)
!1 = !DIFile(filename: "/tmp/s.c", directory: "/tmp")
!2 = !{}
!3 = !{i32 2, !"Dwarf Version", i32 4}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{i32 1, !"PIC Level", i32 2}
!6 = !{!"clang version 4.0.0 (trunk 282540) (llvm/trunk 282542)"}
!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, variables: !2)
!8 = !DISubroutineType(types: !2)
!9 = !DILocation(line: 1, column: 13, scope: !7)
!10 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 3, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: true, unit: !0, variables: !2)
!11 = !DILocation(line: 4, column: 10, scope: !10)
!12 = !DILocation(line: 4, column: 3, scope: !10)

0 comments on commit 7cb910a

Please sign in to comment.