1; Note that this needs new pass manager for now. Passing `-sample-profile-top-down-load` to legacy pass manager is a no-op. 2 3; Test we aren't doing specialization for inlining with default source order 4; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline-topdown.prof -sample-profile-top-down-load=false -S | FileCheck -check-prefix=DEFAULT %s 5 6; Test we specialize based on call path with context-sensitive profile while inlining with '-sample-profile-top-down-load' 7; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline-topdown.prof -sample-profile-merge-inlinee -sample-profile-top-down-load=true -S | FileCheck -check-prefix=TOPDOWN %s 8 9 10@.str = private unnamed_addr constant [11 x i8] c"sum is %d\0A\00", align 1 11 12define i32 @_Z3sumii(i32 %x, i32 %y) #0 !dbg !6 { 13entry: 14 %x.addr = alloca i32, align 4 15 %y.addr = alloca i32, align 4 16 store i32 %x, i32* %x.addr, align 4 17 store i32 %y, i32* %y.addr, align 4 18 %tmp = load i32, i32* %x.addr, align 4, !dbg !8 19 %tmp1 = load i32, i32* %y.addr, align 4, !dbg !8 20 %add = add nsw i32 %tmp, %tmp1, !dbg !8 21 %tmp2 = load i32, i32* %x.addr, align 4, !dbg !8 22 %tmp3 = load i32, i32* %y.addr, align 4, !dbg !8 23 %call = call i32 @_Z3subii(i32 %tmp2, i32 %tmp3), !dbg !8 24 ret i32 %add, !dbg !8 25} 26 27define i32 @_Z3subii(i32 %x, i32 %y) #0 !dbg !9 { 28entry: 29 %x.addr = alloca i32, align 4 30 %y.addr = alloca i32, align 4 31 store i32 %x, i32* %x.addr, align 4 32 store i32 %y, i32* %y.addr, align 4 33 %tmp = load i32, i32* %x.addr, align 4, !dbg !10 34 %tmp1 = load i32, i32* %y.addr, align 4, !dbg !10 35 %add = sub nsw i32 %tmp, %tmp1, !dbg !10 36 ret i32 %add, !dbg !11 37} 38 39define i32 @main() #0 !dbg !12 { 40entry: 41 %retval = alloca i32, align 4 42 %s = alloca i32, align 4 43 %i = alloca i32, align 4 44 store i32 0, i32* %retval 45 store i32 0, i32* %i, align 4, !dbg !13 46 br label %while.cond, !dbg !14 47 48while.cond: ; preds = %if.end, %entry 49 %tmp = load i32, i32* %i, align 4, !dbg !15 50 %inc = add nsw i32 %tmp, 1, !dbg !15 51 store i32 %inc, i32* %i, align 4, !dbg !15 52 %cmp = icmp slt i32 %tmp, 400000000, !dbg !15 53 br i1 %cmp, label %while.body, label %while.end, !dbg !15 54 55while.body: ; preds = %while.cond 56 %tmp1 = load i32, i32* %i, align 4, !dbg !17 57 %cmp1 = icmp ne i32 %tmp1, 100, !dbg !17 58 br i1 %cmp1, label %if.then, label %if.else, !dbg !17 59 60if.then: ; preds = %while.body 61 %tmp2 = load i32, i32* %i, align 4, !dbg !19 62 %tmp3 = load i32, i32* %s, align 4, !dbg !19 63 %call = call i32 @_Z3sumii(i32 %tmp2, i32 %tmp3), !dbg !19 64 store i32 %call, i32* %s, align 4, !dbg !19 65 br label %if.end, !dbg !19 66 67if.else: ; preds = %while.body 68 store i32 30, i32* %s, align 4, !dbg !21 69 br label %if.end 70 71if.end: ; preds = %if.else, %if.then 72 br label %while.cond, !dbg !23 73 74while.end: ; preds = %while.cond 75 %tmp4 = load i32, i32* %s, align 4, !dbg !25 76 %call2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i32 %tmp4), !dbg !25 77 ret i32 0, !dbg !26 78} 79 80declare i32 @printf(i8*, ...) 81 82attributes #0 = { "use-sample-profile" } 83 84!llvm.dbg.cu = !{!0} 85!llvm.module.flags = !{!3, !4} 86!llvm.ident = !{!5} 87 88!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.5 ", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2) 89!1 = !DIFile(filename: "calls.cc", directory: ".") 90!2 = !{} 91!3 = !{i32 2, !"Dwarf Version", i32 4} 92!4 = !{i32 1, !"Debug Info Version", i32 3} 93!5 = !{!"clang version 3.5 "} 94!6 = distinct !DISubprogram(name: "sum", scope: !1, file: !1, line: 3, type: !7, scopeLine: 3, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) 95!7 = !DISubroutineType(types: !2) 96!8 = !DILocation(line: 4, scope: !6) 97!9 = distinct !DISubprogram(name: "sub", scope: !1, file: !1, line: 20, type: !7, scopeLine: 20, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) 98!10 = !DILocation(line: 20, scope: !9) 99!11 = !DILocation(line: 21, scope: !9) 100!12 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 7, type: !7, scopeLine: 7, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) 101!13 = !DILocation(line: 8, scope: !12) 102!14 = !DILocation(line: 9, scope: !12) 103!15 = !DILocation(line: 9, scope: !16) 104!16 = !DILexicalBlockFile(scope: !12, file: !1, discriminator: 2) 105!17 = !DILocation(line: 10, scope: !18) 106!18 = distinct !DILexicalBlock(scope: !12, file: !1, line: 10) 107!19 = !DILocation(line: 10, scope: !20) 108!20 = !DILexicalBlockFile(scope: !18, file: !1, discriminator: 2) 109!21 = !DILocation(line: 10, scope: !22) 110!22 = !DILexicalBlockFile(scope: !18, file: !1, discriminator: 4) 111!23 = !DILocation(line: 10, scope: !24) 112!24 = !DILexicalBlockFile(scope: !18, file: !1, discriminator: 6) 113!25 = !DILocation(line: 11, scope: !12) 114!26 = !DILocation(line: 12, scope: !12) 115 116 117; DEFAULT: @_Z3sumii 118; DEFAULT-NOT: call i32 @_Z3subii 119; DEFAULT: @main() 120; DEFAULT-NOT: call i32 @_Z3subii 121 122; TOPDOWN: @_Z3sumii 123; TOPDOWN-NOT: call i32 @_Z3subii 124; TOPDOWN: @main() 125; TOPDOWN: call i32 @_Z3subii 126