brintos

brintos / llvm-project-archived public Read only

0
0
Text · 11.5 KiB · 5bca822 Raw
240 lines · plain
1;; Test for memprof metadata propagation, ensuring metadata is simplified2;; to function attributes appropriately after inlining profiled call chains.3;;4;; The following code was used to generate the following IR and its memprof5;; profile:6;;7;; #include <stdlib.h>8;; #include <string.h>9;; #include <unistd.h>10;; char *foo() {11;;   return new char[10];12;; }13;; char *foo2() {14;;   return foo();15;; }16;; int main(int argc, char **argv) {17;;   char *c = foo();18;;   char *d = foo();19;;   char *e = foo2();20;;   memset(c, 0, 10);21;;   memset(d, 0, 10);22;;   memset(e, 0, 10);23;;   delete[] c;24;;   sleep(200);25;;   delete[] d;26;;   delete[] e;27;;   return 0;28;; }29 30 31;; Also check that remarks are emitted when the allocations are hinted.32; RUN: opt -passes=inline -pass-remarks=memory-profile-info %s -S 2>&1 | FileCheck %s33 34; CHECK: remark: memprof_inline.cc:5:10: call in function _Z4foo2v marked with memprof allocation attribute cold35; CHECK: remark: memprof_inline.cc:5:10: call in function main marked with memprof allocation attribute notcold36; CHECK: remark: memprof_inline.cc:5:10: call in function main marked with memprof allocation attribute cold37 38; ModuleID = 'memprof_inline.cc'39source_filename = "memprof_inline.cc"40target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"41target triple = "x86_64-unknown-linux-gnu"42 43; Function Attrs: mustprogress uwtable44; CHECK-LABEL: define dso_local noundef ptr @_Z3foov45define dso_local noundef ptr @_Z3foov() #0 !dbg !39 {46entry:47  ;; We should keep the original memprof metadata intact.48  ; CHECK: call {{.*}} @_Znam{{.*}} !memprof ![[ORIGMEMPROF:[0-9]+]]49  %call = call noalias noundef nonnull ptr @_Znam(i64 noundef 10) #6, !dbg !42, !memprof !43, !callsite !5050  ; CHECK-NEXT: ret51  ret ptr %call, !dbg !5152}53 54; Function Attrs: nobuiltin allocsize(0)55declare noundef nonnull ptr @_Znam(i64 noundef) #156 57; Function Attrs: mustprogress uwtable58; CHECK-LABEL: define dso_local noundef ptr @_Z4foo2v59define dso_local noundef ptr @_Z4foo2v() #0 !dbg !52 {60entry:61  ; CHECK: call {{.*}} @_Znam{{.*}} #[[COLD:[0-9]+]]62  %call = call noundef ptr @_Z3foov(), !dbg !53, !callsite !5463  ret ptr %call, !dbg !5564}65 66; Function Attrs: mustprogress norecurse uwtable67; CHECK-LABEL: define dso_local noundef i32 @main68define dso_local noundef i32 @main(i32 noundef %argc, ptr noundef %argv) #2 !dbg !56 {69entry:70  %retval = alloca i32, align 471  %argc.addr = alloca i32, align 472  %argv.addr = alloca ptr, align 873  %c = alloca ptr, align 874  %d = alloca ptr, align 875  %e = alloca ptr, align 876  store i32 0, ptr %retval, align 477  store i32 %argc, ptr %argc.addr, align 478  store ptr %argv, ptr %argv.addr, align 879  ; CHECK: call {{.*}} @_Znam{{.*}} #[[NOTCOLD:[0-9]+]]80  %call = call noundef ptr @_Z3foov(), !dbg !57, !callsite !5881  store ptr %call, ptr %c, align 8, !dbg !5982  ; CHECK: call {{.*}} @_Znam{{.*}} #[[COLD]]83  %call1 = call noundef ptr @_Z3foov(), !dbg !60, !callsite !6184  store ptr %call1, ptr %d, align 8, !dbg !6285  ; CHECK: call {{.*}} @_Znam{{.*}} #[[COLD]]86  %call2 = call noundef ptr @_Z4foo2v(), !dbg !63, !callsite !6487  store ptr %call2, ptr %e, align 8, !dbg !6588  %0 = load ptr, ptr %c, align 8, !dbg !6689  call void @llvm.memset.p0.i64(ptr align 1 %0, i8 0, i64 10, i1 false), !dbg !6790  %1 = load ptr, ptr %d, align 8, !dbg !6891  call void @llvm.memset.p0.i64(ptr align 1 %1, i8 0, i64 10, i1 false), !dbg !6992  %2 = load ptr, ptr %e, align 8, !dbg !7093  call void @llvm.memset.p0.i64(ptr align 1 %2, i8 0, i64 10, i1 false), !dbg !7194  %3 = load ptr, ptr %c, align 8, !dbg !7295  %isnull = icmp eq ptr %3, null, !dbg !7396  br i1 %isnull, label %delete.end, label %delete.notnull, !dbg !7397 98delete.notnull:                                   ; preds = %entry99  call void @_ZdaPv(ptr noundef %3) #7, !dbg !74100  br label %delete.end, !dbg !74101 102delete.end:                                       ; preds = %delete.notnull, %entry103  %call4 = call i32 @sleep(i32 noundef 200), !dbg !76104  %4 = load ptr, ptr %d, align 8, !dbg !77105  %isnull5 = icmp eq ptr %4, null, !dbg !78106  br i1 %isnull5, label %delete.end7, label %delete.notnull6, !dbg !78107 108delete.notnull6:                                  ; preds = %delete.end109  call void @_ZdaPv(ptr noundef %4) #7, !dbg !79110  br label %delete.end7, !dbg !79111 112delete.end7:                                      ; preds = %delete.notnull6, %delete.end113  %5 = load ptr, ptr %e, align 8, !dbg !80114  %isnull8 = icmp eq ptr %5, null, !dbg !81115  br i1 %isnull8, label %delete.end10, label %delete.notnull9, !dbg !81116 117delete.notnull9:                                  ; preds = %delete.end7118  call void @_ZdaPv(ptr noundef %5) #7, !dbg !82119  br label %delete.end10, !dbg !82120 121delete.end10:                                     ; preds = %delete.notnull9, %delete.end7122  ret i32 0, !dbg !83123}124 125; Function Attrs: argmemonly nofree nounwind willreturn writeonly126declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3127 128; Function Attrs: nobuiltin nounwind129declare void @_ZdaPv(ptr noundef) #4130 131declare i32 @sleep(i32 noundef) #5132 133; CHECK: attributes #[[COLD]] = { builtin allocsize(0) "memprof"="cold" }134; CHECK: attributes #[[NOTCOLD]] = { builtin allocsize(0) "memprof"="notcold" }135 136attributes #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" }137attributes #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" }138attributes #2 = { mustprogress norecurse 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" }139attributes #3 = { argmemonly nofree nounwind willreturn writeonly }140attributes #4 = { 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" }141attributes #5 = { "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" }142attributes #6 = { builtin allocsize(0) }143attributes #7 = { builtin nounwind }144 145!llvm.dbg.cu = !{!0}146!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8, !9}147!llvm.ident = !{!38}148 149!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)150!1 = !DIFile(filename: "memprof_inline.cc", directory: "/usr/local/google/home/tejohnson/llvm/tmp", checksumkind: CSK_MD5, checksum: "8711f6fd269e6cb5611fef48bc906eab")151!2 = !{i32 7, !"Dwarf Version", i32 5}152!3 = !{i32 2, !"Debug Info Version", i32 3}153!4 = !{i32 1, !"wchar_size", i32 4}154!5 = !{i32 7, !"PIC Level", i32 2}155!6 = !{i32 7, !"PIE Level", i32 2}156!7 = !{i32 7, !"uwtable", i32 2}157!8 = !{i32 7, !"frame-pointer", i32 2}158!9 = !{i32 1, !"ProfileSummary", !10}159!10 = !{!11, !12, !13, !14, !15, !16, !17, !18, !19, !20}160!11 = !{!"ProfileFormat", !"InstrProf"}161!12 = !{!"TotalCount", i64 0}162!13 = !{!"MaxCount", i64 0}163!14 = !{!"MaxInternalCount", i64 0}164!15 = !{!"MaxFunctionCount", i64 0}165!16 = !{!"NumCounts", i64 0}166!17 = !{!"NumFunctions", i64 0}167!18 = !{!"IsPartialProfile", i64 0}168!19 = !{!"PartialProfileRatio", double 0.000000e+00}169!20 = !{!"DetailedSummary", !21}170!21 = !{!22, !23, !24, !25, !26, !27, !28, !29, !30, !31, !32, !33, !34, !35, !36, !37}171!22 = !{i32 10000, i64 0, i32 0}172!23 = !{i32 100000, i64 0, i32 0}173!24 = !{i32 200000, i64 0, i32 0}174!25 = !{i32 300000, i64 0, i32 0}175!26 = !{i32 400000, i64 0, i32 0}176!27 = !{i32 500000, i64 0, i32 0}177!28 = !{i32 600000, i64 0, i32 0}178!29 = !{i32 700000, i64 0, i32 0}179!30 = !{i32 800000, i64 0, i32 0}180!31 = !{i32 900000, i64 0, i32 0}181!32 = !{i32 950000, i64 0, i32 0}182!33 = !{i32 990000, i64 0, i32 0}183!34 = !{i32 999000, i64 0, i32 0}184!35 = !{i32 999900, i64 0, i32 0}185!36 = !{i32 999990, i64 0, i32 0}186!37 = !{i32 999999, i64 0, i32 0}187!38 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project.git e09c924f98ec157adeaa74819b0aec9a07a1b552)"}188!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)189!40 = !DISubroutineType(types: !41)190!41 = !{}191!42 = !DILocation(line: 5, column: 10, scope: !39)192!43 = !{!44, !46, !48}193!44 = !{!45, !"cold"}194!45 = !{i64 -2458008693472584243, i64 7394638144382192936}195!46 = !{!47, !"notcold"}196!47 = !{i64 -2458008693472584243, i64 -8908997186479157179}197!48 = !{!49, !"cold"}198!49 = !{i64 -2458008693472584243, i64 -8079659623765193173}199; CHECK: ![[ORIGMEMPROF]] = !{![[ORIGMIB1:[0-9]+]], ![[ORIGMIB2:[0-9]+]], ![[ORIGMIB3:[0-9]+]]}200; CHECK: ![[ORIGMIB1]] = !{![[ORIGMIBSTACK1:[0-9]+]], !"cold"}201; CHECK: ![[ORIGMIBSTACK1]] = !{i64 -2458008693472584243, i64 7394638144382192936}202; CHECK: ![[ORIGMIB2]] = !{![[ORIGMIBSTACK2:[0-9]+]], !"notcold"}203; CHECK: ![[ORIGMIBSTACK2]] = !{i64 -2458008693472584243, i64 -8908997186479157179}204; CHECK: ![[ORIGMIB3]] = !{![[ORIGMIBSTACK3:[0-9]+]], !"cold"}205; CHECK: ![[ORIGMIBSTACK3]] = !{i64 -2458008693472584243, i64 -8079659623765193173}206!50 = !{i64 -2458008693472584243}207!51 = !DILocation(line: 5, column: 3, scope: !39)208!52 = distinct !DISubprogram(name: "foo2", linkageName: "_Z4foo2v", scope: !1, file: !1, line: 7, type: !40, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !41)209!53 = !DILocation(line: 8, column: 10, scope: !52)210!54 = !{i64 -8079659623765193173}211!55 = !DILocation(line: 8, column: 3, scope: !52)212!56 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 16, type: !40, scopeLine: 16, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !41)213!57 = !DILocation(line: 17, column: 13, scope: !56)214!58 = !{i64 -8908997186479157179}215!59 = !DILocation(line: 17, column: 9, scope: !56)216!60 = !DILocation(line: 18, column: 13, scope: !56)217!61 = !{i64 7394638144382192936}218!62 = !DILocation(line: 18, column: 9, scope: !56)219!63 = !DILocation(line: 19, column: 13, scope: !56)220!64 = !{i64 -5510257407004945023}221!65 = !DILocation(line: 19, column: 9, scope: !56)222!66 = !DILocation(line: 21, column: 10, scope: !56)223!67 = !DILocation(line: 21, column: 3, scope: !56)224!68 = !DILocation(line: 22, column: 10, scope: !56)225!69 = !DILocation(line: 22, column: 3, scope: !56)226!70 = !DILocation(line: 23, column: 10, scope: !56)227!71 = !DILocation(line: 23, column: 3, scope: !56)228!72 = !DILocation(line: 25, column: 12, scope: !56)229!73 = !DILocation(line: 25, column: 3, scope: !56)230!74 = !DILocation(line: 25, column: 3, scope: !75)231!75 = !DILexicalBlockFile(scope: !56, file: !1, discriminator: 2)232!76 = !DILocation(line: 26, column: 3, scope: !56)233!77 = !DILocation(line: 27, column: 12, scope: !56)234!78 = !DILocation(line: 27, column: 3, scope: !56)235!79 = !DILocation(line: 27, column: 3, scope: !75)236!80 = !DILocation(line: 28, column: 12, scope: !56)237!81 = !DILocation(line: 28, column: 3, scope: !56)238!82 = !DILocation(line: 28, column: 3, scope: !75)239!83 = !DILocation(line: 30, column: 3, scope: !56)240