|
| 1 | +;; Test recursion handling during cloning. |
| 2 | +;; |
| 3 | +;; See llvm/test/Transforms/MemProfContextDisambiguation/recursive.ll for |
| 4 | +;; information on how the test was created. |
| 5 | + |
| 6 | +; RUN: opt -thinlto-bc %s >%t.o |
| 7 | + |
| 8 | +;; By default we should enable cloning of contexts involved with recursive |
| 9 | +;; cycles, but not through the cycle itself. I.e. until full support for |
| 10 | +;; recursion is added, the cloned recursive call from C back to B (line 12) will |
| 11 | +;; not be updated to call a clone. |
| 12 | +; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ |
| 13 | +; RUN: -supports-hot-cold-new \ |
| 14 | +; RUN: -r=%t.o,_Z1Dv,plx \ |
| 15 | +; RUN: -r=%t.o,_Z1Ci,plx \ |
| 16 | +; RUN: -r=%t.o,_Z1Bi,plx \ |
| 17 | +; RUN: -r=%t.o,main,plx \ |
| 18 | +; RUN: -r=%t.o,_Znam, \ |
| 19 | +; RUN: -memprof-verify-ccg -memprof-verify-nodes \ |
| 20 | +; RUN: -pass-remarks=memprof-context-disambiguation \ |
| 21 | +; RUN: -o %t.out 2>&1 | FileCheck %s \ |
| 22 | +; RUN: --implicit-check-not "memprof_recursive3.cc:12:10: call in clone _Z1Ci.memprof.1 assigned" \ |
| 23 | +; RUN: --check-prefix=ALLOW-RECUR-CALLSITES --check-prefix=ALLOW-RECUR-CONTEXTS |
| 24 | + |
| 25 | +;; Skipping recursive callsites should result in no cloning. |
| 26 | +; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ |
| 27 | +; RUN: -supports-hot-cold-new \ |
| 28 | +; RUN: -r=%t.o,_Z1Dv,plx \ |
| 29 | +; RUN: -r=%t.o,_Z1Ci,plx \ |
| 30 | +; RUN: -r=%t.o,_Z1Bi,plx \ |
| 31 | +; RUN: -r=%t.o,main,plx \ |
| 32 | +; RUN: -r=%t.o,_Znam, \ |
| 33 | +; RUN: -memprof-verify-ccg -memprof-verify-nodes \ |
| 34 | +; RUN: -pass-remarks=memprof-context-disambiguation \ |
| 35 | +; RUN: -memprof-allow-recursive-callsites=false \ |
| 36 | +; RUN: -o %t.out 2>&1 | FileCheck %s --allow-empty \ |
| 37 | +; RUN: --implicit-check-not "memprof_recursive3.cc:12:10: call in clone _Z1Ci.memprof.1 assigned" \ |
| 38 | +; RUN: --implicit-check-not="created clone" \ |
| 39 | +; RUN: --implicit-check-not="marked with memprof allocation attribute cold" |
| 40 | + |
| 41 | +;; Skipping recursive contexts should prevent spurious call to cloned version of |
| 42 | +;; B from the context starting at memprof_recursive.cc:19:13, which is actually |
| 43 | +;; recursive (until that support is added). |
| 44 | +; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ |
| 45 | +; RUN: -supports-hot-cold-new \ |
| 46 | +; RUN: -r=%t.o,_Z1Dv,plx \ |
| 47 | +; RUN: -r=%t.o,_Z1Ci,plx \ |
| 48 | +; RUN: -r=%t.o,_Z1Bi,plx \ |
| 49 | +; RUN: -r=%t.o,main,plx \ |
| 50 | +; RUN: -r=%t.o,_Znam, \ |
| 51 | +; RUN: -memprof-verify-ccg -memprof-verify-nodes \ |
| 52 | +; RUN: -pass-remarks=memprof-context-disambiguation \ |
| 53 | +; RUN: -memprof-allow-recursive-contexts=false \ |
| 54 | +; RUN: -o %t.out 2>&1 | FileCheck %s \ |
| 55 | +; RUN: --implicit-check-not "memprof_recursive3.cc:12:10: call in clone _Z1Ci.memprof.1 assigned" \ |
| 56 | +; RUN: --check-prefix=ALLOW-RECUR-CALLSITES --check-prefix=SKIP-RECUR-CONTEXTS |
| 57 | + |
| 58 | +; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:4:0: created clone _Z1Dv.memprof.1 |
| 59 | +; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:5:10: call in clone _Z1Dv marked with memprof allocation attribute notcold |
| 60 | +; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:5:10: call in clone _Z1Dv.memprof.1 marked with memprof allocation attribute cold |
| 61 | +; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:8:0: created clone _Z1Ci.memprof.1 |
| 62 | +; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:10:12: call in clone _Z1Ci.memprof.1 assigned to call function clone _Z1Dv.memprof.1 |
| 63 | +; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:14:0: created clone _Z1Bi.memprof.1 |
| 64 | +; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:15:10: call in clone _Z1Bi.memprof.1 assigned to call function clone _Z1Ci.memprof.1 |
| 65 | +;; We should only call the cold clone for the recursive context if we enabled |
| 66 | +;; recursive contexts via -memprof-allow-recursive-contexts=true (default). |
| 67 | +; ALLOW-RECUR-CONTEXTS: memprof_recursive.cc:19:13: call in clone main assigned to call function clone _Z1Bi.memprof.1 |
| 68 | +; SKIP-RECUR-CONTEXTS-NOT: memprof_recursive.cc:19:13: call in clone main assigned to call function clone _Z1Bi.memprof.1 |
| 69 | +; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:20:13: call in clone main assigned to call function clone _Z1Bi.memprof.1 |
| 70 | + |
| 71 | +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" |
| 72 | +target triple = "x86_64-unknown-linux-gnu" |
| 73 | + |
| 74 | +define ptr @_Z1Dv() !dbg !3 { |
| 75 | +entry: |
| 76 | + %call = tail call ptr @_Znam(i64 10), !dbg !6, !memprof !7, !callsite !14 |
| 77 | + ret ptr null |
| 78 | +} |
| 79 | + |
| 80 | +define ptr @_Z1Ci(i32 %n) !dbg !15 { |
| 81 | +entry: |
| 82 | + %call = tail call ptr @_Z1Dv(), !dbg !16, !callsite !17 |
| 83 | + br label %return |
| 84 | + |
| 85 | +if.end: ; No predecessors! |
| 86 | + %call1 = tail call ptr @_Z1Bi(i32 0), !dbg !18, !callsite !19 |
| 87 | + br label %return |
| 88 | + |
| 89 | +return: ; preds = %if.end, %entry |
| 90 | + ret ptr null |
| 91 | +} |
| 92 | + |
| 93 | +define ptr @_Z1Bi(i32 %n) !dbg !20 { |
| 94 | +entry: |
| 95 | + %call = tail call ptr @_Z1Ci(i32 0), !dbg !21, !callsite !22 |
| 96 | + ret ptr null |
| 97 | +} |
| 98 | + |
| 99 | +define i32 @main() { |
| 100 | +entry: |
| 101 | + %call = tail call ptr @_Z1Bi(i32 0), !dbg !23, !callsite !25 |
| 102 | + %call1 = tail call ptr @_Z1Bi(i32 0), !dbg !26, !callsite !27 |
| 103 | + %call2 = tail call ptr @_Z1Bi(i32 0), !dbg !28, !callsite !29 |
| 104 | + ret i32 0 |
| 105 | +} |
| 106 | + |
| 107 | +declare ptr @_Znam(i64) |
| 108 | + |
| 109 | +!llvm.dbg.cu = !{!0} |
| 110 | +!llvm.module.flags = !{!2} |
| 111 | + |
| 112 | +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0git (https://github.com/llvm/llvm-project.git 7aec6dc477f8148ed066d10dfc7a012a51b6599c)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None) |
| 113 | +!1 = !DIFile(filename: "memprof_recursive.cc", directory: ".", checksumkind: CSK_MD5, checksum: "2f15f63b187a0e0d40e7fdd18b10576a") |
| 114 | +!2 = !{i32 2, !"Debug Info Version", i32 3} |
| 115 | +!3 = distinct !DISubprogram(name: "D", linkageName: "_Z1Dv", scope: !1, file: !1, line: 4, type: !4, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0) |
| 116 | +!4 = !DISubroutineType(types: !5) |
| 117 | +!5 = !{} |
| 118 | +!6 = !DILocation(line: 5, column: 10, scope: !3) |
| 119 | +!7 = !{!8, !10, !12} |
| 120 | +!8 = !{!9, !"cold"} |
| 121 | +!9 = !{i64 6541423618768552252, i64 -200552803509692312, i64 -2954124005641725917, i64 6307901912192269588} |
| 122 | +!10 = !{!11, !"notcold"} |
| 123 | +!11 = !{i64 6541423618768552252, i64 -200552803509692312, i64 -2954124005641725917, i64 -7155190423157709404, i64 -2954124005641725917, i64 8632435727821051414} |
| 124 | +!12 = !{!13, !"cold"} |
| 125 | +!13 = !{i64 6541423618768552252, i64 -200552803509692312, i64 -2954124005641725917, i64 -7155190423157709404, i64 -2954124005641725917, i64 -3421689549917153178} |
| 126 | +!14 = !{i64 6541423618768552252} |
| 127 | +!15 = distinct !DISubprogram(name: "C", linkageName: "_Z1Ci", scope: !1, file: !1, line: 8, type: !4, scopeLine: 8, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0) |
| 128 | +!16 = !DILocation(line: 10, column: 12, scope: !15) |
| 129 | +!17 = !{i64 -200552803509692312} |
| 130 | +!18 = !DILocation(line: 12, column: 10, scope: !15) |
| 131 | +!19 = !{i64 -7155190423157709404} |
| 132 | +!20 = distinct !DISubprogram(name: "B", linkageName: "_Z1Bi", scope: !1, file: !1, line: 14, type: !4, scopeLine: 14, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0) |
| 133 | +!21 = !DILocation(line: 15, column: 10, scope: !20) |
| 134 | +!22 = !{i64 -2954124005641725917} |
| 135 | +!23 = !DILocation(line: 18, column: 13, scope: !24) |
| 136 | +!24 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 17, type: !4, scopeLine: 17, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0) |
| 137 | +!25 = !{i64 8632435727821051414} |
| 138 | +!26 = !DILocation(line: 19, column: 13, scope: !24) |
| 139 | +!27 = !{i64 -3421689549917153178} |
| 140 | +!28 = !DILocation(line: 20, column: 13, scope: !24) |
| 141 | +!29 = !{i64 6307901912192269588} |
0 commit comments