234 lines · plain
1; REQUIRES: asserts2; Test for CSSPGO's SampleContextTracker to make sure context profile tree is promoted and merged properly3; based on inline decision, so post inline counts are accurate.4 5;; The order of nodes within Context Profile Tree depends on the implmementation of std::hash<std::string>.6;; Using check-dag instead of check-next.7 8 9; Note that we need new pass manager to enable top-down processing for sample profile loader10; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/profile-context-tracker.prof -sample-profile-inline-size -sample-profile-cold-inline-threshold=200 -debug-only=sample-context-tracker -o /dev/null 2>&1 | FileCheck %s --check-prefix=INLINE-ALL11; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/profile-context-tracker.prof -sample-profile-prioritized-inline=0 -sample-profile-inline-size=0 -debug-only=sample-context-tracker -o /dev/null 2>&1 | FileCheck %s --check-prefix=INLINE-HOT12 13 14; Test we inlined the following in top-down order and promot rest not inlined context profile into base profile15; main:3 @ _Z5funcAi16; main:3 @ _Z5funcAi:1 @ _Z8funcLeafi17; _Z5funcBi:1 @ _Z8funcLeafi18; INLINE-ALL: Getting base profile for function: main19; INLINE-ALL-NEXT: Merging context profile into base profile: main20; INLINE-ALL-NEXT: Found context tree root to promote: external:12 @ main21; INLINE-ALL-NEXT: Context promoted and merged to: main22; INLINE-ALL-NEXT: Getting callee context for instr: %call = tail call i32 @_Z5funcBi23; INLINE-ALL-NEXT: Callee context found: main:3.1 @ _Z5funcBi24; INLINE-ALL-NEXT: Getting callee context for instr: %call1 = tail call i32 @_Z5funcAi25; INLINE-ALL-NEXT: Callee context found: main:3 @ _Z5funcAi26; INLINE-ALL-NEXT: Marking context profile as inlined: main:3 @ _Z5funcAi27; INLINE-ALL-NEXT: Getting callee context for instr: %call.i = tail call i32 @_Z8funcLeafi28; INLINE-ALL-NEXT: Callee context found: main:3 @ _Z5funcAi:1 @ _Z8funcLeafi29; INLINE-ALL-NEXT: Marking context profile as inlined: main:3 @ _Z5funcAi:1 @ _Z8funcLeafi30; INLINE-ALL-NEXT: Getting callee context for instr: %call.i2 = tail call i32 @_Z3fibi31; INLINE-ALL-NEXT: Getting callee context for instr: %call5.i = tail call i32 @_Z3fibi32; INLINE-ALL-DAG: Getting base profile for function: _Z5funcAi33; INLINE-ALL-DAG-NEXT: Merging context profile into base profile: _Z5funcAi34; INLINE-ALL-DAG: Getting base profile for function: _Z5funcBi35; INLINE-ALL-DAG-NEXT: Merging context profile into base profile: _Z5funcBi36; INLINE-ALL-DAG-NEXT: Found context tree root to promote: external:10 @ _Z5funcBi37; INLINE-ALL-DAG-NEXT: Context promoted to: _Z5funcBi38; INLINE-ALL-DAG-NEXT: Found context tree root to promote: externalA:17 @ _Z5funcBi39; INLINE-ALL-DAG-NEXT: Context promoted and merged to: _Z5funcBi40; INLINE-ALL-DAG-NEXT: Found context tree root to promote: main:3.1 @ _Z5funcBi41; INLINE-ALL-DAG-NEXT: Context promoted and merged to: _Z5funcBi42; INLINE-ALL-DAG-NEXT: Context promoted to: _Z5funcBi:1 @ _Z8funcLeafi43; INLINE-ALL-DAG-NEXT: Getting callee context for instr: %call = tail call i32 @_Z8funcLeafi44; INLINE-ALL-DAG-NEXT: Callee context found: _Z5funcBi:1 @ _Z8funcLeafi45; INLINE-ALL-DAG-NEXT: Marking context profile as inlined: _Z5funcBi:1 @ _Z8funcLeafi46; INLINE-ALL-DAG-NEXT: Getting callee context for instr: %call.i = tail call i32 @_Z3fibi47; INLINE-ALL-DAG-NEXT: Getting callee context for instr: %call5.i = tail call i32 @_Z3fibi48; INLINE-ALL: Getting base profile for function: _Z8funcLeafi49; INLINE-ALL-NEXT: Merging context profile into base profile: _Z8funcLeafi50 51; Test we inlined the following in top-down order and promot rest not inlined context profile into base profile52; _Z5funcAi:1 @ _Z8funcLeafi53; _Z5funcBi:1 @ _Z8funcLeafi54; INLINE-HOT: Getting base profile for function: main55; INLINE-HOT-NEXT: Merging context profile into base profile: main56; INLINE-HOT-NEXT: Found context tree root to promote: external:12 @ main57; INLINE-HOT-NEXT: Context promoted and merged to: main58; INLINE-HOT-NEXT: Getting callee context for instr: %call = tail call i32 @_Z5funcBi59; INLINE-HOT-NEXT: Callee context found: main:3.1 @ _Z5funcBi60; INLINE-HOT-NEXT: Getting callee context for instr: %call1 = tail call i32 @_Z5funcAi61; INLINE-HOT-NEXT: Callee context found: main:3 @ _Z5funcAi62; INLINE-HOT-DAG: Getting base profile for function: _Z5funcAi63; INLINE-HOT-DAG-NEXT: Merging context profile into base profile: _Z5funcAi64; INLINE-HOT-DAG-NEXT: Found context tree root to promote: main:3 @ _Z5funcAi65; INLINE-HOT-DAG-NEXT: Context promoted to: _Z5funcAi66; INLINE-HOT-DAG-NEXT: Context promoted to: _Z5funcAi:1 @ _Z8funcLeafi67; INLINE-HOT-DAG-NEXT: Getting callee context for instr: %call = tail call i32 @_Z8funcLeafi(i32 %add), !dbg !5068; INLINE-HOT-DAG-NEXT: Callee context found: _Z5funcAi:1 @ _Z8funcLeafi69; INLINE-HOT-DAG-NEXT: Marking context profile as inlined: _Z5funcAi:1 @ _Z8funcLeafi70; INLINE-HOT-DAG-NEXT: Getting callee context for instr: %call.i = tail call i32 @_Z3fibi(i32 %tmp.i) #2, !dbg !6271; INLINE-HOT-DAG-NEXT: Getting callee context for instr: %call5.i = tail call i32 @_Z3fibi(i32 %tmp1.i) #2, !dbg !6972; INLINE-HOT-DAG: Getting base profile for function: _Z5funcBi73; INLINE-HOT-DAG-NEXT: Merging context profile into base profile: _Z5funcBi74; INLINE-HOT-DAG-NEXT: Found context tree root to promote: external:10 @ _Z5funcBi75; INLINE-HOT-DAG-NEXT: Context promoted to: _Z5funcBi76; INLINE-HOT-DAG-NEXT: Found context tree root to promote: externalA:17 @ _Z5funcBi77; INLINE-HOT-DAG-NEXT: Context promoted and merged to: _Z5funcBi78; INLINE-HOT-DAG-NEXT: Found context tree root to promote: main:3.1 @ _Z5funcBi79; INLINE-HOT-DAG-NEXT: Context promoted and merged to: _Z5funcBi80; INLINE-HOT-DAG-NEXT: Context promoted to: _Z5funcBi:1 @ _Z8funcLeafi81; INLINE-HOT-DAG-NEXT: Getting callee context for instr: %call = tail call i32 @_Z8funcLeafi82; INLINE-HOT-DAG-NEXT: Callee context found: _Z5funcBi:1 @ _Z8funcLeafi83; INLINE-HOT-DAG-NEXT: Marking context profile as inlined: _Z5funcBi:1 @ _Z8funcLeafi84; INLINE-HOT-DAG-NEXT: Getting callee context for instr: %call.i = tail call i32 @_Z3fibi85; INLINE-HOT-DAG-NEXT: Getting callee context for instr: %call5.i = tail call i32 @_Z3fibi86; INLINE-HOT: Getting base profile for function: _Z8funcLeafi87; INLINE-HOT-NEXT: Merging context profile into base profile: _Z8funcLeafi88 89 90@factor = dso_local global i32 3, align 4, !dbg !091 92define dso_local i32 @main() local_unnamed_addr #0 !dbg !18 {93entry:94 br label %for.body, !dbg !2595 96for.cond.cleanup: ; preds = %for.body97 ret i32 %add3, !dbg !2798 99for.body: ; preds = %for.body, %entry100 %x.011 = phi i32 [ 300000, %entry ], [ %dec, %for.body ]101 %r.010 = phi i32 [ 0, %entry ], [ %add3, %for.body ]102 %call = tail call i32 @_Z5funcBi(i32 %x.011), !dbg !32103 %add = add nuw nsw i32 %x.011, 1, !dbg !31104 %call1 = tail call i32 @_Z5funcAi(i32 %add), !dbg !28105 %add2 = add i32 %call, %r.010, !dbg !34106 %add3 = add i32 %add2, %call1, !dbg !35107 %dec = add nsw i32 %x.011, -1, !dbg !36108 %cmp = icmp eq i32 %x.011, 0, !dbg !38109 br i1 %cmp, label %for.cond.cleanup, label %for.body, !dbg !25110}111 112define dso_local i32 @_Z5funcAi(i32 %x) local_unnamed_addr #1 !dbg !40 {113entry:114 %add = add nsw i32 %x, 100000, !dbg !44115 %call = tail call i32 @_Z8funcLeafi(i32 %add), !dbg !45116 ret i32 %call, !dbg !46117}118 119define dso_local i32 @_Z8funcLeafi(i32 %x) local_unnamed_addr #1 !dbg !54 {120entry:121 %cmp = icmp sgt i32 %x, 0, !dbg !57122 br i1 %cmp, label %while.body, label %while.cond2.preheader, !dbg !59123 124while.cond2.preheader: ; preds = %entry125 %cmp313 = icmp slt i32 %x, 0, !dbg !60126 br i1 %cmp313, label %while.body4, label %if.end, !dbg !63127 128while.body: ; preds = %while.body, %entry129 %x.addr.016 = phi i32 [ %sub, %while.body ], [ %x, %entry ]130 %tmp = load volatile i32, ptr @factor, align 4, !dbg !64131 %call = tail call i32 @_Z3fibi(i32 %tmp), !dbg !67132 %sub = sub nsw i32 %x.addr.016, %call, !dbg !68133 %cmp1 = icmp sgt i32 %sub, 0, !dbg !69134 br i1 %cmp1, label %while.body, label %if.end, !dbg !71135 136while.body4: ; preds = %while.body4, %while.cond2.preheader137 %x.addr.114 = phi i32 [ %add, %while.body4 ], [ %x, %while.cond2.preheader ]138 %tmp1 = load volatile i32, ptr @factor, align 4, !dbg !72139 %call5 = tail call i32 @_Z3fibi(i32 %tmp1), !dbg !74140 %add = add nsw i32 %call5, %x.addr.114, !dbg !75141 %cmp3 = icmp slt i32 %add, 0, !dbg !60142 br i1 %cmp3, label %while.body4, label %if.end, !dbg !63143 144if.end: ; preds = %while.body4, %while.body, %while.cond2.preheader145 %x.addr.2 = phi i32 [ 0, %while.cond2.preheader ], [ %sub, %while.body ], [ %add, %while.body4 ]146 ret i32 %x.addr.2, !dbg !76147}148 149define dso_local i32 @_Z5funcBi(i32 %x) local_unnamed_addr #0 !dbg !47 {150entry:151 %sub = add nsw i32 %x, -100000, !dbg !51152 %call = tail call i32 @_Z8funcLeafi(i32 %sub), !dbg !52153 ret i32 %call, !dbg !53154}155 156declare i32 @_Z3fibi(i32)157 158attributes #0 = { nofree noinline norecurse nounwind uwtable "use-sample-profile" }159attributes #1 = { nofree norecurse nounwind uwtable "use-sample-profile" }160 161!llvm.dbg.cu = !{!2}162!llvm.module.flags = !{!14, !15, !16}163!llvm.ident = !{!17}164 165!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())166!1 = distinct !DIGlobalVariable(name: "factor", scope: !2, file: !3, line: 21, type: !13, isLocal: false, isDefinition: true)167!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 11.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !5, globals: !12, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None)168!3 = !DIFile(filename: "merged.cpp", directory: "/local/autofdo")169!4 = !{}170!5 = !{!6, !10, !11}171!6 = !DISubprogram(name: "funcA", linkageName: "_Z5funcAi", scope: !3, file: !3, line: 6, type: !7, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4)172!7 = !DISubroutineType(types: !8)173!8 = !{!9, !9}174!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)175!10 = !DISubprogram(name: "funcB", linkageName: "_Z5funcBi", scope: !3, file: !3, line: 7, type: !7, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4)176!11 = !DISubprogram(name: "funcLeaf", linkageName: "_Z8funcLeafi", scope: !3, file: !3, line: 22, type: !7, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4)177!12 = !{!0}178!13 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !9)179!14 = !{i32 7, !"Dwarf Version", i32 4}180!15 = !{i32 2, !"Debug Info Version", i32 3}181!16 = !{i32 1, !"wchar_size", i32 4}182!17 = !{!"clang version 11.0.0"}183!18 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 11, type: !19, scopeLine: 11, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !21)184!19 = !DISubroutineType(types: !20)185!20 = !{!9}186!21 = !{!22, !23}187!22 = !DILocalVariable(name: "r", scope: !18, file: !3, line: 12, type: !9)188!23 = !DILocalVariable(name: "x", scope: !24, file: !3, line: 13, type: !9)189!24 = distinct !DILexicalBlock(scope: !18, file: !3, line: 13, column: 3)190!25 = !DILocation(line: 13, column: 3, scope: !26)191!26 = !DILexicalBlockFile(scope: !24, file: !3, discriminator: 2)192!27 = !DILocation(line: 17, column: 3, scope: !18)193!28 = !DILocation(line: 14, column: 10, scope: !29)194!29 = distinct !DILexicalBlock(scope: !30, file: !3, line: 13, column: 37)195!30 = distinct !DILexicalBlock(scope: !24, file: !3, line: 13, column: 3)196!31 = !DILocation(line: 14, column: 29, scope: !29)197!32 = !DILocation(line: 14, column: 21, scope: !33)198!33 = !DILexicalBlockFile(scope: !29, file: !3, discriminator: 2)199!34 = !DILocation(line: 14, column: 19, scope: !29)200!35 = !DILocation(line: 14, column: 7, scope: !29)201!36 = !DILocation(line: 13, column: 33, scope: !37)202!37 = !DILexicalBlockFile(scope: !30, file: !3, discriminator: 6)203!38 = !DILocation(line: 13, column: 26, scope: !39)204!39 = !DILexicalBlockFile(scope: !30, file: !3, discriminator: 2)205!40 = distinct !DISubprogram(name: "funcA", linkageName: "_Z5funcAi", scope: !3, file: !3, line: 26, type: !7, scopeLine: 26, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2)206!44 = !DILocation(line: 27, column: 22, scope: !40)207!45 = !DILocation(line: 27, column: 11, scope: !40)208!46 = !DILocation(line: 29, column: 3, scope: !40)209!47 = distinct !DISubprogram(name: "funcB", linkageName: "_Z5funcBi", scope: !3, file: !3, line: 32, type: !7, scopeLine: 32, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2)210!51 = !DILocation(line: 33, column: 22, scope: !47)211!52 = !DILocation(line: 33, column: 11, scope: !47)212!53 = !DILocation(line: 35, column: 3, scope: !47)213!54 = distinct !DISubprogram(name: "funcLeaf", linkageName: "_Z8funcLeafi", scope: !3, file: !3, line: 48, type: !7, scopeLine: 48, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2)214!57 = !DILocation(line: 49, column: 9, scope: !58)215!58 = distinct !DILexicalBlock(scope: !54, file: !3, line: 49, column: 7)216!59 = !DILocation(line: 49, column: 7, scope: !54)217!60 = !DILocation(line: 58, column: 14, scope: !61)218!61 = !DILexicalBlockFile(scope: !62, file: !3, discriminator: 2)219!62 = distinct !DILexicalBlock(scope: !58, file: !3, line: 56, column: 8)220!63 = !DILocation(line: 58, column: 5, scope: !61)221!64 = !DILocation(line: 52, column: 16, scope: !65)222!65 = distinct !DILexicalBlock(scope: !66, file: !3, line: 51, column: 19)223!66 = distinct !DILexicalBlock(scope: !58, file: !3, line: 49, column: 14)224!67 = !DILocation(line: 52, column: 12, scope: !65)225!68 = !DILocation(line: 52, column: 9, scope: !65)226!69 = !DILocation(line: 51, column: 14, scope: !70)227!70 = !DILexicalBlockFile(scope: !66, file: !3, discriminator: 2)228!71 = !DILocation(line: 51, column: 5, scope: !70)229!72 = !DILocation(line: 59, column: 16, scope: !73)230!73 = distinct !DILexicalBlock(scope: !62, file: !3, line: 58, column: 19)231!74 = !DILocation(line: 59, column: 12, scope: !73)232!75 = !DILocation(line: 59, column: 9, scope: !73)233!76 = !DILocation(line: 63, column: 3, scope: !54)234