132 lines · plain
1;; Tests memprof profile matching when the leaf frame is missing in the2;; profile. In this case the call to operator new was inlined before3;; matching and we are able to match the next call frame up the inlined4;; context.5 6;; Avoid failures on big-endian systems that can't read the profile properly7; REQUIRES: x86_64-linux8 9;; # To generate below LLVM IR for use in matching.10;; $ clang++ -gmlt -fdebug-info-for-profiling -S memprof_missing_leaf.cc \11;; -O2 -emit-llvm12;;13;; where memprof_missing_leaf.cc is as follows:14;;15;; #include <new>16;;17;; // Use musttail to simulate a missing leaf debug frame in the profiled binary.18;; // Note we don't currently match onto explicit ::operator new calls, which is19;; // why the non-musttail case uses implicit new (which doesn't support musttail).20;; // Note that changes in the code below which affect relative line number21;; // offsets of calls from their parent function can affect callsite matching in22;; // the LLVM IR.23;; #ifndef USE_MUSTTAIL24;; #define USE_MUSTTAIL 025;; #endif26;;27;; // clang::musttail requires that the argument signature matches that of the caller.28;; void *bar(std::size_t s) {29;; #if USE_MUSTTAIL30;; [[clang::musttail]] return ::operator new (s);31;; #else32;; return new char[s];33;; #endif34;; }35;;36;; int main() {37;; char *a = (char *)bar(1);38;; delete a;39;; return 0;40;;}41 42; RUN: split-file %s %t43; RUN: llvm-profdata merge %t/memprof_missing_leaf.yaml -o %t/memprof_missing_leaf.memprofdata44; RUN: opt < %t/memprof_missing_leaf.ll -passes='memprof-use<profile-filename=%t/memprof_missing_leaf.memprofdata>' -S | FileCheck %s45 46;--- memprof_missing_leaf.yaml47---48HeapProfileRecords:49 - GUID: main50 AllocSites:51 - Callstack:52 - { Function: main, LineOffset: 1, Column: 21, IsInlineFrame: false }53 MemInfoBlock:54 AllocCount: 155 TotalSize: 156 TotalLifetime: 057 TotalLifetimeAccessDensity: 058 CallSites: []59...60;--- memprof_missing_leaf.ll61; CHECK: call {{.*}} @_Znam{{.*}} #[[ATTR:[0-9]+]]62; CHECK: attributes #[[ATTR]] = {{.*}} "memprof"="notcold"63 64; ModuleID = '<stdin>'65source_filename = "memprof_missing_leaf.cc"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; Function Attrs: nobuiltin allocsize(0)70declare noundef nonnull ptr @_Znam(i64 noundef) #071 72; Function Attrs: mustprogress norecurse uwtable73define dso_local noundef i32 @main() #1 !dbg !8 {74entry:75 %s.addr.i = alloca i64, align 876 %retval = alloca i32, align 477 %a = alloca ptr, align 878 store i32 0, ptr %retval, align 479 store i64 1, ptr %s.addr.i, align 8, !tbaa !1180 %0 = load i64, ptr %s.addr.i, align 8, !dbg !15, !tbaa !1181 %call.i = call noalias noundef nonnull ptr @_Znam(i64 noundef %0) #3, !dbg !1882 store ptr %call.i, ptr %a, align 8, !dbg !19, !tbaa !2083 %1 = load ptr, ptr %a, align 8, !dbg !22, !tbaa !2084 %isnull = icmp eq ptr %1, null, !dbg !2385 br i1 %isnull, label %delete.end, label %delete.notnull, !dbg !2386 87delete.notnull: ; preds = %entry88 call void @_ZdlPv(ptr noundef %1) #4, !dbg !2389 br label %delete.end, !dbg !2390 91delete.end: ; preds = %delete.notnull, %entry92 ret i32 0, !dbg !2493}94 95; Function Attrs: nobuiltin nounwind96declare void @_ZdlPv(ptr noundef) #297 98attributes #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" }99attributes #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" }100attributes #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" }101attributes #3 = { builtin allocsize(0) }102attributes #4 = { builtin nounwind }103 104!llvm.dbg.cu = !{!0}105!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}106 107!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)108!1 = !DIFile(filename: "memprof_missing_leaf.cc", directory: ".", checksumkind: CSK_MD5, checksum: "f1445a8699406a6b826128704d257677")109!2 = !{i32 7, !"Dwarf Version", i32 5}110!3 = !{i32 2, !"Debug Info Version", i32 3}111!4 = !{i32 1, !"wchar_size", i32 4}112!5 = !{i32 8, !"PIC Level", i32 2}113!6 = !{i32 7, !"PIE Level", i32 2}114!7 = !{i32 7, !"uwtable", i32 2}115!8 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 15, type: !9, scopeLine: 15, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)116!9 = !DISubroutineType(types: !10)117!10 = !{}118!11 = !{!12, !12, i64 0}119!12 = !{!"long", !13, i64 0}120!13 = !{!"omnipotent char", !14, i64 0}121!14 = !{!"Simple C++ TBAA"}122!15 = !DILocation(line: 11, column: 19, scope: !16, inlinedAt: !17)123!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)124!17 = distinct !DILocation(line: 16, column: 21, scope: !8)125!18 = !DILocation(line: 11, column: 10, scope: !16, inlinedAt: !17)126!19 = !DILocation(line: 16, column: 9, scope: !8)127!20 = !{!21, !21, i64 0}128!21 = !{!"any pointer", !13, i64 0}129!22 = !DILocation(line: 17, column: 10, scope: !8)130!23 = !DILocation(line: 17, column: 3, scope: !8)131!24 = !DILocation(line: 18, column: 3, scope: !8)132