1; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/use-sample-profile-attr.prof -S | FileCheck %s 2; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/use-sample-profile-attr.prof -S | FileCheck %s 3 4@.str = private unnamed_addr constant [11 x i8] c"sum is %d\0A\00", align 1 5 6;; @goo doesn't have use-sample-profile attribute so it won't have 7;; profile annotated. 8; CHECK-NOT: @goo{{.*}} !prof 9define void @goo() !dbg !26 { 10 ret void 11} 12 13;; @foo has use-sample-profile attribute so it will have profile annotated. 14; CHECK: @foo{{.*}} !prof ![[HDRCNT1:[0-9]+]] 15define i32 @foo(i32 %x, i32 %y) #0 !dbg !4 { 16entry: 17 %x.addr = alloca i32, align 4 18 %y.addr = alloca i32, align 4 19 store i32 %x, i32* %x.addr, align 4 20 store i32 %y, i32* %y.addr, align 4 21 %0 = load i32, i32* %x.addr, align 4, !dbg !11 22 %1 = load i32, i32* %y.addr, align 4, !dbg !11 23 %add = add nsw i32 %0, %1, !dbg !11 24 ret i32 %add, !dbg !11 25} 26 27;; @main has use-sample-profile attribute so it will have profile annotated. 28; CHECK: @main{{.*}} !prof ![[HDRCNT2:[0-9]+]] 29define i32 @main() #1 !dbg !7 { 30entry: 31 %retval = alloca i32, align 4 32 %s = alloca i32, align 4 33 %i = alloca i32, align 4 34 store i32 0, i32* %retval 35 store i32 0, i32* %i, align 4, !dbg !12 36 br label %while.cond, !dbg !13 37 38while.cond: ; preds = %if.end, %entry 39 %0 = load i32, i32* %i, align 4, !dbg !14 40 %inc = add nsw i32 %0, 1, !dbg !14 41 store i32 %inc, i32* %i, align 4, !dbg !14 42 %cmp = icmp slt i32 %0, 400000000, !dbg !14 43 br i1 %cmp, label %while.body, label %while.end, !dbg !14 44 45while.body: ; preds = %while.cond 46 %1 = load i32, i32* %i, align 4, !dbg !16 47 %cmp1 = icmp ne i32 %1, 100, !dbg !16 48 br i1 %cmp1, label %if.then, label %if.else, !dbg !16 49 50 51if.then: ; preds = %while.body 52 %2 = load i32, i32* %i, align 4, !dbg !18 53 %3 = load i32, i32* %s, align 4, !dbg !18 54;; @foo is inlined because the callsite is hot and @foo has use-sample-profile 55;; attribute. 56; CHECK: if.then: 57; CHECK-NOT: call i32 @foo 58 %call = call i32 @foo(i32 %2, i32 %3), !dbg !18 59 store i32 %call, i32* %s, align 4, !dbg !18 60 br label %if.end, !dbg !18 61 62if.else: ; preds = %while.body 63;; @goo is not inlined because @goo doesn't have use-sample-profile attribute. 64; CHECK: if.else: 65; CHECK: call void @goo 66 call void @goo(), !dbg !27 67 store i32 30, i32* %s, align 4, !dbg !20 68 br label %if.end 69 70if.end: ; preds = %if.else, %if.then 71 br label %while.cond, !dbg !22 72 73while.end: ; preds = %while.cond 74 %4 = load i32, i32* %s, align 4, !dbg !24 75 %call2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i32 %4), !dbg !24 76 ret i32 0, !dbg !25 77} 78 79; CHECK: ![[HDRCNT1]] = !{!"function_entry_count", i64 11} 80; CHECK: ![[HDRCNT2]] = !{!"function_entry_count", i64 2} 81 82attributes #0 = {"use-sample-profile"} 83attributes #1 = {"use-sample-profile"} 84 85declare i32 @printf(i8*, ...) 86 87!llvm.dbg.cu = !{!0} 88!llvm.module.flags = !{!8, !9} 89!llvm.ident = !{!10} 90 91!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) 92!1 = !DIFile(filename: "calls.cc", directory: ".") 93!2 = !{} 94!4 = distinct !DISubprogram(name: "foo", line: 3, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 3, file: !1, scope: !5, type: !6, retainedNodes: !2) 95!5 = !DIFile(filename: "calls.cc", directory: ".") 96!6 = !DISubroutineType(types: !2) 97!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) 98!8 = !{i32 2, !"Dwarf Version", i32 4} 99!9 = !{i32 1, !"Debug Info Version", i32 3} 100!10 = !{!"clang version 3.5 "} 101!11 = !DILocation(line: 4, scope: !4) 102!12 = !DILocation(line: 8, scope: !7) 103!13 = !DILocation(line: 9, scope: !7) 104!14 = !DILocation(line: 9, scope: !15) 105!15 = !DILexicalBlockFile(discriminator: 2, file: !1, scope: !7) 106!16 = !DILocation(line: 10, scope: !17) 107!17 = distinct !DILexicalBlock(line: 10, column: 0, file: !1, scope: !7) 108!18 = !DILocation(line: 10, scope: !19) 109!19 = !DILexicalBlockFile(discriminator: 2, file: !1, scope: !17) 110!20 = !DILocation(line: 10, scope: !21) 111!21 = !DILexicalBlockFile(discriminator: 4, file: !1, scope: !17) 112!22 = !DILocation(line: 10, scope: !23) 113!23 = !DILexicalBlockFile(discriminator: 6, file: !1, scope: !17) 114!24 = !DILocation(line: 11, scope: !7) 115!25 = !DILocation(line: 12, scope: !7) 116!26 = distinct !DISubprogram(name: "goo", line: 11, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 3, file: !1, scope: !5, type: !6, retainedNodes: !2) 117!27 = !DILocation(line: 11, column: 20, scope: !7) 118