brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.4 KiB · 0bf6222 Raw
185 lines · plain
1;; Test recursion handling during cloning.2 3;; -stats requires asserts4; REQUIRES: asserts5 6;; Original code looks like:7;;8;; #include <stdlib.h>9;; #include <string.h>10;; #include <unistd.h>11;; __attribute((noinline)) char *D() {12;;   return new char[10];13;; }14;; __attribute((noinline)) char *B(int n);15;; __attribute((noinline)) char *C(int n) {16;;   if (!n) {17;;     return D();18;;   }19;;   return B(n-1);20;; }21;; __attribute((noinline)) char *B(int n) {22;;   return C(n);23;; }24;; int main(int argc, char **argv) {25;;   char *x = B(1);26;;   char *y = B(1);27;;   char *z = B(0);28;;   memset(x, 0, 10);29;;   memset(y, 0, 10);30;;   memset(z, 0, 10);31;;   free(x);32;;   sleep(200);33;;   free(y);34;;   free(z);35;;   return 0;36;; }37;;38;; The IR was then reduced using llvm-reduce with the expected FileCheck input.39 40;; Check behavior when we enable cloning of contexts involved with recursive41;; cycles, but not through the cycle itself. I.e. with full support for cloning42;; recursive cycles off, the cloned recursive call from C back to B (line 12)43;; will not be updated to call a clone.44; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \45; RUN:  -memprof-verify-ccg -memprof-verify-nodes \46; RUN:  -pass-remarks=memprof-context-disambiguation \47; RUN:	-memprof-allow-recursive-callsites=true \48; RUN:	-memprof-clone-recursive-contexts=false \49; RUN:  %s -S 2>&1 | FileCheck %s \50; RUN:  --implicit-check-not "memprof_recursive.cc:12:10: call in clone _Z1Ci.memprof.1 assigned to call function clone _Z1Bi.memprof" \51; RUN:  --check-prefix=ALL --check-prefix=ALLOW-RECUR-CALLSITES --check-prefix=ALLOW-RECUR-CONTEXTS52 53;; Skipping recursive callsites should result in no cloning.54; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \55; RUN:  -memprof-verify-ccg -memprof-verify-nodes \56; RUN:  -pass-remarks=memprof-context-disambiguation \57; RUN:	-memprof-allow-recursive-callsites=false \58; RUN:  %s -S 2>&1 | FileCheck %s \59; RUN:  --implicit-check-not "memprof_recursive.cc:12:10: call in clone _Z1Ci.memprof.1 assigned to call function clone _Z1Bi.memprof" \60; RUN:  --implicit-check-not="created clone" \61; RUN:	--implicit-check-not="marked with memprof allocation attribute cold" \62; RUN:  --check-prefix=ALL63 64;; Check the default behavior (clone recursive callsites).65; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \66; RUN:  -memprof-verify-ccg -memprof-verify-nodes -stats \67; RUN:  -memprof-export-to-dot -memprof-dot-file-path-prefix=%t. \68; RUN:  -pass-remarks=memprof-context-disambiguation \69; RUN:  %s -S 2>&1 | FileCheck %s \70; RUN:  --check-prefix=ALL --check-prefix=ALLOW-RECUR-CALLSITES --check-prefix=ALLOW-RECUR-CONTEXTS \71; RUN:  --check-prefix=CLONE-RECUR-CALLSITES72 73;; Check that the backedge was correctly detected and emitted to the dot file74;; as a dotted edge.75; RUN: cat %t.ccg.postbuild.dot | FileCheck %s --check-prefix=DOT76; DOT-DAG: Node[[B:0x[a-f0-9]+]] {{.*}}_Z1Bi -\> _Z1Ci77; DOT-DAG: Node[[C:0x[a-f0-9]+]] {{.*}}_Z1Ci -\> _Z1Bi78; DOT-DAG: Node[[C]] -> Node[[B]]{{.*}}style="dotted"79 80;; Skipping recursive contexts should prevent spurious call to cloned version of81;; B from the context starting at memprof_recursive.cc:19:13, which is actually82;; recursive (until that support is added).83; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \84; RUN:  -memprof-verify-ccg -memprof-verify-nodes \85; RUN:  -pass-remarks=memprof-context-disambiguation \86; RUN:	-memprof-allow-recursive-callsites=true \87; RUN:	-memprof-allow-recursive-contexts=false \88; RUN:	-memprof-clone-recursive-contexts=false \89; RUN:  %s -S 2>&1 | FileCheck %s \90; RUN:  --implicit-check-not "memprof_recursive.cc:12:10: call in clone _Z1Ci.memprof.1 assigned to call function clone _Z1Bi.memprof" \91; RUN:  --check-prefix=ALL --check-prefix=ALLOW-RECUR-CALLSITES --check-prefix=SKIP-RECUR-CONTEXTS92 93; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:4:0: created clone _Z1Dv.memprof.194; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:8:0: created clone _Z1Ci.memprof.195; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:14:0: created clone _Z1Bi.memprof.196; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:20:13: call in clone main assigned to call function clone _Z1Bi.memprof.197;; We should only call the cold clone for the recursive context if we enabled98;; recursive contexts via -memprof-allow-recursive-contexts=true (default).99; ALLOW-RECUR-CONTEXTS: memprof_recursive.cc:19:13: call in clone main assigned to call function clone _Z1Bi.memprof.1100; CLONE-RECUR-CALLSITES: memprof_recursive.cc:12:10: call in clone _Z1Ci.memprof.1 assigned to call function clone _Z1Bi.memprof.1101; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:15:10: call in clone _Z1Bi.memprof.1 assigned to call function clone _Z1Ci.memprof.1102; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:10:12: call in clone _Z1Ci.memprof.1 assigned to call function clone _Z1Dv.memprof.1103; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:5:10: call in clone _Z1Dv.memprof.1 marked with memprof allocation attribute cold104;; We should call the original B for the recursive context if we have105;; disabled recursive contexts via -memprof-allow-recursive-contexts=false.106; SKIP-RECUR-CONTEXTS: memprof_recursive.cc:19:13: call in clone main assigned to call function clone _Z1Bi107; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:12:10: call in clone _Z1Ci assigned to call function clone _Z1Bi108; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:18:13: call in clone main assigned to call function clone _Z1Bi109; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:15:10: call in clone _Z1Bi assigned to call function clone _Z1Ci110; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:10:12: call in clone _Z1Ci assigned to call function clone _Z1Dv111; ALL: memprof_recursive.cc:5:10: call in clone _Z1Dv marked with memprof allocation attribute notcold112; CLONE-RECUR-CALLSITES: 1 memprof-context-disambiguation - Number of backedges with deferred cloning113 114target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"115target triple = "x86_64-unknown-linux-gnu"116 117define ptr @_Z1Dv() !dbg !3 {118entry:119  %call = tail call ptr @_Znam(i64 10), !dbg !6, !memprof !7, !callsite !14120  ret ptr null121}122 123define ptr @_Z1Ci(i32 %n) !dbg !15 {124entry:125  %call = tail call ptr @_Z1Dv(), !dbg !16, !callsite !17126  br label %return127 128if.end:                                           ; No predecessors!129  %call1 = tail call ptr @_Z1Bi(i32 0), !dbg !18, !callsite !19130  br label %return131 132return:                                           ; preds = %if.end, %entry133  ret ptr null134}135 136define ptr @_Z1Bi(i32 %n) !dbg !20 {137entry:138  %call = tail call ptr @_Z1Ci(i32 0), !dbg !21, !callsite !22139  ret ptr null140}141 142define i32 @main() {143entry:144  %call = tail call ptr @_Z1Bi(i32 0), !dbg !23, !callsite !25145  %call1 = tail call ptr @_Z1Bi(i32 0), !dbg !26, !callsite !27146  %call2 = tail call ptr @_Z1Bi(i32 0), !dbg !28, !callsite !29147  ret i32 0148}149 150declare ptr @_Znam(i64)151 152!llvm.dbg.cu = !{!0}153!llvm.module.flags = !{!2}154 155!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)156!1 = !DIFile(filename: "memprof_recursive.cc", directory: ".", checksumkind: CSK_MD5, checksum: "2f15f63b187a0e0d40e7fdd18b10576a")157!2 = !{i32 2, !"Debug Info Version", i32 3}158!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)159!4 = !DISubroutineType(types: !5)160!5 = !{}161!6 = !DILocation(line: 5, column: 10, scope: !3)162!7 = !{!8, !10, !12}163!8 = !{!9, !"cold"}164!9 = !{i64 6541423618768552252, i64 -200552803509692312, i64 -2954124005641725917, i64 6307901912192269588}165!10 = !{!11, !"notcold"}166!11 = !{i64 6541423618768552252, i64 -200552803509692312, i64 -2954124005641725917, i64 -7155190423157709404, i64 -2954124005641725917, i64 8632435727821051414}167!12 = !{!13, !"cold"}168!13 = !{i64 6541423618768552252, i64 -200552803509692312, i64 -2954124005641725917, i64 -7155190423157709404, i64 -2954124005641725917, i64 -3421689549917153178}169!14 = !{i64 6541423618768552252}170!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)171!16 = !DILocation(line: 10, column: 12, scope: !15)172!17 = !{i64 -200552803509692312}173!18 = !DILocation(line: 12, column: 10, scope: !15)174!19 = !{i64 -7155190423157709404}175!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)176!21 = !DILocation(line: 15, column: 10, scope: !20)177!22 = !{i64 -2954124005641725917}178!23 = !DILocation(line: 18, column: 13, scope: !24)179!24 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 17, type: !4, scopeLine: 17, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)180!25 = !{i64 8632435727821051414}181!26 = !DILocation(line: 19, column: 13, scope: !24)182!27 = !{i64 -3421689549917153178}183!28 = !DILocation(line: 20, column: 13, scope: !24)184!29 = !{i64 6307901912192269588}185