1; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/profsampleacc.extbinary.afdo -profile-summary-cutoff-hot=900000 -profile-sample-accurate -S | FileCheck %s --check-prefix=CALL_SUM_IS_HOT 2 3; RUN: llvm-profdata merge -sample -extbinary -prof-sym-list=%S/Inputs/profile-symbol-list.text %S/Inputs/profsampleacc.extbinary.afdo -o %t.symlist.afdo 4; RUN: opt < %s -passes=sample-profile -sample-profile-file=%t.symlist.afdo -profile-summary-cutoff-hot=600000 -profile-accurate-for-symsinlist -S | FileCheck %s --check-prefix=PROFSYMLIST 5; RUN: opt < %s -passes=sample-profile -sample-profile-file=%t.symlist.afdo -profile-accurate-for-symsinlist -profile-symbol-list-cutoff=2 -S | FileCheck %s --check-prefix=PSLCUTOFF2 6; RUN: opt < %s -passes=sample-profile -sample-profile-file=%t.symlist.afdo -profile-accurate-for-symsinlist -profile-symbol-list-cutoff=3 -S | FileCheck %s --check-prefix=PSLCUTOFF3 7; 8; If -profile-accurate-for-symsinlist and -profile-sample-accurate both present, 9; -profile-sample-accurate will override -profile-accurate-for-symsinlist. 10; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/profsampleacc.extbinary.afdo -profile-summary-cutoff-hot=900000 -profile-sample-accurate -profile-accurate-for-symsinlist -S | FileCheck %s --check-prefix=CALL_SUM_IS_HOT 11; 12; Original C++ test case 13; 14; #include <stdio.h> 15; 16; int sum(int x, int y) { 17; return x + y; 18; } 19; 20; int main() { 21; int s, i = 0; 22; while (i++ < 20000 * 20000) 23; if (i != 100) s = sum(i, s); else s = 30; 24; printf("sum is %d\n", s); 25; return 0; 26; } 27; 28@.str = private unnamed_addr constant [11 x i8] c"sum is %d\0A\00", align 1 29 30; Check _Z3sumii's function entry count will be 0 when 31; profile-sample-accurate is enabled. 32; CALL_SUM_IS_HOT: define i32 @_Z3sumii{{.*}}!prof ![[ZERO_ID:[0-9]+]] 33; 34; Check _Z3sumii's function entry count will be nonzero when 35; profile-sample-accurate is enabled because the callsite is warm and not 36; inlined so its function entry count is adjusted to nonzero. 37; CALL_SUM_IS_WARM: define i32 @_Z3sumii{{.*}}!prof ![[NONZERO_ID:[0-9]+]] 38; 39; Check _Z3sumii's function entry count will be initialized to -1 when 40; profile-accurate-for-profsymlist is enabled and _Z3sumii exists in the 41; profile symbol list because it also shows up in the profile as inline 42; instance. 43; PROFSYMLIST: define i32 @_Z3sumii{{.*}}!prof ![[UNKNOWN_ID:[0-9]+]] 44; 45; Function Attrs: nounwind uwtable 46define i32 @_Z3sumii(i32 %x, i32 %y) #0 !dbg !4 { 47entry: 48 %x.addr = alloca i32, align 4 49 %y.addr = alloca i32, align 4 50 store i32 %x, ptr %x.addr, align 4 51 store i32 %y, ptr %y.addr, align 4 52 %0 = load i32, ptr %x.addr, align 4, !dbg !11 53 %1 = load i32, ptr %y.addr, align 4, !dbg !11 54 %add = add nsw i32 %0, %1, !dbg !11 55 ret i32 %add, !dbg !11 56} 57 58; Check -profile-symbol-list-cutoff=3 will include _Z3toov into profile 59; symbol list and -profile-symbol-list-cutoff=2 will not. 60; PSLCUTOFF2: define i32 @_Z3toov{{.*}}!prof ![[TOO_ID:[0-9]+]] 61; PSLCUTOFF3: define i32 @_Z3toov{{.*}}!prof ![[TOO_ID:[0-9]+]] 62define i32 @_Z3toov(i32 %x, i32 %y) #0 { 63entry: 64 %add = add nsw i32 %x, %y 65 ret i32 %add 66} 67 68; Function Attrs: uwtable 69define i32 @main() #0 !dbg !7 { 70entry: 71 %retval = alloca i32, align 4 72 %s = alloca i32, align 4 73 %i = alloca i32, align 4 74 store i32 0, ptr %retval 75 store i32 0, ptr %i, align 4, !dbg !12 76 br label %while.cond, !dbg !13 77 78while.cond: ; preds = %if.end, %entry 79 %0 = load i32, ptr %i, align 4, !dbg !14 80 %inc = add nsw i32 %0, 1, !dbg !14 81 store i32 %inc, ptr %i, align 4, !dbg !14 82 %cmp = icmp slt i32 %0, 400000000, !dbg !14 83 br i1 %cmp, label %while.body, label %while.end, !dbg !14 84 85while.body: ; preds = %while.cond 86 %1 = load i32, ptr %i, align 4, !dbg !16 87 %cmp1 = icmp ne i32 %1, 100, !dbg !16 88 br i1 %cmp1, label %if.then, label %if.else, !dbg !16 89 90; With the hot cutoff being set to 600000, the inline instance of _Z3sumii 91; in main is neither hot nor cold. Check it won't be inlined when 92; profile-sample-accurate is enabled. 93; CALL_SUM_IS_WARM: if.then: 94; CALL_SUM_IS_WARM: call i32 @_Z3sumii 95; CALL_SUM_IS_WARM: if.else: 96; 97; With the hot cutoff being set to 900000, the inline instance of _Z3sumii 98; in main is hot. Check the callsite of _Z3sumii will be inlined when 99; profile-sample-accurate is enabled. 100; CALL_SUM_IS_HOT: if.then: 101; CALL_SUM_IS_HOT-NOT: call i32 @_Z3sumii 102; CALL_SUM_IS_HOT: if.else: 103; 104; Check _Z3sumii will be inlined when profile-accurate-for-profsymlist is 105; enabled 106; PROFSYMLIST: if.then: 107; PROFSYMLIST-NOT: call i32 @_Z3sumii 108; PROFSYMLIST: if.else: 109if.then: ; preds = %while.body 110 %2 = load i32, ptr %i, align 4, !dbg !18 111 %3 = load i32, ptr %s, align 4, !dbg !18 112 %call = call i32 @_Z3sumii(i32 %2, i32 %3), !dbg !18 113 store i32 %call, ptr %s, align 4, !dbg !18 114 br label %if.end, !dbg !18 115 116if.else: ; preds = %while.body 117 store i32 30, ptr %s, align 4, !dbg !20 118 br label %if.end 119 120if.end: ; preds = %if.else, %if.then 121 br label %while.cond, !dbg !22 122 123while.end: ; preds = %while.cond 124 %4 = load i32, ptr %s, align 4, !dbg !24 125 %call2 = call i32 (ptr, ...) @printf(ptr @.str, i32 %4), !dbg !24 126 ret i32 0, !dbg !25 127} 128 129declare i32 @printf(ptr, ...) #2 130 131attributes #0 = { "use-sample-profile" } 132 133!llvm.dbg.cu = !{!0} 134!llvm.module.flags = !{!8, !9} 135!llvm.ident = !{!10} 136 137; CALL_SUM_IS_HOT: ![[ZERO_ID]] = !{!"function_entry_count", i64 0} 138; CALL_SUM_IS_WARM: ![[NONZERO_ID]] = !{!"function_entry_count", i64 5179} 139; PROFSYMLIST: ![[UNKNOWN_ID]] = !{!"function_entry_count", i64 -1} 140; PSLCUTOFF2: ![[TOO_ID]] = !{!"function_entry_count", i64 -1} 141; PSLCUTOFF3: ![[TOO_ID]] = !{!"function_entry_count", i64 0} 142!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5 ", isOptimized: false, emissionKind: NoDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2) 143!1 = !DIFile(filename: "calls.cc", directory: ".") 144!2 = !{} 145!4 = distinct !DISubprogram(name: "sum", line: 3, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 3, file: !1, scope: !5, type: !6, retainedNodes: !2) 146!5 = !DIFile(filename: "calls.cc", directory: ".") 147!6 = !DISubroutineType(types: !2) 148!7 = distinct !DISubprogram(name: "main", line: 7, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 7, file: !1, scope: !5, type: !6, retainedNodes: !2) 149!8 = !{i32 2, !"Dwarf Version", i32 4} 150!9 = !{i32 1, !"Debug Info Version", i32 3} 151!10 = !{!"clang version 3.5 "} 152!11 = !DILocation(line: 4, scope: !4) 153!12 = !DILocation(line: 8, scope: !7) 154!13 = !DILocation(line: 9, scope: !7) 155!14 = !DILocation(line: 9, scope: !15) 156!15 = !DILexicalBlockFile(discriminator: 2, file: !1, scope: !7) 157!16 = !DILocation(line: 10, scope: !17) 158!17 = distinct !DILexicalBlock(line: 10, column: 0, file: !1, scope: !7) 159!18 = !DILocation(line: 10, scope: !19) 160!19 = !DILexicalBlockFile(discriminator: 2, file: !1, scope: !17) 161!20 = !DILocation(line: 10, scope: !21) 162!21 = !DILexicalBlockFile(discriminator: 4, file: !1, scope: !17) 163!22 = !DILocation(line: 10, scope: !23) 164!23 = !DILexicalBlockFile(discriminator: 6, file: !1, scope: !17) 165!24 = !DILocation(line: 11, scope: !7) 166!25 = !DILocation(line: 12, scope: !7) 167