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