232 lines · plain
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.cpp5;; 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.cpp15;; 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 %t30; RUN: opt -thinlto-bc %t/b.ll >%t/b.o31; RUN: opt -thinlto-bc %t/a.ll >%t/a.o32 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: -combined-index-memprof-context \37; RUN: -r=%t/b.o,_Z3fooi,plx \38; RUN: -r=%t/b.o,aliasee,plx \39; RUN: -r=%t/b.o,a \40; RUN: -r=%t/b.o,b \41; RUN: -r=%t/b.o,_Znam \42; RUN: -r=%t/a.o,main,plx \43; RUN: -r=%t/a.o,_Z3fooi \44; RUN: -r=%t/a.o,a,plx \45; RUN: -r=%t/a.o,b,plx \46; RUN: -memprof-dump-ccg \47; RUN: -o %t2.out 2>&148 49; RUN: llvm-dis %t/b.o.thinlto.bc -o - | FileCheck %s --check-prefix=SUMMARY50 51;; Test direct recursion don't cause assert failed and do cloning right.52; RUN: opt -passes=memprof-context-disambiguation \53; RUN: -memprof-import-summary=%t/b.o.thinlto.bc \54; RUN: %t/b.o -S | FileCheck %s --check-prefix=IR55 56; SUMMARY: stackIds: (1985258834072910425, 2841526434899864997)57; SUMMARY-NOT: stackIds: (1985258834072910425, 1985258834072910425, 2841526434899864997)58 59; IR: _Z3fooi60; IR: _Z3fooi.memprof.161; IR: "memprof"="notcold" 62; IR: "memprof"="cold" 63 64;--- b.ll65; ModuleID = 'b.cpp'66source_filename = "b.cpp"67target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"68target triple = "x86_64-unknown-linux-gnu"69 70;; Make sure the distributed summary bitcode writing succeeds when the memprof71;; metadata is in an aliasee.72@_Z3fooi = alias void (), ptr @aliasee73 74@a = external local_unnamed_addr global ptr, align 875@b = external local_unnamed_addr global i32, align 476 77; Function Attrs: mustprogress uwtable78define dso_local void @aliasee(i32 noundef %0) local_unnamed_addr #0 !dbg !9 {79 br label %2, !dbg !1280 812: ; preds = %7, %182 %3 = tail call noalias noundef nonnull dereferenceable(4) ptr @_Znam(i64 noundef 4) #2, !dbg !13, !memprof !14, !callsite !5583 store ptr %3, ptr @a, align 8, !dbg !56, !tbaa !5784 %4 = and i32 %0, 1, !dbg !6185 %5 = icmp eq i32 %4, 0, !dbg !6286 br i1 %5, label %7, label %6, !dbg !6287 886: ; preds = %289 store i32 1, ptr %3, align 4, !tbaa !6390 br label %7, !dbg !6591 927: ; preds = %6, %293 %8 = load i32, ptr @b, align 4, !dbg !65, !tbaa !6394 %9 = add nsw i32 %8, -1, !dbg !6595 store i32 %9, ptr @b, align 4, !dbg !65, !tbaa !6396 %10 = icmp eq i32 %9, 0, !dbg !6697 br i1 %10, label %11, label %2, !dbg !6698 9911: ; preds = %7100 ret void, !dbg !67101}102 103; Function Attrs: nobuiltin allocsize(0)104declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #1105 106attributes #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" }107attributes #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" }108attributes #2 = { builtin allocsize(0) }109 110!llvm.dbg.cu = !{!0}111!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}112!llvm.ident = !{!8}113 114!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)115!1 = !DIFile(filename: "b.cpp", directory: "/", checksumkind: CSK_MD5, checksum: "8fa6c585f9d2c35f1a82b920e64bbda2")116!2 = !{i32 7, !"Dwarf Version", i32 5}117!3 = !{i32 2, !"Debug Info Version", i32 3}118!4 = !{i32 1, !"wchar_size", i32 4}119!5 = !{i32 8, !"PIC Level", i32 2}120!6 = !{i32 7, !"PIE Level", i32 2}121!7 = !{i32 7, !"uwtable", i32 2}122!8 = !{!"clang version 18.0.0"}123!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)124!10 = !DISubroutineType(types: !11)125!11 = !{}126!12 = !DILocation(line: 12, column: 9, scope: !9)127!13 = !DILocation(line: 5, column: 9, scope: !9)128!14 = !{!15, !17, !19, !21, !23, !25, !27, !29, !31, !33, !35, !37, !39, !41, !43, !45, !47, !49, !51, !53}129!15 = !{!16, !"hot"}130!16 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 2841526434899864997}131!17 = !{!18, !"cold"}132!18 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 8256520048276991898}133!19 = !{!20, !"hot"}134!20 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 2841526434899864997}135!21 = !{!22, !"cold"}136!22 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 8256520048276991898}137!23 = !{!24, !"hot"}138!24 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 2841526434899864997}139!25 = !{!26, !"cold"}140!26 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 8256520048276991898}141!27 = !{!28, !"hot"}142!28 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 2841526434899864997}143!29 = !{!30, !"cold"}144!30 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 8256520048276991898}145!31 = !{!32, !"hot"}146!32 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 2841526434899864997}147!33 = !{!34, !"cold"}148!34 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 8256520048276991898}149!35 = !{!36, !"hot"}150!36 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 2841526434899864997}151!37 = !{!38, !"cold"}152!38 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 8256520048276991898}153!39 = !{!40, !"hot"}154!40 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 2841526434899864997}155!41 = !{!42, !"cold"}156!42 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 1985258834072910425, i64 8256520048276991898}157!43 = !{!44, !"hot"}158!44 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 2841526434899864997}159!45 = !{!46, !"cold"}160!46 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 1985258834072910425, i64 8256520048276991898}161!47 = !{!48, !"hot"}162!48 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 2841526434899864997}163!49 = !{!50, !"cold"}164!50 = !{i64 -1057479539165743997, i64 1985258834072910425, i64 8256520048276991898}165!51 = !{!52, !"hot"}166!52 = !{i64 -1057479539165743997, i64 2841526434899864997}167!53 = !{!54, !"cold"}168!54 = !{i64 -1057479539165743997, i64 8256520048276991898}169!55 = !{i64 -1057479539165743997}170!56 = !DILocation(line: 5, column: 7, scope: !9)171!57 = !{!58, !58, i64 0}172!58 = !{!"any pointer", !59, i64 0}173!59 = !{!"omnipotent char", !60, i64 0}174!60 = !{!"Simple C++ TBAA"}175!61 = !DILocation(line: 6, column: 10, scope: !9)176!62 = !DILocation(line: 6, column: 9, scope: !9)177!63 = !{!64, !64, i64 0}178!64 = !{!"int", !59, i64 0}179!65 = !DILocation(line: 10, column: 5, scope: !9)180!66 = !DILocation(line: 11, column: 9, scope: !9)181!67 = !DILocation(line: 14, column: 1, scope: !9)182 183;--- a.ll184; ModuleID = 'a.cpp'185source_filename = "a.cpp"186target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"187target triple = "x86_64-unknown-linux-gnu"188 189@b = dso_local local_unnamed_addr global i32 10, align 4190@a = dso_local local_unnamed_addr global ptr null, align 8191 192; Function Attrs: mustprogress norecurse uwtable193define dso_local noundef i32 @main() local_unnamed_addr #0 !dbg !9 {194 tail call void @_Z3fooi(i32 noundef 1), !dbg !12, !callsite !13195 store i32 10, ptr @b, align 4, !dbg !14, !tbaa !15196 tail call void @_Z3fooi(i32 noundef 2), !dbg !19, !callsite !20197 ret i32 0, !dbg !21198}199 200declare !dbg !22 void @_Z3fooi(i32 noundef) local_unnamed_addr #1201 202attributes #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" }203attributes #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" }204 205!llvm.dbg.cu = !{!0}206!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}207!llvm.ident = !{!8}208 209!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)210!1 = !DIFile(filename: "a.cpp", directory: "/", checksumkind: CSK_MD5, checksum: "16ecbfa723a07d69c0374cfc704a7c44")211!2 = !{i32 7, !"Dwarf Version", i32 5}212!3 = !{i32 2, !"Debug Info Version", i32 3}213!4 = !{i32 1, !"wchar_size", i32 4}214!5 = !{i32 8, !"PIC Level", i32 2}215!6 = !{i32 7, !"PIE Level", i32 2}216!7 = !{i32 7, !"uwtable", i32 2}217!8 = !{!"clang version 18.0.0"}218!9 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 4, type: !10, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)219!10 = !DISubroutineType(types: !11)220!11 = !{}221!12 = !DILocation(line: 5, column: 5, scope: !9)222!13 = !{i64 2841526434899864997}223!14 = !DILocation(line: 6, column: 7, scope: !9)224!15 = !{!16, !16, i64 0}225!16 = !{!"int", !17, i64 0}226!17 = !{!"omnipotent char", !18, i64 0}227!18 = !{!"Simple C++ TBAA"}228!19 = !DILocation(line: 7, column: 5, scope: !9)229!20 = !{i64 8256520048276991898}230!21 = !DILocation(line: 8, column: 5, scope: !9)231!22 = !DISubprogram(name: "foo", linkageName: "_Z3fooi", scope: !1, file: !1, line: 1, type: !10, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)232