120 lines · plain
1; REQUIRES: x86_64-linux2;3; RUN: rm -rf %t4; RUN: split-file %s %t5; RUN: llvm-ctxprof-util fromYAML --input=%t/profile.yaml --output=%t/profile.ctxprofdata6; RUN: opt -module-summary -passes='thinlto-pre-link<O2>' -use-ctx-profile=%t/profile.ctxprofdata \7; RUN: %t/example.ll -S -o %t/4909520559318251808.ll8; RUN: FileCheck --input-file %t/4909520559318251808.ll %s --check-prefix=PRELINK9 10; RUN: opt -passes='ctx-prof-flatten' -use-ctx-profile=%t/profile.ctxprofdata %t/4909520559318251808.ll -S | FileCheck %s --check-prefix=POSTLINK11;12;13; Check that instrumentation occurs where expected: the "no" block for both foo and14; @an_entrypoint - which explains the subsequent branch weights15;16; PRELINK-LABEL: @foo17; PRELINK-LABEL: yes:18; PRELINK-LABEL: no:19; PRELINK-NEXT: call void @llvm.instrprof.increment(ptr @foo, i64 [[#]], i32 2, i32 1)20 21; PRELINK-LABEL: @an_entrypoint22; PRELINK: br i1 %t, label %yes, label %common.ret, !prof ![[PREPROF:[0-9]+]]23; PRELINK-LABEL: yes:24; PRELINK-NEXT: call void @llvm.instrprof.increment(ptr @an_entrypoint, i64 [[#]], i32 2, i32 1)25; PRELINK: ![[#]] = !{i32 1, !"ProfileSummary", !1}26; PRELINK: ![[#]] = !{!"TotalCount", i64 151600}27; PRELINK: ![[#]] = !{!"MaxCount", i64 102000}28; PRELINK: ![[#]] = !{!"MaxInternalCount", i64 102000}29; PRELINK: ![[#]] = !{!"MaxFunctionCount", i64 20100}30; PRELINK: ![[#]] = !{!"NumCounts", i64 6}31; PRELINK: ![[#]] = !{!"NumFunctions", i64 3}32; PRELINK: ![[PREPROF]] = !{!"branch_weights", i32 4000, i32 6000}33 34; Check that the output has:35; - no instrumentation36; - the 2 functions have an entry count37; - each conditional branch has profile annotation38;39; POSTLINK-NOT: call void @llvm.instrprof40;41; make sure we have function entry counts, branch weights, and a profile summary.42; POSTLINK-LABEL: @foo43; POSTLINK-SAME: !prof ![[FOO_EP:[0-9]+]]44; POSTLINK: br i1 %t, label %yes, label %no, !prof ![[FOO_BW:[0-9]+]]45; POSTLINK-LABEL: @an_entrypoint46; POSTLINK-SAME: !prof ![[AN_ENTRYPOINT_EP:[0-9]+]]47; POSTLINK: br i1 %t, label %yes, label %common.ret, !prof ![[AN_ENTRYPOINT_BW:[0-9]+]]48 49; The postlink summary is restricted to the stuff under the root - including the50; "unhandled" data.51; POSTLINK: ![[#]] = !{i32 1, !"ProfileSummary", !1}52; POSTLINK: ![[#]] = !{!"TotalCount", i64 149500}53; POSTLINK: ![[#]] = !{!"MaxCount", i64 100000}54; POSTLINK: ![[#]] = !{!"MaxInternalCount", i64 100000}55; POSTLINK: ![[#]] = !{!"MaxFunctionCount", i64 20000}56; POSTLINK: ![[#]] = !{!"NumCounts", i64 6}57; POSTLINK: ![[#]] = !{!"NumFunctions", i64 3}58 59;60; @foo will be called both unconditionally and conditionally, on the "yes" branch61; which has a count of 40. So 140 times.62 63; POSTLINK: ![[FOO_EP]] = !{!"function_entry_count", i64 14000} 64 65; foo's "no" branch is taken 10+5 times (from the 2 contexts belonging to foo).66; Which means its "yes" branch is taken 140 - 15 times.67 68; POSTLINK: ![[FOO_BW]] = !{!"branch_weights", i32 12500, i32 1500} 69; POSTLINK: ![[AN_ENTRYPOINT_EP]] = !{!"function_entry_count", i64 10000}70; POSTLINK: ![[AN_ENTRYPOINT_BW]] = !{!"branch_weights", i32 4000, i32 6000} 71 72;--- profile.yaml73Contexts:74 - Guid: 490952055931825180875 TotalRootEntryCount: 10076 Unhandled:77 - Guid: 123478 Counters: [200, 1000]79 Counters: [100, 40]80 Callsites: -81 - Guid: 1187229159338683369682 Counters: [ 100, 5 ]83 -84 - Guid: 1187229159338683369685 Counters: [ 40, 10 ]86FlatProfiles:87 - Guid: 123488 Counters: [ 100, 2000 ]89;--- example.ll90declare void @bar()91 92define void @foo(i32 %a, ptr %fct) #0 !guid !0 {93 %t = icmp sgt i32 %a, 794 br i1 %t, label %yes, label %no95yes:96 call void %fct(i32 %a)97 br label %exit98no:99 call void @bar()100 br label %exit101exit:102 ret void103}104 105define void @an_entrypoint(i32 %a) !guid !1 {106 %t = icmp sgt i32 %a, 0107 call void @foo(i32 10, ptr null)108 br i1 %t, label %yes, label %no109 110yes:111 call void @foo(i32 1, ptr null)112 ret void113no:114 ret void115}116 117attributes #0 = { noinline }118!0 = !{ i64 11872291593386833696 }119!1 = !{i64 4909520559318251808}120