brintos

brintos / llvm-project-archived public Read only

0
0
Text · 16.2 KiB · dda3d2e Raw
347 lines · plain
1;; Test callsite context graph generation for simple call graph with2;; two memprof contexts and no inlining, as well as graph and IR cloning.3;;4;; Original code looks like:5;;6;; char *bar() {7;;   return new char[10];8;; }9;;10;; char *baz() {11;;   return bar();12;; }13;;14;; char *foo() {15;;   return baz();16;; }17;;18;; int main(int argc, char **argv) {19;;   char *x = foo();20;;   char *y = foo();21;;   memset(x, 0, 10);22;;   memset(y, 0, 10);23;;   delete[] x;24;;   sleep(10);25;;   delete[] y;26;;   return 0;27;; }28;;29;; Code compiled with -mllvm -memprof-ave-lifetime-cold-threshold=5 so that the30;; memory freed after sleep(10) results in cold lifetimes.31;;32;; The IR was then reduced using llvm-reduce with the expected FileCheck input.33 34;; -stats requires asserts35; REQUIRES: asserts36 37; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \38; RUN:	-memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \39; RUN:	-memprof-export-to-dot -memprof-dot-file-path-prefix=%t. \40; RUN:	-stats -pass-remarks=memprof-context-disambiguation \41; RUN:  -memprof-report-hinted-sizes \42; RUN:	%s -S 2>&1 | FileCheck %s --check-prefix=DUMP --check-prefix=IR \43; RUN:	--check-prefix=STATS --check-prefix=REMARKS --check-prefix=SIZES44 45; RUN:	cat %t.ccg.postbuild.dot | FileCheck %s --check-prefix=DOT46;; We should have cloned bar, baz, and foo, for the cold memory allocation.47; RUN:	cat %t.ccg.cloned.dot | FileCheck %s --check-prefix=DOTCLONED48 49;; Check again without -supports-hot-cold-new and ensure all MIB are cold and50;; that there is no cloning.51; RUN: opt -passes=memprof-context-disambiguation \52; RUN:	-memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \53; RUN:	-memprof-export-to-dot -memprof-dot-file-path-prefix=%t. \54; RUN:	-stats -pass-remarks=memprof-context-disambiguation \55; RUN:	%s -S 2>&1 | FileCheck %s --implicit-check-not="Callsite Context Graph" \56; RUN:	--implicit-check-not="created clone"57 58target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"59target triple = "x86_64-unknown-linux-gnu"60 61define i32 @main() #0 {62entry:63  %call = call noundef ptr @_Z3foov(), !callsite !064  %call1 = call noundef ptr @_Z3foov(), !callsite !165  ret i32 066}67 68; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)69declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #170 71; Function Attrs: nobuiltin72declare void @_ZdaPv() #273 74define internal ptr @_Z3barv() #3 !dbg !15 {75entry:76  %call = call noalias noundef nonnull ptr @_Znam(i64 noundef 10) #6, !memprof !2, !callsite !777  ret ptr null78}79 80declare ptr @_Znam(i64)81 82define internal ptr @_Z3bazv() #4 {83entry:84  %call = call noundef ptr @_Z3barv(), !callsite !885  ret ptr null86}87 88; Function Attrs: noinline89define internal ptr @_Z3foov() #5 {90entry:91  %call = call noundef ptr @_Z3bazv(), !callsite !992  ret ptr null93}94 95; uselistorder directives96uselistorder ptr @_Z3foov, { 1, 0 }97 98attributes #0 = { "tune-cpu"="generic" }99attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }100attributes #2 = { nobuiltin }101attributes #3 = { "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" }102attributes #4 = { "stack-protector-buffer-size"="8" }103attributes #5 = { noinline }104attributes #6 = { builtin }105 106!llvm.dbg.cu = !{!13}107!llvm.module.flags = !{!20, !21}108 109!0 = !{i64 8632435727821051414}110!1 = !{i64 -3421689549917153178}111!2 = !{!3, !5}112!3 = !{!4, !"notcold", !10}113!4 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 8632435727821051414}114!5 = !{!6, !"cold", !11, !12}115!6 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 -3421689549917153178}116!7 = !{i64 9086428284934609951}117!8 = !{i64 -5964873800580613432}118!9 = !{i64 2732490490862098848}119!10 = !{i64 123, i64 100}120!11 = !{i64 456, i64 200}121!12 = !{i64 789, i64 300}122!13 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !14, producer: "clang version 21.0.0git (git@github.com:llvm/llvm-project.git e391301e0e4d9183fe06e69602e87b0bc889aeda)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)123!14 = !DIFile(filename: "basic.cc", directory: "", checksumkind: CSK_MD5, checksum: "8636c46e81402013b9d54e8307d2f149")124!15 = distinct !DISubprogram(name: "bar", linkageName: "_Z3barv", scope: !14, file: !14, line: 1, type: !16, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !13, declaration: !22)125!16 = !DISubroutineType(types: !17)126!17 = !{!18}127!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)128!19 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)129!20 = !{i32 7, !"Dwarf Version", i32 5}130!21 = !{i32 2, !"Debug Info Version", i32 3}131!22 = !DISubprogram(name: "bar", linkageName: "_Z3barv", scope: !14, file: !14, line: 1, type: !16, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)132 133; DUMP: CCG before cloning:134; DUMP: Callsite Context Graph:135; DUMP: Node [[BAR:0x[a-z0-9]+]]136; DUMP: 	  %call = call noalias noundef nonnull ptr @_Znam(i64 noundef 10) #6	(clone 0)137; DUMP: 	NodeId: 1138; DUMP: 	AllocTypes: NotColdCold139; DUMP: 	ContextIds: 1 2140; DUMP: 	CalleeEdges:141; DUMP: 	CallerEdges:142; DUMP: 		Edge from Callee [[BAR]] to Caller: [[BAZ:0x[a-z0-9]+]] AllocTypes: NotColdCold ContextIds: 1 2 (Caller NodeId: 2)143 144; DUMP: Node [[BAZ]]145; DUMP: 	  %call = call noundef ptr @_Z3barv()	(clone 0)146; DUMP: 	NodeId: 2147; DUMP: 	AllocTypes: NotColdCold148; DUMP: 	ContextIds: 1 2149; DUMP: 	CalleeEdges:150; DUMP: 		Edge from Callee [[BAR]] to Caller: [[BAZ]] AllocTypes: NotColdCold ContextIds: 1 2 (Callee NodeId: 1)151; DUMP: 	CallerEdges:152; DUMP: 		Edge from Callee [[BAZ]] to Caller: [[FOO:0x[a-z0-9]+]] AllocTypes: NotColdCold ContextIds: 1 2 (Caller NodeId: 3)153 154; DUMP: Node [[FOO]]155; DUMP: 	  %call = call noundef ptr @_Z3bazv()	(clone 0)156; DUMP: 	NodeId: 3157; DUMP: 	AllocTypes: NotColdCold158; DUMP: 	ContextIds: 1 2159; DUMP: 	CalleeEdges:160; DUMP: 		Edge from Callee [[BAZ]] to Caller: [[FOO]] AllocTypes: NotColdCold ContextIds: 1 2 (Callee NodeId: 2)161; DUMP: 	CallerEdges:162; DUMP: 		Edge from Callee [[FOO]] to Caller: [[MAIN1:0x[a-z0-9]+]] AllocTypes: NotCold ContextIds: 1 (Caller NodeId: 4)163; DUMP: 		Edge from Callee [[FOO]] to Caller: [[MAIN2:0x[a-z0-9]+]] AllocTypes: Cold ContextIds: 2 (Caller NodeId: 5)164 165; DUMP: Node [[MAIN1]]166; DUMP: 	  %call = call noundef ptr @_Z3foov()	(clone 0)167; DUMP: 	NodeId: 4168; DUMP: 	AllocTypes: NotCold169; DUMP: 	ContextIds: 1170; DUMP: 	CalleeEdges:171; DUMP: 		Edge from Callee [[FOO]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1 (Callee NodeId: 3)172; DUMP: 	CallerEdges:173 174; DUMP: Node [[MAIN2]]175; DUMP: 	  %call1 = call noundef ptr @_Z3foov()	(clone 0)176; DUMP: 	NodeId: 5177; DUMP: 	AllocTypes: Cold178; DUMP: 	ContextIds: 2179; DUMP: 	CalleeEdges:180; DUMP: 		Edge from Callee [[FOO]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2 (Callee NodeId: 3)181; DUMP: 	CallerEdges:182 183; DUMP: CCG after cloning:184; DUMP: Callsite Context Graph:185; DUMP: Node [[BAR:0x[a-z0-9]+]]186; DUMP: 	  %call = call noalias noundef nonnull ptr @_Znam(i64 noundef 10) #6	(clone 0)187; DUMP: 	NodeId: 1188; DUMP: 	AllocTypes: NotCold189; DUMP: 	ContextIds: 1190; DUMP: 	CalleeEdges:191; DUMP: 	CallerEdges:192; DUMP: 		Edge from Callee [[BAR]] to Caller: [[BAZ:0x[a-z0-9]+]] AllocTypes: NotCold ContextIds: 1 (Caller NodeId: 2)193; DUMP:		Clones: [[BAR2:0x[a-z0-9]+]] NodeId: 8194 195; DUMP: Node [[BAZ]]196; DUMP: 	  %call = call noundef ptr @_Z3barv()	(clone 0)197; DUMP: 	NodeId: 2198; DUMP: 	AllocTypes: NotCold199; DUMP: 	ContextIds: 1200; DUMP: 	CalleeEdges:201; DUMP: 		Edge from Callee [[BAR]] to Caller: [[BAZ]] AllocTypes: NotCold ContextIds: 1 (Callee NodeId: 1)202; DUMP: 	CallerEdges:203; DUMP: 		Edge from Callee [[BAZ]] to Caller: [[FOO:0x[a-z0-9]+]] AllocTypes: NotCold ContextIds: 1 (Caller NodeId: 3)204; DUMP:		Clones: [[BAZ2:0x[a-z0-9]+]] NodeId: 7205 206; DUMP: Node [[FOO]]207; DUMP: 	  %call = call noundef ptr @_Z3bazv()	(clone 0)208; DUMP: 	NodeId: 3209; DUMP: 	AllocTypes: NotCold210; DUMP: 	ContextIds: 1211; DUMP: 	CalleeEdges:212; DUMP: 		Edge from Callee [[BAZ]] to Caller: [[FOO]] AllocTypes: NotCold ContextIds: 1 (Callee NodeId: 2)213; DUMP: 	CallerEdges:214; DUMP: 		Edge from Callee [[FOO]] to Caller: [[MAIN1:0x[a-z0-9]+]] AllocTypes: NotCold ContextIds: 1 (Caller NodeId: 4)215; DUMP:		Clones: [[FOO2:0x[a-z0-9]+]] NodeId: 6216 217; DUMP: Node [[MAIN1]]218; DUMP: 	  %call = call noundef ptr @_Z3foov()	(clone 0)219; DUMP: 	NodeId: 4220; DUMP: 	AllocTypes: NotCold221; DUMP: 	ContextIds: 1222; DUMP: 	CalleeEdges:223; DUMP: 		Edge from Callee [[FOO]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1 (Callee NodeId: 3)224; DUMP: 	CallerEdges:225 226; DUMP: Node [[MAIN2]]227; DUMP: 	  %call1 = call noundef ptr @_Z3foov()	(clone 0)228; DUMP: 	NodeId: 5229; DUMP: 	AllocTypes: Cold230; DUMP: 	ContextIds: 2231; DUMP: 	CalleeEdges:232; DUMP: 		Edge from Callee [[FOO2]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2 (Callee NodeId: 6)233; DUMP: 	CallerEdges:234 235; DUMP: Node [[FOO2]]236; DUMP: 	  %call = call noundef ptr @_Z3bazv()	(clone 0)237; DUMP: 	NodeId: 6238; DUMP: 	AllocTypes: Cold239; DUMP: 	ContextIds: 2240; DUMP: 	CalleeEdges:241; DUMP: 		Edge from Callee [[BAZ2]] to Caller: [[FOO2]] AllocTypes: Cold ContextIds: 2 (Callee NodeId: 7)242; DUMP: 	CallerEdges:243; DUMP: 		Edge from Callee [[FOO2]] to Caller: [[MAIN2:0x[a-z0-9]+]] AllocTypes: Cold ContextIds: 2 (Caller NodeId: 5)244; DUMP:		Clone of [[FOO]] NodeId: 3245 246; DUMP: Node [[BAZ2]]247; DUMP: 	  %call = call noundef ptr @_Z3barv()	(clone 0)248; DUMP: 	NodeId: 7249; DUMP: 	AllocTypes: Cold250; DUMP: 	ContextIds: 2251; DUMP: 	CalleeEdges:252; DUMP: 		Edge from Callee [[BAR2]] to Caller: [[BAZ2]] AllocTypes: Cold ContextIds: 2 (Callee NodeId: 8)253; DUMP: 	CallerEdges:254; DUMP: 		Edge from Callee [[BAZ2]] to Caller: [[FOO2]] AllocTypes: Cold ContextIds: 2 (Caller NodeId: 6)255; DUMP:		Clone of [[BAZ]] NodeId: 2256 257; DUMP: Node [[BAR2]]258; DUMP: 	  %call = call noalias noundef nonnull ptr @_Znam(i64 noundef 10) #6	(clone 0)259; DUMP: 	NodeId: 8260; DUMP: 	AllocTypes: Cold261; DUMP: 	ContextIds: 2262; DUMP: 	CalleeEdges:263; DUMP: 	CallerEdges:264; DUMP: 		Edge from Callee [[BAR2]] to Caller: [[BAZ2]] AllocTypes: Cold ContextIds: 2 (Caller NodeId: 7)265; DUMP:		Clone of [[BAR]] NodeId: 1266 267 268; REMARKS: created clone _Z3barv.memprof.1269; REMARKS: created clone _Z3bazv.memprof.1270; REMARKS: created clone _Z3foov.memprof.1271; REMARKS: call in clone main assigned to call function clone _Z3foov.memprof.1272; REMARKS: call in clone _Z3foov.memprof.1 assigned to call function clone _Z3bazv.memprof.1273; REMARKS: call in clone _Z3bazv.memprof.1 assigned to call function clone _Z3barv.memprof.1274; REMARKS: call in clone _Z3barv.memprof.1 marked with memprof allocation attribute cold275; REMARKS: call in clone main assigned to call function clone _Z3foov276; REMARKS: call in clone _Z3foov assigned to call function clone _Z3bazv277; REMARKS: call in clone _Z3bazv assigned to call function clone _Z3barv278; REMARKS: call in clone _Z3barv marked with memprof allocation attribute notcold279 280; SIZES: NotCold full allocation context 123 with total size 100 is NotCold after cloning (context id 1)281; SIZES: Cold full allocation context 456 with total size 200 is Cold after cloning (context id 2)282; SIZES: Cold full allocation context 789 with total size 300 is Cold after cloning (context id 2)283 284; IR: define {{.*}} @main285;; The first call to foo does not allocate cold memory. It should call the286;; original functions, which ultimately call the original allocation decorated287;; with a "notcold" attribute.288; IR:   call {{.*}} @_Z3foov()289;; The second call to foo allocates cold memory. It should call cloned functions290;; which ultimately call a cloned allocation decorated with a "cold" attribute.291; IR:   call {{.*}} @_Z3foov.memprof.1()292; IR: define internal {{.*}} @_Z3barv()293; IR:   call {{.*}} @_Znam(i64 noundef 10) #[[NOTCOLD:[0-9]+]]294; IR: define internal {{.*}} @_Z3bazv()295; IR:   call {{.*}} @_Z3barv()296; IR: define internal {{.*}} @_Z3foov()297; IR:   call {{.*}} @_Z3bazv()298; IR: define internal {{.*}} @_Z3barv.memprof.1() {{.*}} !dbg ![[SP:[0-9]+]]299; IR:   call {{.*}} @_Znam(i64 noundef 10) #[[COLD:[0-9]+]]300; IR: define internal {{.*}} @_Z3bazv.memprof.1()301; IR:   call {{.*}} @_Z3barv.memprof.1()302; IR: define internal {{.*}} @_Z3foov.memprof.1()303; IR:   call {{.*}} @_Z3bazv.memprof.1()304; IR: attributes #[[NOTCOLD]] = { builtin "memprof"="notcold" }305; IR: attributes #[[COLD]] = { builtin "memprof"="cold" }306;; Make sure the clone's linkageName was updated.307; IR: ![[SP]] = distinct !DISubprogram(name: "bar", linkageName: "_Z3barv.memprof.1", {{.*}} declaration: ![[SP2:[0-9]+]])308; IR: ![[SP2]] = !DISubprogram(name: "bar", linkageName: "_Z3barv.memprof.1"309 310 311; STATS: 1 memprof-context-disambiguation - Number of cold static allocations (possibly cloned)312; STATS: 1 memprof-context-disambiguation - Number of not cold static allocations (possibly cloned)313; STATS: 3 memprof-context-disambiguation - Number of function clones created during whole program analysis314 315 316; DOT: digraph "postbuild" {317; DOT: 	label="postbuild";318; DOT: 	Node[[BAR:0x[a-z0-9]+]] [shape=record,tooltip="N[[BAR]] ContextIds: 1 2",fillcolor="mediumorchid1",style="filled",label="{OrigId: Alloc0 NodeId: 1\n_Z3barv -\> _Znam}"];319; DOT: 	Node[[BAZ:0x[a-z0-9]+]] [shape=record,tooltip="N[[BAZ]] ContextIds: 1 2",fillcolor="mediumorchid1",style="filled",label="{OrigId: 12481870273128938184 NodeId: 2\n_Z3bazv -\> _Z3barv}"];320; DOT: 	Node[[BAZ]] -> Node[[BAR]][tooltip="ContextIds: 1 2",fillcolor="mediumorchid1",color="mediumorchid1"];321; DOT: 	Node[[FOO:0x[a-z0-9]+]] [shape=record,tooltip="N[[FOO]] ContextIds: 1 2",fillcolor="mediumorchid1",style="filled",label="{OrigId: 2732490490862098848 NodeId: 3\n_Z3foov -\> _Z3bazv}"];322; DOT: 	Node[[FOO]] -> Node[[BAZ]][tooltip="ContextIds: 1 2",fillcolor="mediumorchid1",color="mediumorchid1"];323; DOT: 	Node[[MAIN1:0x[a-z0-9]+]] [shape=record,tooltip="N[[MAIN1]] ContextIds: 1",fillcolor="brown1",style="filled",label="{OrigId: 8632435727821051414 NodeId: 4\nmain -\> _Z3foov}"];324; DOT: 	Node[[MAIN1]] -> Node[[FOO]][tooltip="ContextIds: 1",fillcolor="brown1",color="brown1"];325; DOT: 	Node[[MAIN2:0x[a-z0-9]+]] [shape=record,tooltip="N[[MAIN2]] ContextIds: 2",fillcolor="cyan",style="filled",label="{OrigId: 15025054523792398438 NodeId: 5\nmain -\> _Z3foov}"];326; DOT: 	Node[[MAIN2]] -> Node[[FOO]][tooltip="ContextIds: 2",fillcolor="cyan",color="cyan"];327; DOT: }328 329 330; DOTCLONED: digraph "cloned" {331; DOTCLONED: 	label="cloned";332; DOTCLONED: 	Node[[BAR:0x[a-z0-9]+]] [shape=record,tooltip="N[[BAR]] ContextIds: 1",fillcolor="brown1",style="filled",label="{OrigId: Alloc0 NodeId: 1\n_Z3barv -\> _Znam}"];333; DOTCLONED: 	Node[[BAZ:0x[a-z0-9]+]] [shape=record,tooltip="N[[BAZ]] ContextIds: 1",fillcolor="brown1",style="filled",label="{OrigId: 12481870273128938184 NodeId: 2\n_Z3bazv -\> _Z3barv}"];334; DOTCLONED: 	Node[[BAZ]] -> Node[[BAR]][tooltip="ContextIds: 1",fillcolor="brown1",color="brown1"];335; DOTCLONED: 	Node[[FOO:0x[a-z0-9]+]] [shape=record,tooltip="N[[FOO]] ContextIds: 1",fillcolor="brown1",style="filled",label="{OrigId: 2732490490862098848 NodeId: 3\n_Z3foov -\> _Z3bazv}"];336; DOTCLONED: 	Node[[FOO]] -> Node[[BAZ]][tooltip="ContextIds: 1",fillcolor="brown1",color="brown1"];337; DOTCLONED: 	Node[[MAIN1:0x[a-z0-9]+]] [shape=record,tooltip="N[[MAIN1]] ContextIds: 1",fillcolor="brown1",style="filled",label="{OrigId: 8632435727821051414 NodeId: 4\nmain -\> _Z3foov}"];338; DOTCLONED: 	Node[[MAIN1]] -> Node[[FOO]][tooltip="ContextIds: 1",fillcolor="brown1",color="brown1"];339; DOTCLONED: 	Node[[MAIN2:0x[a-z0-9]+]] [shape=record,tooltip="N[[MAIN2]] ContextIds: 2",fillcolor="cyan",style="filled",label="{OrigId: 15025054523792398438 NodeId: 5\nmain -\> _Z3foov}"];340; DOTCLONED: 	Node[[MAIN2]] -> Node[[FOO2:0x[a-z0-9]+]][tooltip="ContextIds: 2",fillcolor="cyan",color="cyan"];341; DOTCLONED: 	Node[[FOO2]] [shape=record,tooltip="N[[FOO2]] ContextIds: 2",fillcolor="cyan",color="blue",style="filled,bold,dashed",label="{OrigId: 0 NodeId: 6\n_Z3foov -\> _Z3bazv}"];342; DOTCLONED: 	Node[[FOO2]] -> Node[[BAZ2:0x[a-z0-9]+]][tooltip="ContextIds: 2",fillcolor="cyan",color="cyan"];343; DOTCLONED: 	Node[[BAZ2]] [shape=record,tooltip="N[[BAZ2]] ContextIds: 2",fillcolor="cyan",color="blue",style="filled,bold,dashed",label="{OrigId: 0 NodeId: 7\n_Z3bazv -\> _Z3barv}"];344; DOTCLONED: 	Node[[BAZ2]] -> Node[[BAR2:0x[a-z0-9]+]][tooltip="ContextIds: 2",fillcolor="cyan",color="cyan"];345; DOTCLONED: 	Node[[BAR2]] [shape=record,tooltip="N[[BAR2]] ContextIds: 2",fillcolor="cyan",color="blue",style="filled,bold,dashed",label="{OrigId: Alloc0 NodeId: 8\n_Z3barv -\> _Znam}"];346; DOTCLONED: }347