brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.1 KiB · 77880db Raw
132 lines · plain
1; REQUIRES: x86_64-linux2; RUN: rm -rf %t3; RUN: split-file %s %t4; RUN: llvm-ctxprof-util fromYAML --input=%t/profile.yaml --output=%t/profile.ctxprofdata5 6; RUN: opt -passes='module-inline,print<ctx-prof-analysis>' -ctx-profile-printer-level=everything %t/1000.ll -S \7; RUN:   -use-ctx-profile=%t/profile.ctxprofdata -ctx-profile-printer-level=yaml \8; RUN:   -o - 2> %t/profile-final.yaml | FileCheck %s9; RUN: diff %t/profile-final.yaml %t/expected.yaml10 11; There are 2 calls to @a from @entrypoint. We only inline the one callsite12; marked as alwaysinline, the rest are blocked (marked noinline). After the inline,13; the updated contextual profile should still have the same tree for the non-inlined case.14; For the inlined case, we should observe, for the @entrypoint context:15;  - an empty callsite where the inlined one was (first one, i.e. 0)16;  - more counters appended to the old counter list (because we ingested the17;    ones from @a). The values are copied.18;  - a new callsite to @b19; CHECK-LABEL: @entrypoint20; CHECK-LABEL: yes:21; CHECK:         call void @llvm.instrprof.increment(ptr @entrypoint, i64 0, i32 3, i32 1)22; CHECK-NEXT:    br label %loop.i23; CHECK-LABEL:  loop.i:24; CHECK-NEXT:    %indvar.i = phi i32 [ %indvar.next.i, %loop.i ], [ 0, %yes ]25; CHECK-NEXT:    call void @llvm.instrprof.increment(ptr @entrypoint, i64 0, i32 2, i32 3)26; CHECK-NEXT:    %b.i = add i32 %x, %indvar.i27; CHECK-NEXT:    call void @llvm.instrprof.callsite(ptr @entrypoint, i64 0, i32 1, i32 2, ptr @b)28; CHECK-NEXT:    %call3.i = call i32 @b() #129; CHECK-LABEL: no:30; CHECK-NEXT:    call void @llvm.instrprof.increment(ptr @entrypoint, i64 0, i32 3, i32 2)31; CHECK-NEXT:    call void @llvm.instrprof.callsite(ptr @entrypoint, i64 0, i32 2, i32 1, ptr @a)32; CHECK-NEXT:    %call2 = call i32 @a(i32 %x) #133; CHECK-NEXT:    br label %exit34 35; Make sure the postlink thinlto pipeline is aware of ctxprof36; RUN: opt -passes='thinlto<O2>' -use-ctx-profile=%t/profile.ctxprofdata \37; RUN:   %t/1000.ll -S -o - | FileCheck %s --check-prefix=PIPELINE38 39; PIPELINE-LABEL: define i32 @entrypoint40; PIPELINE-SAME: !prof ![[ENTRYPOINT_COUNT:[0-9]+]]41; PIPELINE-LABEL: loop.i:42; PIPELINE:         br i1 %cond.i, label %loop.i, label %exit, !prof ![[LOOP_BW_INL:[0-9]+]]43; PIPELINE-LABEL: define i32 @a44; PIPELINE-LABEL: loop:45; PIPELINE:         br i1 %cond, label %loop, label %exit, !prof ![[LOOP_BW_ORIG:[0-9]+]]46 47; *Note* that all values are multiplied by the TotalRootEntryCount, which is 2448;49; PIPELINE: ![[ENTRYPOINT_COUNT]] = !{!"function_entry_count", i64 240}50; These are the weights of the inlined @a, where the counters were 2, 100 (2 for entry, 100 for loop)51; PIPELINE: ![[LOOP_BW_INL]] = !{!"branch_weights", i32 2352, i32 48}52; These are the weights of the un-inlined @a, where the counters were 8, 500 (8 for entry, 500 for loop)53; PIPELINE: ![[LOOP_BW_ORIG]] = !{!"branch_weights", i32 11808, i32 192}54 55;--- 1000.ll56define i32 @entrypoint(i32 %x) !guid !0 {57  call void @llvm.instrprof.increment(ptr @entrypoint, i64 0, i32 3, i32 0)58  %t = icmp eq i32 %x, 059  br i1 %t, label %yes, label %no60yes:61  call void @llvm.instrprof.increment(ptr @entrypoint, i64 0, i32 3, i32 1)62  call void @llvm.instrprof.callsite(ptr @entrypoint, i64 0, i32 2, i32 0, ptr @a)63  %call1 = call i32 @a(i32 %x) alwaysinline64  br label %exit65no:66  call void @llvm.instrprof.increment(ptr @entrypoint, i64 0, i32 3, i32 2)67  call void @llvm.instrprof.callsite(ptr @entrypoint, i64 0, i32 2, i32 1, ptr @a)68  %call2 = call i32 @a(i32 %x) noinline69  br label %exit70exit:71  %ret = phi i32 [%call1, %yes], [%call2, %no]72  ret i32 %ret73}74 75define i32 @a(i32 %x) !guid !1 {76entry:77  call void @llvm.instrprof.increment(ptr @a, i64 0, i32 2, i32 0)78  br label %loop79loop:80  %indvar = phi i32 [%indvar.next, %loop], [0, %entry]81  call void @llvm.instrprof.increment(ptr @a, i64 0, i32 2, i32 1)82  %b = add i32 %x, %indvar83  call void @llvm.instrprof.callsite(ptr @a, i64 0, i32 1, i32 0, ptr @b)84  %call3 = call i32 @b() noinline85  %indvar.next = add i32 %indvar, %call386  %cond = icmp slt i32 %indvar.next, %x87  br i1 %cond, label %loop, label %exit88exit:89  ret i32 890}91 92define i32 @b() !guid !2 {93  call void @llvm.instrprof.increment(ptr @b, i64 0, i32 1, i32 0)94  ret i32 195}96 97!0 = !{i64 1000}98!1 = !{i64 1001}99!2 = !{i64 1002}100;--- profile.yaml101Contexts:102  - Guid: 1000103    TotalRootEntryCount: 24104    Counters: [10, 2, 8]105    Callsites:  -106                  - Guid: 1001107                    Counters: [2, 100]108                    Callsites:  -109                                  - Guid: 1002110                                    Counters: [100]111                -112                  - Guid: 1001113                    Counters: [8, 500]114                    Callsites:  -115                                  - Guid: 1002116                                    Counters: [500]117;--- expected.yaml118 119Contexts:120  - Guid:            1000121    TotalRootEntryCount: 24122    Counters:        [ 10, 2, 8, 100 ]123    Callsites:124      - [  ]125      - - Guid:            1001126          Counters:        [ 8, 500 ]127          Callsites:128            - - Guid:            1002129                Counters:        [ 500 ]130      - - Guid:            1002131          Counters:        [ 100 ]132