| 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 |
|
| 12 |
define i32 @_Z3sumii(i32 %x, i32 %y) #0 !dbg !6 { |
| 13 |
entry: |
| 14 |
%x.addr = alloca i32, align 4 |
| 15 |
%y.addr = alloca i32, align 4 |
| 16 |
store i32 %x, ptr %x.addr, align 4 |
| 17 |
store i32 %y, ptr %y.addr, align 4 |
| 18 |
%tmp = load i32, ptr %x.addr, align 4, !dbg !8 |
| 19 |
%tmp1 = load i32, ptr %y.addr, align 4, !dbg !8 |
| 20 |
%add = add nsw i32 %tmp, %tmp1, !dbg !8 |
| 21 |
%tmp2 = load i32, ptr %x.addr, align 4, !dbg !8 |
| 22 |
%tmp3 = load i32, ptr %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 |
|
| 27 |
define i32 @_Z3subii(i32 %x, i32 %y) #0 !dbg !9 { |
| 28 |
entry: |
| 29 |
%x.addr = alloca i32, align 4 |
| 30 |
%y.addr = alloca i32, align 4 |
| 31 |
store i32 %x, ptr %x.addr, align 4 |
| 32 |
store i32 %y, ptr %y.addr, align 4 |
| 33 |
%tmp = load i32, ptr %x.addr, align 4, !dbg !10 |
| 34 |
%tmp1 = load i32, ptr %y.addr, align 4, !dbg !10 |
| 35 |
%add = sub nsw i32 %tmp, %tmp1, !dbg !10 |
| 36 |
ret i32 %add, !dbg !11 |
| 37 |
} |
| 38 |
|
| 39 |
define i32 @main() #0 !dbg !12 { |
| 40 |
entry: |
| 41 |
%retval = alloca i32, align 4 |
| 42 |
%s = alloca i32, align 4 |
| 43 |
%i = alloca i32, align 4 |
| 44 |
store i32 0, ptr %retval |
| 45 |
store i32 0, ptr %i, align 4, !dbg !13 |
| 46 |
br label %while.cond, !dbg !14 |
| 47 |
|
| 48 |
while.cond: ; preds = %if.end, %entry |
| 49 |
%tmp = load i32, ptr %i, align 4, !dbg !15 |
| 50 |
%inc = add nsw i32 %tmp, 1, !dbg !15 |
| 51 |
store i32 %inc, ptr %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 |
|
| 55 |
while.body: ; preds = %while.cond |
| 56 |
%tmp1 = load i32, ptr %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 |
|
| 60 |
if.then: ; preds = %while.body |
| 61 |
%tmp2 = load i32, ptr %i, align 4, !dbg !19 |
| 62 |
%tmp3 = load i32, ptr %s, align 4, !dbg !19 |
| 63 |
%call = call i32 @_Z3sumii(i32 %tmp2, i32 %tmp3), !dbg !19 |
| 64 |
store i32 %call, ptr %s, align 4, !dbg !19 |
| 65 |
br label %if.end, !dbg !19 |
| 66 |
|
| 67 |
if.else: ; preds = %while.body |
| 68 |
store i32 30, ptr %s, align 4, !dbg !21 |
| 69 |
br label %if.end |
| 70 |
|
| 71 |
if.end: ; preds = %if.else, %if.then |
| 72 |
br label %while.cond, !dbg !23 |
| 73 |
|
| 74 |
while.end: ; preds = %while.cond |
| 75 |
%tmp4 = load i32, ptr %s, align 4, !dbg !25 |
| 76 |
%call2 = call i32 (ptr, ...) @printf(ptr @.str, i32 %tmp4), !dbg !25 |
| 77 |
ret i32 0, !dbg !26 |
| 78 |
} |
| 79 |
|
| 80 |
declare i32 @printf(ptr, ...) |
| 81 |
|
| 82 |
attributes #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 |