brintos

brintos / llvm-project-archived public Read only

0
0
Text · 16.0 KiB · d2e3927 Raw
327 lines · plain
1;; Test for memprof metadata propagation, ensuring metadata is moved to2;; inlined callsites.3;; Also check that callsite metadata was updated with inlined stack ids.4;;5;; The following code was used to generate the following IR and its memprof6;; profile:7;;8;; #include <stdlib.h>9;; #include <string.h>10;; #include <unistd.h>11;; char *foo() {12;;   return new char[10];13;; }14;; char *foo2() __attribute((noinline)) {15;;   return foo();16;; }17;; char *bar() {18;;   return foo2();19;; }20;; char *baz() {21;;   return foo2();22;; }23;; int main(int argc, char **argv) {24;;   char *c = foo();25;;   char *d = foo();26;;   char *e = bar();27;;   char *f = baz();28;;   memset(c, 0, 10);29;;   memset(d, 0, 10);30;;   memset(e, 0, 10);31;;   memset(f, 0, 10);32;;   delete[] c;33;;   sleep(200);34;;   delete[] d;35;;   delete[] e;36;;   delete[] f;37;;   return 0;38;; }39 40; RUN: opt -passes=inline %s -S | FileCheck %s41;; We should not perform additional discarding of non-cold contexts when42;; rebuilding the tries after inlining, even with a very low threshold.43; RUN: opt -passes=inline -memprof-callsite-cold-threshold=1 %s -S | FileCheck %s44 45; ModuleID = 'memprof_inline2.cc'46source_filename = "memprof_inline2.cc"47target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"48target triple = "x86_64-unknown-linux-gnu"49 50; Function Attrs: mustprogress uwtable51; CHECK-LABEL: define dso_local noundef ptr @_Z3foov52define dso_local noundef ptr @_Z3foov() #0 !dbg !39 {53entry:54  ;; We should keep the original memprof metadata intact.55  ; CHECK: call {{.*}} @_Znam{{.*}} !memprof ![[ORIGMEMPROF:[0-9]+]]56  %call = call noalias noundef nonnull ptr @_Znam(i64 noundef 10) #7, !dbg !42, !memprof !43, !callsite !5257  ret ptr %call, !dbg !5358}59 60; Function Attrs: nobuiltin allocsize(0)61declare noundef nonnull ptr @_Znam(i64 noundef) #162 63;; Mark noinline so we don't inline into calls from bar and baz. We should end64;; up with a memprof metadata on the call to foo below.65; Function Attrs: mustprogress noinline uwtable66; CHECK-LABEL: define dso_local noundef ptr @_Z4foo2v67define dso_local noundef ptr @_Z4foo2v() #2 !dbg !54 {68entry:69  ;; We should have memprof metadata for the call stacks from bar and baz,70  ;; and the callsite metadata should be the concatentation of the id from the71  ;; inlined call to new and the original callsite.72  ; CHECK: call {{.*}} @_Znam{{.*}} !memprof ![[NEWMEMPROF:[0-9]+]], !callsite ![[NEWCALLSITE:[0-9]+]]73  %call = call noundef ptr @_Z3foov(), !dbg !55, !callsite !5674  ret ptr %call, !dbg !5775}76 77; Function Attrs: mustprogress uwtable78define dso_local noundef ptr @_Z3barv() #0 !dbg !58 {79entry:80  %call = call noundef ptr @_Z4foo2v(), !dbg !59, !callsite !6081  ret ptr %call, !dbg !6182}83 84; Function Attrs: mustprogress uwtable85define dso_local noundef ptr @_Z3bazv() #0 !dbg !62 {86entry:87  %call = call noundef ptr @_Z4foo2v(), !dbg !63, !callsite !6488  ret ptr %call, !dbg !6589}90 91;; Make sure we don't propagate any memprof/callsite metadata92; Function Attrs: mustprogress uwtable93; CHECK-LABEL: define dso_local noundef ptr @notprofiled94define dso_local noundef ptr @notprofiled() #0 !dbg !66 {95entry:96  ;; When foo is inlined, both the memprof and callsite metadata should be97  ;; stripped from the inlined call to new, as there is no callsite metadata on98  ;; the call.99  ; CHECK: call {{.*}} @_Znam100  ; CHECK-NOT: !memprof101  ; CHECK-NOT: !callsite102  %call = call noundef ptr @_Z3foov(), !dbg !67103  ;; When baz is inlined, the callsite metadata should be stripped from the104  ;; inlined call to foo2, as there is no callsite metadata on the call.105  ; CHECK: call {{.*}} @_Z4foo2v106  ; CHECK-NOT: !callsite107  %call2 = call noundef ptr @_Z3bazv()108  ; CHECK-NEXT: ret109  ret ptr %call, !dbg !68110}111 112; Function Attrs: mustprogress noinline norecurse optnone uwtable113define dso_local noundef i32 @main(i32 noundef %argc, ptr noundef %argv) #3 !dbg !69 {114entry:115  %retval = alloca i32, align 4116  %argc.addr = alloca i32, align 4117  %argv.addr = alloca ptr, align 8118  %c = alloca ptr, align 8119  %d = alloca ptr, align 8120  %e = alloca ptr, align 8121  %f = alloca ptr, align 8122  store i32 0, ptr %retval, align 4123  store i32 %argc, ptr %argc.addr, align 4124  store ptr %argv, ptr %argv.addr, align 8125  ;; The below 4 callsites are all annotated as noinline126  %call = call noundef ptr @_Z3foov() #8, !dbg !70, !callsite !71127  store ptr %call, ptr %c, align 8, !dbg !72128  %call1 = call noundef ptr @_Z3foov() #8, !dbg !73, !callsite !74129  store ptr %call1, ptr %d, align 8, !dbg !75130  %call2 = call noundef ptr @_Z3barv() #8, !dbg !76, !callsite !77131  store ptr %call2, ptr %e, align 8, !dbg !78132  %call3 = call noundef ptr @_Z3bazv() #8, !dbg !79, !callsite !80133  store ptr %call3, ptr %f, align 8, !dbg !81134  %0 = load ptr, ptr %c, align 8, !dbg !82135  call void @llvm.memset.p0.i64(ptr align 1 %0, i8 0, i64 10, i1 false), !dbg !83136  %1 = load ptr, ptr %d, align 8, !dbg !84137  call void @llvm.memset.p0.i64(ptr align 1 %1, i8 0, i64 10, i1 false), !dbg !85138  %2 = load ptr, ptr %e, align 8, !dbg !86139  call void @llvm.memset.p0.i64(ptr align 1 %2, i8 0, i64 10, i1 false), !dbg !87140  %3 = load ptr, ptr %f, align 8, !dbg !88141  call void @llvm.memset.p0.i64(ptr align 1 %3, i8 0, i64 10, i1 false), !dbg !89142  %4 = load ptr, ptr %c, align 8, !dbg !90143  %isnull = icmp eq ptr %4, null, !dbg !91144  br i1 %isnull, label %delete.end, label %delete.notnull, !dbg !91145 146delete.notnull:                                   ; preds = %entry147  call void @_ZdaPv(ptr noundef %4) #9, !dbg !92148  br label %delete.end, !dbg !92149 150delete.end:                                       ; preds = %delete.notnull, %entry151  %call4 = call i32 @sleep(i32 noundef 200), !dbg !94152  %5 = load ptr, ptr %d, align 8, !dbg !95153  %isnull5 = icmp eq ptr %5, null, !dbg !96154  br i1 %isnull5, label %delete.end7, label %delete.notnull6, !dbg !96155 156delete.notnull6:                                  ; preds = %delete.end157  call void @_ZdaPv(ptr noundef %5) #9, !dbg !97158  br label %delete.end7, !dbg !97159 160delete.end7:                                      ; preds = %delete.notnull6, %delete.end161  %6 = load ptr, ptr %e, align 8, !dbg !98162  %isnull8 = icmp eq ptr %6, null, !dbg !99163  br i1 %isnull8, label %delete.end10, label %delete.notnull9, !dbg !99164 165delete.notnull9:                                  ; preds = %delete.end7166  call void @_ZdaPv(ptr noundef %6) #9, !dbg !100167  br label %delete.end10, !dbg !100168 169delete.end10:                                     ; preds = %delete.notnull9, %delete.end7170  %7 = load ptr, ptr %f, align 8, !dbg !101171  %isnull11 = icmp eq ptr %7, null, !dbg !102172  br i1 %isnull11, label %delete.end13, label %delete.notnull12, !dbg !102173 174delete.notnull12:                                 ; preds = %delete.end10175  call void @_ZdaPv(ptr noundef %7) #9, !dbg !103176  br label %delete.end13, !dbg !103177 178delete.end13:                                     ; preds = %delete.notnull12, %delete.end10179  ret i32 0, !dbg !104180}181 182; Function Attrs: argmemonly nofree nounwind willreturn writeonly183declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4184 185; Function Attrs: nobuiltin nounwind186declare void @_ZdaPv(ptr noundef) #5187 188declare i32 @sleep(i32 noundef) #6189 190attributes #0 = { mustprogress uwtable "disable-tail-calls"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }191attributes #1 = { nobuiltin allocsize(0) "disable-tail-calls"="true" "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }192attributes #2 = { mustprogress noinline uwtable "disable-tail-calls"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }193attributes #3 = { mustprogress noinline norecurse optnone uwtable "disable-tail-calls"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }194attributes #4 = { argmemonly nofree nounwind willreturn writeonly }195attributes #5 = { nobuiltin nounwind "disable-tail-calls"="true" "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }196attributes #6 = { "disable-tail-calls"="true" "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }197attributes #7 = { builtin allocsize(0) }198attributes #8 = { noinline }199attributes #9 = { builtin nounwind }200 201!llvm.dbg.cu = !{!0}202!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8, !9}203!llvm.ident = !{!38}204 205!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 15.0.0 (https://github.com/llvm/llvm-project.git e09c924f98ec157adeaa74819b0aec9a07a1b552)", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None)206!1 = !DIFile(filename: "memprof_inline.cc", directory: "/usr/local/google/home/tejohnson/llvm/tmp", checksumkind: CSK_MD5, checksum: "8711f6fd269e6cb5611fef48bc906eab")207!2 = !{i32 7, !"Dwarf Version", i32 5}208!3 = !{i32 2, !"Debug Info Version", i32 3}209!4 = !{i32 1, !"wchar_size", i32 4}210!5 = !{i32 7, !"PIC Level", i32 2}211!6 = !{i32 7, !"PIE Level", i32 2}212!7 = !{i32 7, !"uwtable", i32 2}213!8 = !{i32 7, !"frame-pointer", i32 2}214!9 = !{i32 1, !"ProfileSummary", !10}215!10 = !{!11, !12, !13, !14, !15, !16, !17, !18, !19, !20}216!11 = !{!"ProfileFormat", !"InstrProf"}217!12 = !{!"TotalCount", i64 0}218!13 = !{!"MaxCount", i64 0}219!14 = !{!"MaxInternalCount", i64 0}220!15 = !{!"MaxFunctionCount", i64 0}221!16 = !{!"NumCounts", i64 0}222!17 = !{!"NumFunctions", i64 0}223!18 = !{!"IsPartialProfile", i64 0}224!19 = !{!"PartialProfileRatio", double 0.000000e+00}225!20 = !{!"DetailedSummary", !21}226!21 = !{!22, !23, !24, !25, !26, !27, !28, !29, !30, !31, !32, !33, !34, !35, !36, !37}227!22 = !{i32 10000, i64 0, i32 0}228!23 = !{i32 100000, i64 0, i32 0}229!24 = !{i32 200000, i64 0, i32 0}230!25 = !{i32 300000, i64 0, i32 0}231!26 = !{i32 400000, i64 0, i32 0}232!27 = !{i32 500000, i64 0, i32 0}233!28 = !{i32 600000, i64 0, i32 0}234!29 = !{i32 700000, i64 0, i32 0}235!30 = !{i32 800000, i64 0, i32 0}236!31 = !{i32 900000, i64 0, i32 0}237!32 = !{i32 950000, i64 0, i32 0}238!33 = !{i32 990000, i64 0, i32 0}239!34 = !{i32 999000, i64 0, i32 0}240!35 = !{i32 999900, i64 0, i32 0}241!36 = !{i32 999990, i64 0, i32 0}242!37 = !{i32 999999, i64 0, i32 0}243!38 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project.git e09c924f98ec157adeaa74819b0aec9a07a1b552)"}244!39 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file: !1, line: 4, type: !40, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !41)245!40 = !DISubroutineType(types: !41)246!41 = !{}247!42 = !DILocation(line: 5, column: 10, scope: !39)248;; The first 2 are from the direct calls to foo from main. Those stay on the249;; callsite in foo, which isn't inlined into main due to the callsites in main250;; being annotated as noinline.251;; The second 2 are from the calls from foo2, which inlines its callsite to foo252;; but is not itself inlined into its callers. Therefore they get moved to a253;; new memprof metadata within foo2.254!43 = !{!44, !46, !48, !50}255!44 = !{!45, !"cold"}256!45 = !{i64 -2458008693472584243, i64 7394638144382192936}257!46 = !{!47, !"notcold"}258!47 = !{i64 -2458008693472584243, i64 -8908997186479157179}259!48 = !{!49, !"notcold"}260!49 = !{i64 -2458008693472584243, i64 -8079659623765193173, i64 -4805294506621015872}261!50 = !{!51, !"cold"}262!51 = !{i64 -2458008693472584243, i64 -8079659623765193173, i64 -972865200055133905}263; CHECK: ![[ORIGMEMPROF]] = !{![[ORIGMIB1:[0-9]+]], ![[ORIGMIB2:[0-9]+]], ![[ORIGMIB3:[0-9]+]], ![[ORIGMIB4:[0-9]+]]}264; CHECK: ![[ORIGMIB1]] = !{![[ORIGMIBSTACK1:[0-9]+]], !"cold"}265; CHECK: ![[ORIGMIBSTACK1]] = !{i64 -2458008693472584243, i64 7394638144382192936}266; CHECK: ![[ORIGMIB2]] = !{![[ORIGMIBSTACK2:[0-9]+]], !"notcold"}267; CHECK: ![[ORIGMIBSTACK2]] = !{i64 -2458008693472584243, i64 -8908997186479157179}268; CHECK: ![[ORIGMIB3]] = !{![[ORIGMIBSTACK3:[0-9]+]], !"notcold"}269; CHECK: ![[ORIGMIBSTACK3]] = !{i64 -2458008693472584243, i64 -8079659623765193173, i64 -4805294506621015872}270; CHECK: ![[ORIGMIB4]] = !{![[ORIGMIBSTACK4:[0-9]+]], !"cold"}271; CHECK: ![[ORIGMIBSTACK4]] = !{i64 -2458008693472584243, i64 -8079659623765193173, i64 -972865200055133905}272; CHECK: ![[NEWMEMPROF]] = !{![[ORIGMIB3:[0-9]+]], ![[ORIGMIB4:[0-9]+]]}273; CHECK: ![[NEWCALLSITE]] = !{i64 -2458008693472584243, i64 -8079659623765193173}274!52 = !{i64 -2458008693472584243}275!53 = !DILocation(line: 5, column: 3, scope: !39)276!54 = distinct !DISubprogram(name: "foo2", linkageName: "_Z4foo2v", scope: !1, file: !1, line: 7, type: !40, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !41)277!55 = !DILocation(line: 8, column: 10, scope: !54)278!56 = !{i64 -8079659623765193173}279!57 = !DILocation(line: 8, column: 3, scope: !54)280!58 = distinct !DISubprogram(name: "bar", linkageName: "_Z3barv", scope: !1, file: !1, line: 10, type: !40, scopeLine: 10, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !41)281!59 = !DILocation(line: 11, column: 10, scope: !58)282!60 = !{i64 -972865200055133905}283!61 = !DILocation(line: 11, column: 3, scope: !58)284!62 = distinct !DISubprogram(name: "baz", linkageName: "_Z3bazv", scope: !1, file: !1, line: 13, type: !40, scopeLine: 13, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !41)285!63 = !DILocation(line: 14, column: 10, scope: !62)286!64 = !{i64 -4805294506621015872}287!65 = !DILocation(line: 14, column: 3, scope: !62)288!66 = distinct !DISubprogram(name: "notprofiled", linkageName: "notprofiled", scope: !1, file: !1, line: 400, type: !40, scopeLine: 400, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !41)289!67 = !DILocation(line: 401, column: 10, scope: !66)290!68 = !DILocation(line: 401, column: 3, scope: !66)291!69 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 16, type: !40, scopeLine: 16, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !41)292!70 = !DILocation(line: 17, column: 13, scope: !69)293!71 = !{i64 -8908997186479157179}294!72 = !DILocation(line: 17, column: 9, scope: !69)295!73 = !DILocation(line: 18, column: 13, scope: !69)296!74 = !{i64 7394638144382192936}297!75 = !DILocation(line: 18, column: 9, scope: !69)298!76 = !DILocation(line: 19, column: 13, scope: !69)299!77 = !{i64 -5510257407004945023}300!78 = !DILocation(line: 19, column: 9, scope: !69)301!79 = !DILocation(line: 20, column: 13, scope: !69)302!80 = !{i64 8771588133652501463}303!81 = !DILocation(line: 20, column: 9, scope: !69)304!82 = !DILocation(line: 21, column: 10, scope: !69)305!83 = !DILocation(line: 21, column: 3, scope: !69)306!84 = !DILocation(line: 22, column: 10, scope: !69)307!85 = !DILocation(line: 22, column: 3, scope: !69)308!86 = !DILocation(line: 23, column: 10, scope: !69)309!87 = !DILocation(line: 23, column: 3, scope: !69)310!88 = !DILocation(line: 24, column: 10, scope: !69)311!89 = !DILocation(line: 24, column: 3, scope: !69)312!90 = !DILocation(line: 25, column: 12, scope: !69)313!91 = !DILocation(line: 25, column: 3, scope: !69)314!92 = !DILocation(line: 25, column: 3, scope: !93)315!93 = !DILexicalBlockFile(scope: !69, file: !1, discriminator: 2)316!94 = !DILocation(line: 26, column: 3, scope: !69)317!95 = !DILocation(line: 27, column: 12, scope: !69)318!96 = !DILocation(line: 27, column: 3, scope: !69)319!97 = !DILocation(line: 27, column: 3, scope: !93)320!98 = !DILocation(line: 28, column: 12, scope: !69)321!99 = !DILocation(line: 28, column: 3, scope: !69)322!100 = !DILocation(line: 28, column: 3, scope: !93)323!101 = !DILocation(line: 29, column: 12, scope: !69)324!102 = !DILocation(line: 29, column: 3, scope: !69)325!103 = !DILocation(line: 29, column: 3, scope: !93)326!104 = !DILocation(line: 30, column: 3, scope: !69)327