brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.2 KiB · 8accc83 Raw
139 lines · plain
1;; Check that duplicate spurious duplicate (identical) clones are simply2;; created as aliases to the first identical copy, rather than creating3;; multiple clones that call the same callee clones or have the same4;; allocation types. This currently happens in some cases due to additional5;; cloning performed during function assignment.6;;7;; The ThinLTO combined summary was manually modified as described there8;; to force multiple identical copies of various functions.9 10;; -stats requires asserts11; REQUIRES: asserts12 13; RUN: rm -rf %t && split-file %s %t && cd %t14; RUN: llvm-as src.ll -o src.o15; RUN: llvm-as src.o.thinlto.ll -o src.o.thinlto.bc16; RUN: opt -passes=memprof-context-disambiguation -stats \17; RUN: 	-memprof-import-summary=src.o.thinlto.bc \18; RUN:  -pass-remarks=memprof-context-disambiguation \19; RUN:	src.o -S 2>&1 | FileCheck %s20 21; CHECK: created clone bar.memprof.122;; Duplicates of bar are created as declarations since bar is available_externally,23;; and the compiler does not well support available_externally aliases.24; CHECK: created clone decl bar.memprof.225; CHECK: created clone decl bar.memprof.326; CHECK: created clone _Z3foov.memprof.127;; Duplicates of _Z3foov are created as aliases to the appropriate materialized28;; clone of _Z3foov.29; CHECK: created clone alias _Z3foov.memprof.230; CHECK: created clone alias _Z3foov.memprof.331 32;--- src.ll33source_filename = "memprof-distrib-alias.ll"34target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"35target triple = "x86_64-unknown-linux-gnu"36 37@_Z8fooAliasv = alias ptr (...), ptr @_Z3foov38 39;; Original alias is unchanged.40; CHECK: @_Z8fooAliasv = alias ptr (...), ptr @_Z3foov{{$}}41;; We create an equivalent alias for the cloned def @_Z3foov.memprof.1.42; CHECK: @_Z8fooAliasv.memprof.1 = alias ptr (...), ptr @_Z3foov.memprof.143 44;; We should also create aliases for the duplicate clones of _Z3foov45;; (_Z3foov.memprof.2 and _Z3foov.memprof.3) to the versions they are duplicates46;; of, and ditto for the associated @_Z8fooAliasv clones.47;;48;; _Z3foov.memprof.2 is a duplicate of original _Z3foov, and thus so is _Z8fooAliasv.memprof.249; CHECK: @_Z3foov.memprof.2 = alias ptr (), ptr @_Z3foov{{$}}50; CHECK: @_Z8fooAliasv.memprof.2 = alias ptr (...), ptr @_Z3foov{{$}}51;; _Z3foov.memprof.3 is a duplicate of _Z3foov.memprof.1, and thus so is _Z8fooAliasv.memprof.352; CHECK: @_Z3foov.memprof.3 = alias ptr (), ptr @_Z3foov.memprof.153; CHECK: @_Z8fooAliasv.memprof.3 = alias ptr (...), ptr @_Z3foov.memprof.154 55; CHECK-LABEL: define i32 @main()56define i32 @main() #0 {57entry:58  ;; The first call to bar does not allocate cold memory. It should call59  ;; the original function, which eventually calls the original allocation60  ;; decorated with a "notcold" attribute.61  ; CHECK:   call {{.*}} @bar()62  %call = call ptr @bar(), !callsite !063  ;; The second call to bar allocates cold memory. It should call the cloned64  ;; function which eventually calls a cloned allocation decorated with a65  ;; "cold" attribute.66  ; CHECK:   call {{.*}} @bar.memprof.1()67  %call1 = call ptr @bar(), !callsite !168  ret i32 069}70 71; CHECK-LABEL: define available_externally i32 @bar()72define available_externally i32 @bar() #0 {73entry:74  ; CHECK: call {{.*}} @_Z8fooAliasv()75  %call = call ptr @_Z8fooAliasv(), !callsite !876  ret i32 077}78 79declare ptr @_Znam(i64)80 81; CHECK-LABEL: define ptr @_Z3foov()82define ptr @_Z3foov() #0 {83entry:84  ; CHECK: call {{.*}} @_Znam(i64 0) #[[NOTCOLD:[0-9]+]]85  %call = call ptr @_Znam(i64 0), !memprof !2, !callsite !786  ret ptr null87}88 89; We create actual clone for bar.memprof.1.90; CHECK: define available_externally i32 @bar.memprof.1()91; CHECK:   call {{.*}} @_Z3foov.memprof.1()92 93;; bar.memprof.2 and bar.memprof.3 are duplicates (of original bar and94;; bar.memprof.1, respectively). However, they are available externally,95;; so rather than create an alias we simply create a declaration, since the96;; compiler does not fully support available_externally aliases.97; CHECK: declare i32 @bar.memprof.298; CHECK: declare i32 @bar.memprof.399 100; We create actual clone for foo.memprof.1.101; CHECK: define {{.*}} @_Z3foov.memprof.1()102; CHECK:   call {{.*}} @_Znam(i64 0) #[[COLD:[0-9]+]]103 104; CHECK: attributes #[[NOTCOLD]] = { "memprof"="notcold" }105; CHECK: attributes #[[COLD]] = { "memprof"="cold" }106 107; CHECK: 4 memprof-context-disambiguation - Number of function clone duplicates detected during ThinLTO backend108; CHECK: 2 memprof-context-disambiguation - Number of function clones created during ThinLTO backend109 110attributes #0 = { noinline optnone }111 112!0 = !{i64 8632435727821051414}113!1 = !{i64 -3421689549917153178}114!2 = !{!3, !5}115!3 = !{!4, !"notcold"}116!4 = !{i64 9086428284934609951, i64 1234, i64 8632435727821051414}117!5 = !{!6, !"cold"}118!6 = !{i64 9086428284934609951, i64 1234, i64 -3421689549917153178}119!7 = !{i64 9086428284934609951}120!8 = !{i64 1234}121 122;--- src.o.thinlto.ll123; ModuleID = 'src.o.thinlto.ll'124source_filename = "src.o.thinlto.bc"125 126^0 = module: (path: "src.o", hash: (1720506022, 1575514144, 2506794664, 3599359797, 3160884478))127^1 = gv: (guid: 6583049656999245004, summaries: (alias: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 1, dsoLocal: 1, canAutoHide: 0, importType: definition), aliasee: ^2)))128;; Summary for _Z3foov, where the allocs part has been manually modified to add129;; two additional clones that are the same as the prior versions:130;;	... allocs: ((versions: (notcold, cold, notcold, cold), ...131^2 = gv: (guid: 9191153033785521275, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 1, dsoLocal: 1, canAutoHide: 0, importType: definition), insts: 2, funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0, noInline: 1, alwaysInline: 0, noUnwind: 0, mayThrow: 0, hasUnknownCall: 0, mustBeUnreachable: 0), allocs: ((versions: (notcold, cold, notcold, cold), memProf: ((type: notcold, stackIds: (1234, 8632435727821051414)), (type: cold, stackIds: (1234, 15025054523792398438))))))))132^3 = gv: (guid: 15822663052811949562, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 1, dsoLocal: 1, canAutoHide: 0, importType: definition), insts: 3, funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0, noInline: 1, alwaysInline: 0, noUnwind: 0, mayThrow: 0, hasUnknownCall: 0, mustBeUnreachable: 0), calls: ((callee: ^4)), callsites: ((callee: ^4, clones: (0), stackIds: (8632435727821051414)), (callee: ^4, clones: (1), stackIds: (15025054523792398438))))))133;; Summary for bar, where the callsites part has been manually modified to add134;; two additional clones that are the same as the prior clones:135;;	... callsites: ((callee: ^1, clones: (0, 1, 0, 1), ...136^4 = gv: (guid: 16434608426314478903, summaries: (function: (module: ^0, flags: (linkage: available_externally, visibility: default, notEligibleToImport: 0, live: 1, dsoLocal: 1, canAutoHide: 0, importType: definition), insts: 2, funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0, noInline: 1, alwaysInline: 0, noUnwind: 0, mayThrow: 0, hasUnknownCall: 0, mustBeUnreachable: 0), calls: ((callee: ^1)), callsites: ((callee: ^1, clones: (0, 1, 0, 1), stackIds: (1234))))))137^6 = flags: 353138^7 = blockcount: 0139