xref: /llvm-project/llvm/test/Transforms/PGOProfile/memprof_missing_leaf.ll (revision a03343daa6e7a44531e06c8897d6c6d4a46cd430)
187f5e229STeresa Johnson;; Tests memprof profile matching when the leaf frame is missing in the
287f5e229STeresa Johnson;; profile. In this case the call to operator new was inlined before
387f5e229STeresa Johnson;; matching and we are able to match the next call frame up the inlined
487f5e229STeresa Johnson;; context.
587f5e229STeresa Johnson
687f5e229STeresa Johnson;; Avoid failures on big-endian systems that can't read the profile properly
787f5e229STeresa Johnson; REQUIRES: x86_64-linux
887f5e229STeresa Johnson
987f5e229STeresa Johnson;; # To generate below LLVM IR for use in matching.
1087f5e229STeresa Johnson;; $ clang++ -gmlt -fdebug-info-for-profiling -S memprof_missing_leaf.cc \
1187f5e229STeresa Johnson;; 	-O2 -emit-llvm
12*a03343daSKazu Hirata;;
13*a03343daSKazu Hirata;; where memprof_missing_leaf.cc is as follows:
14*a03343daSKazu Hirata;;
15*a03343daSKazu Hirata;; #include <new>
16*a03343daSKazu Hirata;;
17*a03343daSKazu Hirata;; // Use musttail to simulate a missing leaf debug frame in the profiled binary.
18*a03343daSKazu Hirata;; // Note we don't currently match onto explicit ::operator new calls, which is
19*a03343daSKazu Hirata;; // why the non-musttail case uses implicit new (which doesn't support musttail).
20*a03343daSKazu Hirata;; // Note that changes in the code below which affect relative line number
21*a03343daSKazu Hirata;; // offsets of calls from their parent function can affect callsite matching in
22*a03343daSKazu Hirata;; // the LLVM IR.
23*a03343daSKazu Hirata;; #ifndef USE_MUSTTAIL
24*a03343daSKazu Hirata;; #define USE_MUSTTAIL 0
25*a03343daSKazu Hirata;; #endif
26*a03343daSKazu Hirata;;
27*a03343daSKazu Hirata;; // clang::musttail requires that the argument signature matches that of the caller.
28*a03343daSKazu Hirata;; void *bar(std::size_t s) {
29*a03343daSKazu Hirata;; #if USE_MUSTTAIL
30*a03343daSKazu Hirata;;   [[clang::musttail]] return ::operator new (s);
31*a03343daSKazu Hirata;; #else
32*a03343daSKazu Hirata;;   return new char[s];
33*a03343daSKazu Hirata;; #endif
34*a03343daSKazu Hirata;; }
35*a03343daSKazu Hirata;;
36*a03343daSKazu Hirata;; int main() {
37*a03343daSKazu Hirata;;   char *a = (char *)bar(1);
38*a03343daSKazu Hirata;;   delete a;
39*a03343daSKazu Hirata;;   return 0;
40*a03343daSKazu Hirata;;}
4187f5e229STeresa Johnson
42*a03343daSKazu Hirata; RUN: split-file %s %t
43*a03343daSKazu Hirata; RUN: llvm-profdata merge %t/memprof_missing_leaf.yaml -o %t/memprof_missing_leaf.memprofdata
44*a03343daSKazu Hirata; RUN: opt < %t/memprof_missing_leaf.ll -passes='memprof-use<profile-filename=%t/memprof_missing_leaf.memprofdata>' -S | FileCheck %s
4587f5e229STeresa Johnson
46*a03343daSKazu Hirata;--- memprof_missing_leaf.yaml
47*a03343daSKazu Hirata---
48*a03343daSKazu HirataHeapProfileRecords:
49*a03343daSKazu Hirata  - GUID:            main
50*a03343daSKazu Hirata    AllocSites:
51*a03343daSKazu Hirata      - Callstack:
52*a03343daSKazu Hirata          - { Function: main, LineOffset: 1, Column: 21, IsInlineFrame: false }
53*a03343daSKazu Hirata        MemInfoBlock:
54*a03343daSKazu Hirata          AllocCount:      1
55*a03343daSKazu Hirata          TotalSize:       1
56*a03343daSKazu Hirata          TotalLifetime:   0
57*a03343daSKazu Hirata          TotalLifetimeAccessDensity: 0
58*a03343daSKazu Hirata    CallSites:       []
59*a03343daSKazu Hirata...
60*a03343daSKazu Hirata;--- memprof_missing_leaf.ll
6187f5e229STeresa Johnson; CHECK: call {{.*}} @_Znam{{.*}} #[[ATTR:[0-9]+]]
6287f5e229STeresa Johnson; CHECK: attributes #[[ATTR]] = {{.*}} "memprof"="notcold"
6387f5e229STeresa Johnson
6487f5e229STeresa Johnson; ModuleID = '<stdin>'
6587f5e229STeresa Johnsonsource_filename = "memprof_missing_leaf.cc"
6687f5e229STeresa Johnsontarget datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
6787f5e229STeresa Johnsontarget triple = "x86_64-unknown-linux-gnu"
6887f5e229STeresa Johnson
6987f5e229STeresa Johnson; Function Attrs: nobuiltin allocsize(0)
7087f5e229STeresa Johnsondeclare noundef nonnull ptr @_Znam(i64 noundef) #0
7187f5e229STeresa Johnson
7287f5e229STeresa Johnson; Function Attrs: mustprogress norecurse uwtable
7387f5e229STeresa Johnsondefine dso_local noundef i32 @main() #1 !dbg !8 {
7487f5e229STeresa Johnsonentry:
7587f5e229STeresa Johnson  %s.addr.i = alloca i64, align 8
7687f5e229STeresa Johnson  %retval = alloca i32, align 4
7787f5e229STeresa Johnson  %a = alloca ptr, align 8
7887f5e229STeresa Johnson  store i32 0, ptr %retval, align 4
7987f5e229STeresa Johnson  store i64 1, ptr %s.addr.i, align 8, !tbaa !11
8087f5e229STeresa Johnson  %0 = load i64, ptr %s.addr.i, align 8, !dbg !15, !tbaa !11
8187f5e229STeresa Johnson  %call.i = call noalias noundef nonnull ptr @_Znam(i64 noundef %0) #3, !dbg !18
8287f5e229STeresa Johnson  store ptr %call.i, ptr %a, align 8, !dbg !19, !tbaa !20
8387f5e229STeresa Johnson  %1 = load ptr, ptr %a, align 8, !dbg !22, !tbaa !20
8487f5e229STeresa Johnson  %isnull = icmp eq ptr %1, null, !dbg !23
8587f5e229STeresa Johnson  br i1 %isnull, label %delete.end, label %delete.notnull, !dbg !23
8687f5e229STeresa Johnson
8787f5e229STeresa Johnsondelete.notnull:                                   ; preds = %entry
8887f5e229STeresa Johnson  call void @_ZdlPv(ptr noundef %1) #4, !dbg !23
8987f5e229STeresa Johnson  br label %delete.end, !dbg !23
9087f5e229STeresa Johnson
9187f5e229STeresa Johnsondelete.end:                                       ; preds = %delete.notnull, %entry
9287f5e229STeresa Johnson  ret i32 0, !dbg !24
9387f5e229STeresa Johnson}
9487f5e229STeresa Johnson
9587f5e229STeresa Johnson; Function Attrs: nobuiltin nounwind
9687f5e229STeresa Johnsondeclare void @_ZdlPv(ptr noundef) #2
9787f5e229STeresa Johnson
9887f5e229STeresa Johnsonattributes #0 = { 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" }
9987f5e229STeresa Johnsonattributes #1 = { 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" }
10087f5e229STeresa Johnsonattributes #2 = { nobuiltin nounwind "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" }
10187f5e229STeresa Johnsonattributes #3 = { builtin allocsize(0) }
10287f5e229STeresa Johnsonattributes #4 = { builtin nounwind }
10387f5e229STeresa Johnson
10487f5e229STeresa Johnson!llvm.dbg.cu = !{!0}
10587f5e229STeresa Johnson!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
10687f5e229STeresa Johnson
10787f5e229STeresa Johnson!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 18.0.0 (git@github.com:llvm/llvm-project.git 71bf052ec90e77cb4aa66505d47cbc4b6016ac1d)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None)
10887f5e229STeresa Johnson!1 = !DIFile(filename: "memprof_missing_leaf.cc", directory: ".", checksumkind: CSK_MD5, checksum: "f1445a8699406a6b826128704d257677")
10987f5e229STeresa Johnson!2 = !{i32 7, !"Dwarf Version", i32 5}
11087f5e229STeresa Johnson!3 = !{i32 2, !"Debug Info Version", i32 3}
11187f5e229STeresa Johnson!4 = !{i32 1, !"wchar_size", i32 4}
11287f5e229STeresa Johnson!5 = !{i32 8, !"PIC Level", i32 2}
11387f5e229STeresa Johnson!6 = !{i32 7, !"PIE Level", i32 2}
11487f5e229STeresa Johnson!7 = !{i32 7, !"uwtable", i32 2}
11587f5e229STeresa Johnson!8 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 15, type: !9, scopeLine: 15, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
11687f5e229STeresa Johnson!9 = !DISubroutineType(types: !10)
11787f5e229STeresa Johnson!10 = !{}
11887f5e229STeresa Johnson!11 = !{!12, !12, i64 0}
11987f5e229STeresa Johnson!12 = !{!"long", !13, i64 0}
12087f5e229STeresa Johnson!13 = !{!"omnipotent char", !14, i64 0}
12187f5e229STeresa Johnson!14 = !{!"Simple C++ TBAA"}
12287f5e229STeresa Johnson!15 = !DILocation(line: 11, column: 19, scope: !16, inlinedAt: !17)
12387f5e229STeresa Johnson!16 = distinct !DISubprogram(name: "bar", linkageName: "_Z3barm", scope: !1, file: !1, line: 7, type: !9, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
12487f5e229STeresa Johnson!17 = distinct !DILocation(line: 16, column: 21, scope: !8)
12587f5e229STeresa Johnson!18 = !DILocation(line: 11, column: 10, scope: !16, inlinedAt: !17)
12687f5e229STeresa Johnson!19 = !DILocation(line: 16, column: 9, scope: !8)
12787f5e229STeresa Johnson!20 = !{!21, !21, i64 0}
12887f5e229STeresa Johnson!21 = !{!"any pointer", !13, i64 0}
12987f5e229STeresa Johnson!22 = !DILocation(line: 17, column: 10, scope: !8)
13087f5e229STeresa Johnson!23 = !DILocation(line: 17, column: 3, scope: !8)
13187f5e229STeresa Johnson!24 = !DILocation(line: 18, column: 3, scope: !8)
132