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-prefix=YAML < %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-prefix=YAML < %t.opt.yaml 5 6 ; Original test case. 7 ; 8 ; 1 #include <stdlib.h> 9 ; 2 10 ; 3 long long foo() { 11 ; 4 long long int sum = 0; 12 ; 5 for (int i = 0; i < 500000000; i++) 13 ; 6 if (i < 1000) 14 ; 7 sum -= i; 15 ; 8 else 16 ; 9 sum += -i * rand(); 17 ; 10 return sum; 18 ; 11 } 19 ; 12 20 ; 13 int main() { return foo() > 0; } 21 22 ; We are expecting foo() to be inlined in main() (almost all the cycles are 23 ; spent inside foo). 24 ; CHECK: remark: remarks.cc:13:21: inlined hot callee '_Z3foov' into 'main' 25 26 ; The back edge for the loop is the hottest edge in the loop subgraph. 27 ; CHECK: remark: remarks.cc:6:9: most popular destination for conditional branches at remarks.cc:5:3 28 29 ; The predicate almost always chooses the 'else' branch. 30 ; CHECK: remark: remarks.cc:9:15: most popular destination for conditional branches at remarks.cc:6:9 31 32 ; Checking to see if YAML file is generated and contains remarks 33 ;YAML: --- !Passed 34 ;YAML-NEXT: Pass: sample-profile 35 ;YAML-NEXT: Name: HotInline 36 ;YAML-NEXT: DebugLoc: { File: remarks.cc, Line: 13, Column: 21 } 37 ;YAML-NEXT: Function: main 38 ;YAML-NEXT: Args: 39 ;YAML-NEXT: - String: 'inlined hot callee ''' 40 ;YAML-NEXT: - Callee: _Z3foov 41 ;YAML-NEXT: DebugLoc: { File: remarks.cc, Line: 3, Column: 0 } 42 ;YAML-NEXT: - String: ''' into ''' 43 ;YAML-NEXT: - Caller: main 44 ;YAML-NEXT: DebugLoc: { File: remarks.cc, Line: 13, Column: 0 } 45 ;YAML-NEXT: - String: '''' 46 ;YAML-NEXT: ... 47 ;YAML: --- !Analysis 48 ;YAML-NEXT: Pass: sample-profile 49 ;YAML-NEXT: Name: AppliedSamples 50 ;YAML-NEXT: DebugLoc: { File: remarks.cc, Line: 5, Column: 8 } 51 ;YAML-NEXT: Function: main 52 ;YAML-NEXT: Args: 53 ;YAML-NEXT: - String: 'Applied ' 54 ;YAML-NEXT: - NumSamples: '18305' 55 ;YAML-NEXT: - String: ' samples from profile (offset: ' 56 ;YAML-NEXT: - LineOffset: '2' 57 ;YAML-NEXT: - String: ')' 58 ;YAML-NEXT: ... 59 ;YAML: --- !Passed 60 ;YAML-NEXT: Pass: sample-profile 61 ;YAML-NEXT: Name: PopularDest 62 ;YAML-NEXT: DebugLoc: { File: remarks.cc, Line: 6, Column: 9 } 63 ;YAML-NEXT: Function: main 64 ;YAML-NEXT: Args: 65 ;YAML-NEXT: - String: 'most popular destination for conditional branches at ' 66 ;YAML-NEXT: - CondBranchesLoc: 'remarks.cc:5:3' 67 ;YAML-NEXT: DebugLoc: { File: remarks.cc, Line: 5, Column: 3 } 68 ;YAML-NEXT: ... 69 70 ; Function Attrs: nounwind uwtable 71 define i64 @_Z3foov() #0 !dbg !4 { 72 entry: 73 %sum = alloca i64, align 8 74 %i = alloca i32, align 4 75 %0 = bitcast i64* %sum to i8*, !dbg !19 76 call void @llvm.lifetime.start.p0i8(i64 8, i8* %0) #4, !dbg !19 77 call void @llvm.dbg.declare(metadata i64* %sum, metadata !9, metadata !20), !dbg !21 78 store i64 0, i64* %sum, align 8, !dbg !21, !tbaa !22 79 %1 = bitcast i32* %i to i8*, !dbg !26 80 call void @llvm.lifetime.start.p0i8(i64 4, i8* %1) #4, !dbg !26 81 call void @llvm.dbg.declare(metadata i32* %i, metadata !10, metadata !20), !dbg !27 82 store i32 0, i32* %i, align 4, !dbg !27, !tbaa !28 83 br label %for.cond, !dbg !26 84 85 for.cond: ; preds = %for.inc, %entry 86 %2 = load i32, i32* %i, align 4, !dbg !30, !tbaa !28 87 %cmp = icmp slt i32 %2, 500000000, !dbg !34 88 br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !35 89 90 for.cond.cleanup: ; preds = %for.cond 91 %3 = bitcast i32* %i to i8*, !dbg !36 92 call void @llvm.lifetime.end.p0i8(i64 4, i8* %3) #4, !dbg !36 93 br label %for.end 94 95 for.body: ; preds = %for.cond 96 %4 = load i32, i32* %i, align 4, !dbg !38, !tbaa !28 97 %cmp1 = icmp slt i32 %4, 1000, !dbg !40 98 br i1 %cmp1, label %if.then, label %if.else, !dbg !41 99 100 if.then: ; preds = %for.body 101 %5 = load i32, i32* %i, align 4, !dbg !42, !tbaa !28 102 %conv = sext i32 %5 to i64, !dbg !42 103 %6 = load i64, i64* %sum, align 8, !dbg !43, !tbaa !22 104 %sub = sub nsw i64 %6, %conv, !dbg !43 105 store i64 %sub, i64* %sum, align 8, !dbg !43, !tbaa !22 106 br label %if.end, !dbg !44 107 108 if.else: ; preds = %for.body 109 %7 = load i32, i32* %i, align 4, !dbg !45, !tbaa !28 110 %sub2 = sub nsw i32 0, %7, !dbg !46 111 %call = call i32 @rand() #4, !dbg !47 112 %mul = mul nsw i32 %sub2, %call, !dbg !48 113 %conv3 = sext i32 %mul to i64, !dbg !46 114 %8 = load i64, i64* %sum, align 8, !dbg !49, !tbaa !22 115 %add = add nsw i64 %8, %conv3, !dbg !49 116 store i64 %add, i64* %sum, align 8, !dbg !49, !tbaa !22 117 br label %if.end 118 119 if.end: ; preds = %if.else, %if.then 120 br label %for.inc, !dbg !50 121 122 for.inc: ; preds = %if.end 123 %9 = load i32, i32* %i, align 4, !dbg !51, !tbaa !28 124 %inc = add nsw i32 %9, 1, !dbg !51 125 store i32 %inc, i32* %i, align 4, !dbg !51, !tbaa !28 126 br label %for.cond, !dbg !52 127 128 for.end: ; preds = %for.cond.cleanup 129 %10 = load i64, i64* %sum, align 8, !dbg !53, !tbaa !22 130 %11 = bitcast i64* %sum to i8*, !dbg !54 131 call void @llvm.lifetime.end.p0i8(i64 8, i8* %11) #4, !dbg !54 132 ret i64 %10, !dbg !55 133 } 134 135 ; Function Attrs: nounwind argmemonly 136 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1 137 138 ; Function Attrs: nounwind readnone 139 declare void @llvm.dbg.declare(metadata, metadata, metadata) #2 140 141 ; Function Attrs: nounwind 142 declare i32 @rand() #3 143 144 ; Function Attrs: nounwind argmemonly 145 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1 146 147 ; Function Attrs: nounwind uwtable 148 define i32 @main() #0 !dbg !13 { 149 entry: 150 %retval = alloca i32, align 4 151 store i32 0, i32* %retval, align 4 152 %call = call i64 @_Z3foov(), !dbg !56 153 %cmp = icmp sgt i64 %call, 0, !dbg !57 154 %conv = zext i1 %cmp to i32, !dbg !56 155 ret i32 %conv, !dbg !58 156 } 157 158 attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "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" } 159 attributes #1 = { nounwind argmemonly } 160 attributes #2 = { nounwind readnone } 161 attributes #3 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "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" } 162 attributes #4 = { nounwind } 163 164 !llvm.dbg.cu = !{!0} 165 !llvm.module.flags = !{!16, !17} 166 !llvm.ident = !{!18} 167 168 !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) 169 !1 = !DIFile(filename: "remarks.cc", directory: ".") 170 !2 = !{} 171 !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) 172 !5 = !DISubroutineType(types: !6) 173 !6 = !{!7} 174 !7 = !DIBasicType(name: "long long int", size: 64, align: 64, encoding: DW_ATE_signed) 175 !8 = !{!9, !10} 176 !9 = !DILocalVariable(name: "sum", scope: !4, file: !1, line: 4, type: !7) 177 !10 = !DILocalVariable(name: "i", scope: !11, file: !1, line: 5, type: !12) 178 !11 = distinct !DILexicalBlock(scope: !4, file: !1, line: 5, column: 3) 179 !12 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 180 !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) 181 !14 = !DISubroutineType(types: !15) 182 !15 = !{!12} 183 !16 = !{i32 2, !"Dwarf Version", i32 4} 184 !17 = !{i32 2, !"Debug Info Version", i32 3} 185 !18 = !{!"clang version 3.8.0 (trunk 251041) (llvm/trunk 251053)"} 186 !19 = !DILocation(line: 4, column: 3, scope: !4) 187 !20 = !DIExpression() 188 !21 = !DILocation(line: 4, column: 17, scope: !4) 189 !22 = !{!23, !23, i64 0} 190 !23 = !{!"long long", !24, i64 0} 191 !24 = !{!"omnipotent char", !25, i64 0} 192 !25 = !{!"Simple C/C++ TBAA"} 193 !26 = !DILocation(line: 5, column: 8, scope: !11) 194 !27 = !DILocation(line: 5, column: 12, scope: !11) 195 !28 = !{!29, !29, i64 0} 196 !29 = !{!"int", !24, i64 0} 197 !30 = !DILocation(line: 5, column: 19, scope: !31) 198 !31 = !DILexicalBlockFile(scope: !32, file: !1, discriminator: 3) 199 !32 = !DILexicalBlockFile(scope: !33, file: !1, discriminator: 1) 200 !33 = distinct !DILexicalBlock(scope: !11, file: !1, line: 5, column: 3) 201 !34 = !DILocation(line: 5, column: 21, scope: !33) 202 !35 = !DILocation(line: 5, column: 3, scope: !11) 203 !36 = !DILocation(line: 5, column: 3, scope: !37) 204 !37 = !DILexicalBlockFile(scope: !33, file: !1, discriminator: 2) 205 !38 = !DILocation(line: 6, column: 9, scope: !39) 206 !39 = distinct !DILexicalBlock(scope: !33, file: !1, line: 6, column: 9) 207 !40 = !DILocation(line: 6, column: 11, scope: !39) 208 !41 = !DILocation(line: 6, column: 9, scope: !33) 209 !42 = !DILocation(line: 7, column: 14, scope: !39) 210 !43 = !DILocation(line: 7, column: 11, scope: !39) 211 !44 = !DILocation(line: 7, column: 7, scope: !39) 212 !45 = !DILocation(line: 9, column: 15, scope: !39) 213 !46 = !DILocation(line: 9, column: 14, scope: !39) 214 !47 = !DILocation(line: 9, column: 19, scope: !39) 215 !48 = !DILocation(line: 9, column: 17, scope: !39) 216 !49 = !DILocation(line: 9, column: 11, scope: !39) 217 !50 = !DILocation(line: 6, column: 13, scope: !39) 218 !51 = !DILocation(line: 5, column: 35, scope: !33) 219 !52 = !DILocation(line: 5, column: 3, scope: !33) 220 !53 = !DILocation(line: 10, column: 10, scope: !4) 221 !54 = !DILocation(line: 11, column: 1, scope: !4) 222 !55 = !DILocation(line: 10, column: 3, scope: !4) 223 !56 = !DILocation(line: 13, column: 21, scope: !13) 224 !57 = !DILocation(line: 13, column: 27, scope: !13) 225 !58 = !DILocation(line: 13, column: 14, scope: !13) 226