1; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/remarks.prof -S -pass-remarks=sample-profile -pass-remarks-output=%t.opt.yaml 2>&1 | FileCheck %s 2; RUN: FileCheck %s -check-prefixes=YAML,YAML-NO-ANNOTATE < %t.opt.yaml 3; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/remarks.prof -S -pass-remarks=sample-profile -pass-remarks-output=%t.opt.yaml 2>&1 | FileCheck %s 4; RUN: FileCheck %s -check-prefixes=YAML,YAML-NO-ANNOTATE < %t.opt.yaml 5 6; RUN: opt < %s -sample-profile -annotate-sample-profile-inline-phase -sample-profile-file=%S/Inputs/remarks.prof -S -pass-remarks=sample-profile -pass-remarks-output=%t.opt.yaml 2>&1 | FileCheck %s 7; RUN: FileCheck %s -check-prefixes=YAML,YAML-ANNOTATE < %t.opt.yaml 8; RUN: opt < %s -passes=sample-profile -annotate-sample-profile-inline-phase -sample-profile-file=%S/Inputs/remarks.prof -S -pass-remarks=sample-profile -pass-remarks-output=%t.opt.yaml 2>&1 | FileCheck %s 9; RUN: FileCheck %s -check-prefixes=YAML,YAML-ANNOTATE < %t.opt.yaml 10 11; Original test case. 12; 13; 1 #include <stdlib.h> 14; 2 15; 3 long long foo() { 16; 4 long long int sum = 0; 17; 5 for (int i = 0; i < 500000000; i++) 18; 6 if (i < 1000) 19; 7 sum -= i; 20; 8 else 21; 9 sum += -i * rand(); 22; 10 return sum; 23; 11 } 24; 12 25; 13 int main() { return foo() > 0; } 26 27; We are expecting foo() to be inlined in main() (almost all the cycles are 28; spent inside foo). 29; CHECK: remark: remarks.cc:13:21: '_Z3foov' inlined into 'main' to match profiling context with (cost=130, threshold=2147483647) at callsite main:0:21; 30; CHECK: remark: remarks.cc:9:19: 'rand' inlined into 'main' to match profiling context with (cost=always): always inline attribute at callsite _Z3foov:6:19 @ main:0:21; 31 32; The back edge for the loop is the hottest edge in the loop subgraph. 33; CHECK: remark: remarks.cc:6:9: most popular destination for conditional branches at remarks.cc:5:3 34 35; The predicate almost always chooses the 'else' branch. 36; CHECK: remark: remarks.cc:9:15: most popular destination for conditional branches at remarks.cc:6:9 37 38; Checking to see if YAML file is generated and contains remarks 39;YAML: --- !Passed 40;YAML-NO-ANNOTATE-NEXT: Pass: sample-profile-inline 41;YAML-ANNOTATE-NEXT: Pass: main-sample-profile-inline 42;YAML-NEXT: Name: Inlined 43;YAML-NEXT: DebugLoc: { File: remarks.cc, Line: 13, Column: 21 } 44;YAML-NEXT: Function: main 45;YAML-NEXT: Args: 46;YAML-NEXT: - String: '''' 47;YAML-NEXT: - Callee: _Z3foov 48;YAML-NEXT: DebugLoc: { File: remarks.cc, Line: 3, Column: 0 } 49;YAML-NEXT: - String: ''' inlined into ' 50;YAML-NEXT: - Caller: main 51;YAML-NEXT: DebugLoc: { File: remarks.cc, Line: 13, Column: 0 } 52;YAML-NEXT: - String: '''' 53;YAML-NEXT: - String: ' to match profiling context' 54;YAML-NEXT: - String: ' with ' 55;YAML-NEXT: - String: '(cost=' 56;YAML-NEXT: - Cost: '130' 57;YAML-NEXT: - String: ', threshold=' 58;YAML-NEXT: - Threshold: '2147483647' 59;YAML-NEXT: - String: ')' 60;YAML-NEXT: - String: ' at callsite ' 61;YAML-NEXT: - String: main 62;YAML-NEXT: - String: ':' 63;YAML-NEXT: - Line: '0' 64;YAML-NEXT: - String: ':' 65;YAML-NEXT: - Column: '21' 66;YAML-NEXT: - String: ';' 67;YAML-NEXT: ... 68;YAML: --- !Passed 69;YAML-NO-ANNOTATE-NEXT: Pass: sample-profile-inline 70;YAML-ANNOTATE-NEXT: Pass: main-sample-profile-inline 71;YAML-NEXT: Name: AlwaysInline 72;YAML-NEXT: DebugLoc: { File: remarks.cc, Line: 9, Column: 19 } 73;YAML-NEXT: Function: main 74;YAML-NEXT: Args: 75;YAML-NEXT: - String: '''' 76;YAML-NEXT: - Callee: rand 77;YAML-NEXT: DebugLoc: { File: remarks.cc, Line: 90, Column: 0 } 78;YAML-NEXT: - String: ''' inlined into ''' 79;YAML-NEXT: - Caller: main 80;YAML-NEXT: DebugLoc: { File: remarks.cc, Line: 13, Column: 0 } 81;YAML-NEXT: - String: '''' 82;YAML-NEXT: - String: ' to match profiling context' 83;YAML-NEXT: - String: ' with ' 84;YAML-NEXT: - String: '(cost=always)' 85;YAML-NEXT: - String: ': ' 86;YAML-NEXT: - Reason: always inline attribute 87;YAML-NEXT: - String: ' at callsite ' 88;YAML-NEXT: - String: _Z3foov 89;YAML-NEXT: - String: ':' 90;YAML-NEXT: - Line: '6' 91;YAML-NEXT: - String: ':' 92;YAML-NEXT: - Column: '19' 93;YAML-NEXT: - String: ' @ ' 94;YAML-NEXT: - String: main 95;YAML-NEXT: - String: ':' 96;YAML-NEXT: - Line: '0' 97;YAML-NEXT: - String: ':' 98;YAML-NEXT: - Column: '21' 99;YAML-NEXT: - String: ';' 100;YAML: --- !Analysis 101;YAML-NEXT: Pass: sample-profile 102;YAML-NEXT: Name: AppliedSamples 103;YAML-NEXT: DebugLoc: { File: remarks.cc, Line: 5, Column: 8 } 104;YAML-NEXT: Function: main 105;YAML-NEXT: Args: 106;YAML-NEXT: - String: 'Applied ' 107;YAML-NEXT: - NumSamples: '18305' 108;YAML-NEXT: - String: ' samples from profile (offset: ' 109;YAML-NEXT: - LineOffset: '2' 110;YAML-NEXT: - String: ')' 111;YAML-NEXT: ... 112;YAML: --- !Passed 113;YAML-NEXT: Pass: sample-profile 114;YAML-NEXT: Name: PopularDest 115;YAML-NEXT: DebugLoc: { File: remarks.cc, Line: 6, Column: 9 } 116;YAML-NEXT: Function: main 117;YAML-NEXT: Args: 118;YAML-NEXT: - String: 'most popular destination for conditional branches at ' 119;YAML-NEXT: - CondBranchesLoc: 'remarks.cc:5:3' 120;YAML-NEXT: DebugLoc: { File: remarks.cc, Line: 5, Column: 3 } 121;YAML-NEXT: ... 122 123; Function Attrs: nounwind uwtable 124define i64 @_Z3foov() #0 !dbg !4 { 125entry: 126 %sum = alloca i64, align 8 127 %i = alloca i32, align 4 128 %0 = bitcast i64* %sum to i8*, !dbg !19 129 call void @llvm.lifetime.start.p0i8(i64 8, i8* %0) #4, !dbg !19 130 call void @llvm.dbg.declare(metadata i64* %sum, metadata !9, metadata !20), !dbg !21 131 store i64 0, i64* %sum, align 8, !dbg !21, !tbaa !22 132 %1 = bitcast i32* %i to i8*, !dbg !26 133 call void @llvm.lifetime.start.p0i8(i64 4, i8* %1) #4, !dbg !26 134 call void @llvm.dbg.declare(metadata i32* %i, metadata !10, metadata !20), !dbg !27 135 store i32 0, i32* %i, align 4, !dbg !27, !tbaa !28 136 br label %for.cond, !dbg !26 137 138for.cond: ; preds = %for.inc, %entry 139 %2 = load i32, i32* %i, align 4, !dbg !30, !tbaa !28 140 %cmp = icmp slt i32 %2, 500000000, !dbg !34 141 br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !35 142 143for.cond.cleanup: ; preds = %for.cond 144 %3 = bitcast i32* %i to i8*, !dbg !36 145 call void @llvm.lifetime.end.p0i8(i64 4, i8* %3) #4, !dbg !36 146 br label %for.end 147 148for.body: ; preds = %for.cond 149 %4 = load i32, i32* %i, align 4, !dbg !38, !tbaa !28 150 %cmp1 = icmp slt i32 %4, 1000, !dbg !40 151 br i1 %cmp1, label %if.then, label %if.else, !dbg !41 152 153if.then: ; preds = %for.body 154 %5 = load i32, i32* %i, align 4, !dbg !42, !tbaa !28 155 %conv = sext i32 %5 to i64, !dbg !42 156 %6 = load i64, i64* %sum, align 8, !dbg !43, !tbaa !22 157 %sub = sub nsw i64 %6, %conv, !dbg !43 158 store i64 %sub, i64* %sum, align 8, !dbg !43, !tbaa !22 159 br label %if.end, !dbg !44 160 161if.else: ; preds = %for.body 162 %7 = load i32, i32* %i, align 4, !dbg !45, !tbaa !28 163 %sub2 = sub nsw i32 0, %7, !dbg !46 164 %call = call i32 @rand() #4, !dbg !47 165 %mul = mul nsw i32 %sub2, %call, !dbg !48 166 %conv3 = sext i32 %mul to i64, !dbg !46 167 %8 = load i64, i64* %sum, align 8, !dbg !49, !tbaa !22 168 %add = add nsw i64 %8, %conv3, !dbg !49 169 store i64 %add, i64* %sum, align 8, !dbg !49, !tbaa !22 170 br label %if.end 171 172if.end: ; preds = %if.else, %if.then 173 br label %for.inc, !dbg !50 174 175for.inc: ; preds = %if.end 176 %9 = load i32, i32* %i, align 4, !dbg !51, !tbaa !28 177 %inc = add nsw i32 %9, 1, !dbg !51 178 store i32 %inc, i32* %i, align 4, !dbg !51, !tbaa !28 179 br label %for.cond, !dbg !52 180 181for.end: ; preds = %for.cond.cleanup 182 %10 = load i64, i64* %sum, align 8, !dbg !53, !tbaa !22 183 %11 = bitcast i64* %sum to i8*, !dbg !54 184 call void @llvm.lifetime.end.p0i8(i64 8, i8* %11) #4, !dbg !54 185 ret i64 %10, !dbg !55 186} 187 188; Function Attrs: nounwind argmemonly 189declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1 190 191; Function Attrs: nounwind readnone 192declare void @llvm.dbg.declare(metadata, metadata, metadata) #2 193 194; Function Attrs: nounwind 195define i32 @rand() #3 !dbg !59 { 196 ret i32 1 197} 198 199; Function Attrs: nounwind argmemonly 200declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1 201 202; Function Attrs: nounwind uwtable 203define i32 @main() #0 !dbg !13 { 204entry: 205 %retval = alloca i32, align 4 206 store i32 0, i32* %retval, align 4 207 %call = call i64 @_Z3foov(), !dbg !56 208 %cmp = icmp sgt i64 %call, 0, !dbg !57 209 %conv = zext i1 %cmp to i32, !dbg !56 210 ret i32 %conv, !dbg !58 211} 212 213attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" "use-sample-profile" } 214attributes #1 = { nounwind argmemonly } 215attributes #2 = { nounwind readnone } 216attributes #3 = { nounwind alwaysinline "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } 217attributes #4 = { nounwind } 218 219!llvm.dbg.cu = !{!0} 220!llvm.module.flags = !{!16, !17} 221!llvm.ident = !{!18} 222 223!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 251041) (llvm/trunk 251053)", isOptimized: true, runtimeVersion: 0, emissionKind: NoDebug, enums: !2) 224!1 = !DIFile(filename: "remarks.cc", directory: ".") 225!2 = !{} 226!4 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file: !1, line: 3, type: !5, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !8) 227!5 = !DISubroutineType(types: !6) 228!6 = !{!7} 229!7 = !DIBasicType(name: "long long int", size: 64, align: 64, encoding: DW_ATE_signed) 230!8 = !{!9, !10} 231!9 = !DILocalVariable(name: "sum", scope: !4, file: !1, line: 4, type: !7) 232!10 = !DILocalVariable(name: "i", scope: !11, file: !1, line: 5, type: !12) 233!11 = distinct !DILexicalBlock(scope: !4, file: !1, line: 5, column: 3) 234!12 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 235!13 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 13, type: !14, isLocal: false, isDefinition: true, scopeLine: 13, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2) 236!14 = !DISubroutineType(types: !15) 237!15 = !{!12} 238!16 = !{i32 2, !"Dwarf Version", i32 4} 239!17 = !{i32 2, !"Debug Info Version", i32 3} 240!18 = !{!"clang version 3.8.0 (trunk 251041) (llvm/trunk 251053)"} 241!19 = !DILocation(line: 4, column: 3, scope: !4) 242!20 = !DIExpression() 243!21 = !DILocation(line: 4, column: 17, scope: !4) 244!22 = !{!23, !23, i64 0} 245!23 = !{!"long long", !24, i64 0} 246!24 = !{!"omnipotent char", !25, i64 0} 247!25 = !{!"Simple C/C++ TBAA"} 248!26 = !DILocation(line: 5, column: 8, scope: !11) 249!27 = !DILocation(line: 5, column: 12, scope: !11) 250!28 = !{!29, !29, i64 0} 251!29 = !{!"int", !24, i64 0} 252!30 = !DILocation(line: 5, column: 19, scope: !31) 253!31 = !DILexicalBlockFile(scope: !32, file: !1, discriminator: 3) 254!32 = !DILexicalBlockFile(scope: !33, file: !1, discriminator: 1) 255!33 = distinct !DILexicalBlock(scope: !11, file: !1, line: 5, column: 3) 256!34 = !DILocation(line: 5, column: 21, scope: !33) 257!35 = !DILocation(line: 5, column: 3, scope: !11) 258!36 = !DILocation(line: 5, column: 3, scope: !37) 259!37 = !DILexicalBlockFile(scope: !33, file: !1, discriminator: 2) 260!38 = !DILocation(line: 6, column: 9, scope: !39) 261!39 = distinct !DILexicalBlock(scope: !33, file: !1, line: 6, column: 9) 262!40 = !DILocation(line: 6, column: 11, scope: !39) 263!41 = !DILocation(line: 6, column: 9, scope: !33) 264!42 = !DILocation(line: 7, column: 14, scope: !39) 265!43 = !DILocation(line: 7, column: 11, scope: !39) 266!44 = !DILocation(line: 7, column: 7, scope: !39) 267!45 = !DILocation(line: 9, column: 15, scope: !39) 268!46 = !DILocation(line: 9, column: 14, scope: !39) 269!47 = !DILocation(line: 9, column: 19, scope: !39) 270!48 = !DILocation(line: 9, column: 17, scope: !39) 271!49 = !DILocation(line: 9, column: 11, scope: !39) 272!50 = !DILocation(line: 6, column: 13, scope: !39) 273!51 = !DILocation(line: 5, column: 35, scope: !33) 274!52 = !DILocation(line: 5, column: 3, scope: !33) 275!53 = !DILocation(line: 10, column: 10, scope: !4) 276!54 = !DILocation(line: 11, column: 1, scope: !4) 277!55 = !DILocation(line: 10, column: 3, scope: !4) 278!56 = !DILocation(line: 13, column: 21, scope: !13) 279!57 = !DILocation(line: 13, column: 27, scope: !13) 280!58 = !DILocation(line: 13, column: 14, scope: !13) 281!59 = distinct !DISubprogram(name: "rand", linkageName: "rand", scope: !1, file: !1, line: 90, type: !5, isLocal: false, isDefinition: true, scopeLine: 90, flags: DIFlagPrototyped, isOptimized: true, unit: !0) 282