164 lines · plain
1;; Tests option to discard small noncold contexts.2 3;; Avoid failures on big-endian systems that can't read the profile properly4; REQUIRES: x86_64-linux5 6;; Generate the profile and the IR.7; RUN: split-file %s %t8 9;; Generate indexed profile10; RUN: llvm-profdata merge %t/memprof_discard_threshold.yaml -o %t.memprofdata11 12;; Test default (threshold 100%). We should get the same results with and13;; without -memprof-keep-all-not-cold-contexts.14 15; RUN: opt < %t/memprof_discard_threshold.ll -passes='memprof-use<profile-filename=%t.memprofdata>' -S 2>&1 | FileCheck %s --check-prefixes=CALL,MEMPROF16 17;; Test discarding (threshold 80%). We should get the same results with and18;; without -memprof-keep-all-not-cold-contexts.19 20; RUN: opt < %t/memprof_discard_threshold.ll -passes='memprof-use<profile-filename=%t.memprofdata>' -S -memprof-report-hinted-sizes -memprof-keep-all-not-cold-contexts 2>&1 | FileCheck %s --check-prefixes=CALL,MEMPROF,REPORT21 22; RUN: opt < %t/memprof_discard_threshold.ll -passes='memprof-use<profile-filename=%t.memprofdata>' -memprof-callsite-cold-threshold=80 -S 2>&1 | FileCheck %s --check-prefixes=CALL,MEMPROF8023 24; RUN: opt < %t/memprof_discard_threshold.ll -passes='memprof-use<profile-filename=%t.memprofdata>' -S -memprof-callsite-cold-threshold=80 -memprof-report-hinted-sizes -memprof-keep-all-not-cold-contexts 2>&1 | FileCheck %s --check-prefixes=CALL,MEMPROF80,REPORT8025 26;; One context should have been discarded, with exactly 80-20 behavior.27; REPORT80: MemProf hinting: Total size for discarded non-cold full allocation context hash 7175328747938231822 for 80.00% cold bytes: 2028 29;--- memprof_discard_threshold.yaml30---31HeapProfileRecords:32 - GUID: A33 AllocSites:34 - Callstack:35 - { Function: A, LineOffset: 1, Column: 10, IsInlineFrame: false }36 - { Function: B, LineOffset: 6, Column: 13, IsInlineFrame: false }37 - { Function: C, LineOffset: 7, Column: 11, IsInlineFrame: false }38 # Cold39 MemInfoBlock:40 AllocCount: 141 TotalSize: 10042 TotalLifetime: 20000043 TotalLifetimeAccessDensity: 044 - Callstack:45 - { Function: A, LineOffset: 1, Column: 10, IsInlineFrame: false }46 - { Function: B, LineOffset: 6, Column: 13, IsInlineFrame: false }47 - { Function: D, LineOffset: 8, Column: 20, IsInlineFrame: false }48 # Not cold49 # While this one is pruned without -memprof-keep-all-not-cold-contexts,50 # if we don't track the aggregate total/cold bytes correctly for51 # discarded contexts we might think that at callsite B we are more than52 # 80% cold and discard all the non-cold contexts.53 MemInfoBlock:54 AllocCount: 155 TotalSize: 50056 TotalLifetime: 057 TotalLifetimeAccessDensity: 2000058 - Callstack:59 - { Function: A, LineOffset: 1, Column: 10, IsInlineFrame: false }60 - { Function: B, LineOffset: 6, Column: 13, IsInlineFrame: false }61 - { Function: E, LineOffset: 5, Column: 4, IsInlineFrame: false }62 - { Function: F, LineOffset: 4, Column: 5, IsInlineFrame: false }63 # Not cold64 MemInfoBlock:65 AllocCount: 166 TotalSize: 3067 TotalLifetime: 068 TotalLifetimeAccessDensity: 2000069 - Callstack:70 - { Function: A, LineOffset: 1, Column: 10, IsInlineFrame: false }71 - { Function: B, LineOffset: 6, Column: 13, IsInlineFrame: false }72 - { Function: E, LineOffset: 5, Column: 4, IsInlineFrame: false }73 - { Function: G, LineOffset: 3, Column: 7, IsInlineFrame: false }74 - { Function: H, LineOffset: 2, Column: 15, IsInlineFrame: false }75 # Cold76 MemInfoBlock:77 AllocCount: 178 TotalSize: 8079 TotalLifetime: 20000080 TotalLifetimeAccessDensity: 081 - Callstack:82 - { Function: A, LineOffset: 1, Column: 10, IsInlineFrame: false }83 - { Function: B, LineOffset: 6, Column: 13, IsInlineFrame: false }84 - { Function: E, LineOffset: 5, Column: 4, IsInlineFrame: false }85 - { Function: G, LineOffset: 3, Column: 7, IsInlineFrame: false }86 - { Function: I, LineOffset: 7, Column: 16, IsInlineFrame: false }87 # Not cold88 MemInfoBlock:89 AllocCount: 190 TotalSize: 2091 TotalLifetime: 092 TotalLifetimeAccessDensity: 2000093 CallSites: []94 95;--- memprof_discard_threshold.ll96; ModuleID = 'memprof_discard_threshold.cc'97source_filename = "memprof_discard_threshold.cc"98target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"99target triple = "x86_64-unknown-linux-gnu"100 101define dso_local noundef ptr @A() !dbg !10 {102entry:103 ; CALL: call {{.*}} @_Znam{{.*}} !memprof ![[M1:[0-9]+]], !callsite ![[C1:[0-9]+]]104 %call = call noalias noundef nonnull ptr @_Znam(i64 noundef 32), !dbg !13105 ret ptr %call106}107 108declare noundef nonnull ptr @_Znam(i64 noundef)109 110; MEMPROF: ![[M1]] = !{![[MIB1:[0-9]+]],111; REPORT-SAME: ![[MIB2:[0-9]+]],112; MEMPROF-SAME: ![[MIB3:[0-9]+]], ![[MIB4:[0-9]+]]113; REPORT-SAME: , ![[MIB5:[0-9]+]]}114; MEMPROF: ![[MIB1]] = !{![[STACK1:[0-9]+]], !"cold"115; REPORT-SAME: , ![[SIZE1:[0-9]+]]}116; MEMPROF: ![[STACK1]] = !{i64 -2647357475745718070, i64 869302454322824036, i64 705268496523263927}117; REPORT: ![[SIZE1]] = !{i64 -7154823362113119138, i64 100}118; REPORT: ![[MIB2]] = !{![[STACK2:[0-9]+]], !"notcold", ![[SIZE2:[0-9]+]]}119; REPORT: ![[STACK2]] = !{i64 -2647357475745718070, i64 869302454322824036, i64 -6015552466537626283, i64 7621414677325196405}120; REPORT: ![[SIZE2]] = !{i64 4574148894276641937, i64 30}121; MEMPROF: ![[MIB3]] = !{![[STACK3:[0-9]+]], !"cold"122; REPORT-SAME: , ![[SIZE3:[0-9]+]]}123; MEMPROF: ![[STACK3]] = !{i64 -2647357475745718070, i64 869302454322824036, i64 -6015552466537626283, i64 -2897722569788633560, i64 3206456850862191843}124; REPORT: ![[SIZE3]] = !{i64 2848517899452258040, i64 80}125; MEMPROF: ![[MIB4]] = !{![[STACK4:[0-9]+]], !"notcold"126; REPORT-SAME: , ![[SIZE4:[0-9]+]]}127; MEMPROF: ![[STACK4]] = !{i64 -2647357475745718070, i64 869302454322824036, i64 -6015552466537626283, i64 -2897722569788633560, i64 -1037739922429764316}128; REPORT: ![[SIZE4]] = !{i64 7175328747938231822, i64 20}129; REPORT: ![[MIB5]] = !{![[STACK5:[0-9]+]], !"notcold", ![[SIZE5:[0-9]+]]}130; REPORT: ![[STACK5]] = !{i64 -2647357475745718070, i64 869302454322824036, i64 -3111772584478263690}131; REPORT: ![[SIZE5]] = !{i64 8469515017747579284, i64 500}132; MEMPROF: ![[C1]] = !{i64 -2647357475745718070}133 134; MEMPROF80: ![[M1]] = !{![[MIB1:[0-9]+]], ![[MIB2:[0-9]+]], ![[MIB3:[0-9]+]]135; REPORT80-SAME: , ![[MIB5:[0-9]+]]}136; MEMPROF80: ![[MIB1]] = !{![[STACK1:[0-9]+]], !"cold"137; REPORT80-SAME: , ![[SIZE1:[0-9]+]]}138; MEMPROF80: ![[STACK1]] = !{i64 -2647357475745718070, i64 869302454322824036, i64 705268496523263927}139; REPORT80: ![[SIZE1]] = !{i64 -7154823362113119138, i64 100}140; MEMPROF80: ![[MIB2]] = !{![[STACK2:[0-9]+]], !"notcold"141; REPORT80-SAME: , ![[SIZE2:[0-9]+]]}142; MEMPROF80: ![[STACK2]] = !{i64 -2647357475745718070, i64 869302454322824036, i64 -6015552466537626283, i64 7621414677325196405}143; REPORT80: ![[SIZE2]] = !{i64 4574148894276641937, i64 30}144; MEMPROF80: ![[MIB3]] = !{![[STACK3:[0-9]+]], !"cold"145; REPORT80-SAME: , ![[SIZE3:[0-9]+]]}146; MEMPROF80: ![[STACK3]] = !{i64 -2647357475745718070, i64 869302454322824036, i64 -6015552466537626283, i64 -2897722569788633560, i64 3206456850862191843}147; REPORT80: ![[SIZE3]] = !{i64 2848517899452258040, i64 80}148; REPORT80: ![[MIB5]] = !{![[STACK5:[0-9]+]], !"notcold", ![[SIZE5:[0-9]+]]}149; REPORT80: ![[STACK5]] = !{i64 -2647357475745718070, i64 869302454322824036, i64 -3111772584478263690}150; REPORT80: ![[SIZE5]] = !{i64 8469515017747579284, i64 500}151; MEMPROF80: ![[C1]] = !{i64 -2647357475745718070}152 153!llvm.dbg.cu = !{!0}154!llvm.module.flags = !{!2, !3}155 156!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 15.0.0 (https://github.com/llvm/llvm-project.git 6cbe6284d1f0a088b5c6482ae27b738f03d82fe7)", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None)157!1 = !DIFile(filename: "memprof.cc", directory: ".", checksumkind: CSK_MD5, checksum: "e8c40ebe4b21776b4d60e9632cbc13c2")158!2 = !{i32 7, !"Dwarf Version", i32 5}159!3 = !{i32 2, !"Debug Info Version", i32 3}160!10 = distinct !DISubprogram(name: "A", linkageName: "A", scope: !1, file: !1, line: 4, type: !11, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !12)161!11 = !DISubroutineType(types: !12)162!12 = !{}163!13 = !DILocation(line: 5, column: 10, scope: !10)164