1;; Test to make sure that memprof works and do cloning right when exists direct recursion. 2;; Original code looks like: 3;; After modify alloc type, there are two direct recursion with hot and cold alloc type. 4;; a.cpp 5;; extern void foo(int); 6;; int b = 10; 7;; int* a; 8;; int main(){ 9;; foo(1); 10;; b = 10; 11;; foo(2); 12;; return 0; 13;; } 14;; b.cpp 15;; extern int b; 16;; extern int *a; 17;; void foo(int c){ 18;; a = new int[1]; 19;; if (c&1) { 20;; for (int i = 0; i < 100; ++i) 21;; a[0] = 1; 22;; } 23;; --b; 24;; if (b) { 25;; foo(c); 26;; } 27;; } 28 29; RUN: split-file %s %t 30; RUN: opt -thinlto-bc %t/b.ll >%t/b.o 31; RUN: opt -thinlto-bc %t/a.ll >%t/a.o 32 33; RUN: llvm-lto2 run %t/b.o %t/a.o -enable-memprof-context-disambiguation \ 34; RUN: -supports-hot-cold-new \ 35; RUN: -thinlto-distributed-indexes \ 36; RUN: -r=%t/b.o,_Z3fooi,plx \ 37; RUN: -r=%t/b.o,aliasee,plx \ 38; RUN: -r=%t/b.o,a \ 39; RUN: -r=%t/b.o,b \ 40; RUN: -r=%t/b.o,_Znam \ 41; RUN: -r=%t/a.o,main,plx \ 42; RUN: -r=%t/a.o,_Z3fooi \ 43; RUN: -r=%t/a.o,a,plx \ 44; RUN: -r=%t/a.o,b,plx \ 45; RUN: -memprof-dump-ccg \ 46; RUN: -o %t2.out 2>&1 47 48; RUN: llvm-dis %t/b.o.thinlto.bc -o - | FileCheck %s --check-prefix=SUMMARY 49 50;; Test direct recursion don't cause assert failed and do cloning right. 51; RUN: opt -passes=memprof-context-disambiguation \ 52; RUN: -memprof-import-summary=%t/b.o.thinlto.bc \ 53; RUN: %t/b.o -S | FileCheck %s --check-prefix=IR 54 55; SUMMARY: stackIds: (1985258834072910425, 2841526434899864997) 56; SUMMARY-NOT: stackIds: (1985258834072910425, 1985258834072910425, 2841526434899864997) 57 58; IR: _Z3fooi 59; IR: _Z3fooi.memprof.1 60; IR: "memprof"="notcold" 61; IR: "memprof"="cold" 62 63;--- b.ll 64; ModuleID = 'b.cpp' 65source_filename = "b.cpp" 66target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" 67target triple = "x86_64-unknown-linux-gnu" 68 69;; Make sure the distributed summary bitcode writing succeeds when the memprof 70;; metadata is in an aliasee. 71@_Z3fooi = alias void (), ptr @aliasee 72 73@a = external local_unnamed_addr global ptr, align 8 74@b = external local_unnamed_addr global i32, align 4 75 76; Function Attrs: mustprogress uwtable 77define dso_local void @aliasee(i32 noundef %0) local_unnamed_addr #0 !dbg !9 { 78 br label %2, !dbg !12 79 802: ; preds = %7, %1 81 %3 = tail call noalias noundef nonnull dereferenceable(4) ptr @_Znam(i64 noundef 4) #2, !dbg !13, !memprof !14, !callsite !55 82 store ptr %3, ptr @a, align 8, !dbg !56, !tbaa !57 83 %4 = and i32 %0, 1, !dbg !61 84 %5 = icmp eq i32 %4, 0, !dbg !62 85 br i1 %5, label %7, label %6, !dbg !62 86 876: ; preds = %2 88 store i32 1, ptr %3, align 4, !tbaa !63 89 br label %7, !dbg !65 90 917: ; preds = %6, %2 92 %8 = load i32, ptr @b, align 4, !dbg !65, !tbaa !63 93 %9 = add nsw i32 %8, -1, !dbg !65 94 store i32 %9, ptr @b, align 4, !dbg !65, !tbaa !63 95 %10 = icmp eq i32 %9, 0, !dbg !66 96 br i1 %10, label %11, label %2, !dbg !66 97 9811: ; preds = %7 99 ret void, !dbg !67 100} 101 102; Function Attrs: nobuiltin allocsize(0) 103declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #1 104 105attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 106attributes #1 = { nobuiltin allocsize(0) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 107attributes #2 = { builtin allocsize(0) } 108 109!llvm.dbg.cu = !{!0} 110!llvm.module.flags = !{!2, !3, !4, !5, !6, !7} 111!llvm.ident = !{!8} 112 113!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 18.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None) 114!1 = !DIFile(filename: "b.cpp", directory: "/", checksumkind: CSK_MD5, checksum: "8fa6c585f9d2c35f1a82b920e64bbda2") 115!2 = !{i32 7, !"Dwarf Version", i32 5} 116!3 = !{i32 2, !"Debug Info Version", i32 3} 117!4 = !{i32 1, !"wchar_size", i32 4} 118!5 = !{i32 8, !"PIC Level", i32 2} 119!6 = !{i32 7, !"PIE Level", i32 2} 120!7 = !{i32 7, !"uwtable", i32 2} 121!8 = !{!"clang version 18.0.0"} 122!9 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooi", scope: !1, file: !1, line: 4, type: !10, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0) 123!10 = !DISubroutineType(types: !11) 124!11 = !{} 125!12 = !DILocation(line: 12, column: 9, scope: !9) 126!13 = !DILocation(line: 5, column: 9, scope: !9) 127!14 = !{!15, !17, !19, !21, !23, !25, !27, !29, !31, !33, !35, !37, !39, !41, !43, !45, !47, !49, !51, !53} 128!15 = !{!16, !"hot"} 129!16 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 2841526434899864997} 130!17 = !{!18, !"cold"} 131!18 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 8256520048276991898} 132!19 = !{!20, !"hot"} 133!20 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 2841526434899864997} 134!21 = !{!22, !"cold"} 135!22 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 8256520048276991898} 136!23 = !{!24, !"hot"} 137!24 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 2841526434899864997} 138!25 = !{!26, !"cold"} 139!26 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 8256520048276991898} 140!27 = !{!28, !"hot"} 141!28 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 2841526434899864997} 142!29 = !{!30, !"cold"} 143!30 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 8256520048276991898} 144!31 = !{!32, !"hot"} 145!32 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 2841526434899864997} 146!33 = !{!34, !"cold"} 147!34 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 8256520048276991898} 148!35 = !{!36, !"hot"} 149!36 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 2841526434899864997} 150!37 = !{!38, !"cold"} 151!38 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 8256520048276991898} 152!39 = !{!40, !"hot"} 153!40 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 2841526434899864997} 154!41 = !{!42, !"cold"} 155!42 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 8256520048276991898} 156!43 = !{!44, !"hot"} 157!44 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 2841526434899864997} 158!45 = !{!46, !"cold"} 159!46 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 8256520048276991898} 160!47 = !{!48, !"hot"} 161!48 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 2841526434899864997} 162!49 = !{!50, !"cold"} 163!50 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 8256520048276991898} 164!51 = !{!52, !"hot"} 165!52 = !{i64 -1057479539165743997, i64 2841526434899864997} 166!53 = !{!54, !"cold"} 167!54 = !{i64 -1057479539165743997, i64 8256520048276991898} 168!55 = !{i64 -1057479539165743997} 169!56 = !DILocation(line: 5, column: 7, scope: !9) 170!57 = !{!58, !58, i64 0} 171!58 = !{!"any pointer", !59, i64 0} 172!59 = !{!"omnipotent char", !60, i64 0} 173!60 = !{!"Simple C++ TBAA"} 174!61 = !DILocation(line: 6, column: 10, scope: !9) 175!62 = !DILocation(line: 6, column: 9, scope: !9) 176!63 = !{!64, !64, i64 0} 177!64 = !{!"int", !59, i64 0} 178!65 = !DILocation(line: 10, column: 5, scope: !9) 179!66 = !DILocation(line: 11, column: 9, scope: !9) 180!67 = !DILocation(line: 14, column: 1, scope: !9) 181 182;--- a.ll 183; ModuleID = 'a.cpp' 184source_filename = "a.cpp" 185target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" 186target triple = "x86_64-unknown-linux-gnu" 187 188@b = dso_local local_unnamed_addr global i32 10, align 4 189@a = dso_local local_unnamed_addr global ptr null, align 8 190 191; Function Attrs: mustprogress norecurse uwtable 192define dso_local noundef i32 @main() local_unnamed_addr #0 !dbg !9 { 193 tail call void @_Z3fooi(i32 noundef 1), !dbg !12, !callsite !13 194 store i32 10, ptr @b, align 4, !dbg !14, !tbaa !15 195 tail call void @_Z3fooi(i32 noundef 2), !dbg !19, !callsite !20 196 ret i32 0, !dbg !21 197} 198 199declare !dbg !22 void @_Z3fooi(i32 noundef) local_unnamed_addr #1 200 201attributes #0 = { mustprogress norecurse uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 202attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 203 204!llvm.dbg.cu = !{!0} 205!llvm.module.flags = !{!2, !3, !4, !5, !6, !7} 206!llvm.ident = !{!8} 207 208!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 18.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None) 209!1 = !DIFile(filename: "a.cpp", directory: "/", checksumkind: CSK_MD5, checksum: "16ecbfa723a07d69c0374cfc704a7c44") 210!2 = !{i32 7, !"Dwarf Version", i32 5} 211!3 = !{i32 2, !"Debug Info Version", i32 3} 212!4 = !{i32 1, !"wchar_size", i32 4} 213!5 = !{i32 8, !"PIC Level", i32 2} 214!6 = !{i32 7, !"PIE Level", i32 2} 215!7 = !{i32 7, !"uwtable", i32 2} 216!8 = !{!"clang version 18.0.0"} 217!9 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 4, type: !10, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0) 218!10 = !DISubroutineType(types: !11) 219!11 = !{} 220!12 = !DILocation(line: 5, column: 5, scope: !9) 221!13 = !{i64 2841526434899864997} 222!14 = !DILocation(line: 6, column: 7, scope: !9) 223!15 = !{!16, !16, i64 0} 224!16 = !{!"int", !17, i64 0} 225!17 = !{!"omnipotent char", !18, i64 0} 226!18 = !{!"Simple C++ TBAA"} 227!19 = !DILocation(line: 7, column: 5, scope: !9) 228!20 = !{i64 8256520048276991898} 229!21 = !DILocation(line: 8, column: 5, scope: !9) 230!22 = !DISubprogram(name: "foo", linkageName: "_Z3fooi", scope: !1, file: !1, line: 1, type: !10, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized) 231