llvm.org GIT mirror llvm / 36838fe
[PGO] Ensure vp data in indexed profile always sorted Done in InstrProfWriter to eliminate the need for client code to do the sorting. The operation is done once and reused many times so it is more efficient. Update unit test to remove sorting. Also update expected output of affected tests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257145 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 3 years ago
3 changed file(s) with 10 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
115115 // We're updating a function we've seen before.
116116 Result = Dest.merge(I, Weight);
117117 }
118
119 Dest.sortValueData();
118120
119121 // We keep track of the max function count as we go for simplicity.
120122 // Update this statistic no matter the result of the merge.
None # RUN: llvm-profdata show -ic-targets -all-functions %s | FileCheck %s --check-prefix=IC
0 # RUN: llvm-profdata show -ic-targets -all-functions %s | FileCheck %s --check-prefix=ICTXT
11 # RUN: llvm-profdata show -ic-targets -counts -text -all-functions %s | FileCheck %s --check-prefix=ICTEXT
22 # RUN: llvm-profdata merge -o %t.profdata %s
33 # RUN: llvm-profdata show -ic-targets -all-functions %t.profdata | FileCheck %s --check-prefix=IC
4444 1
4545 foo2:20000
4646
47 #ICTXT: Indirect Call Site Count: 3
48 #ICTXT-NEXT: Indirect Target Results:
49 #ICTXT-NEXT: [ 1, foo, 100 ]
50 #ICTXT-NEXT: [ 1, foo2, 1000 ]
51 #ICTXT-NEXT: [ 2, foo2, 20000 ]
52
4753 #IC: Indirect Call Site Count: 3
4854 #IC-NEXT: Indirect Target Results:
55 #IC-NEXT: [ 1, foo2, 1000 ]
4956 #IC-NEXT: [ 1, foo, 100 ]
50 #IC-NEXT: [ 1, foo2, 1000 ]
5157 #IC-NEXT: [ 2, foo2, 20000 ]
5258
5359 #ICTEXT: foo:100
158158
159159 std::unique_ptr VD =
160160 R.get().getValueForSite(IPVK_IndirectCallTarget, 0);
161 // Now sort the target acording to frequency.
162 std::sort(&VD[0], &VD[3],
163 [](const InstrProfValueData &VD1, const InstrProfValueData &VD2) {
164 return VD1.Count > VD2.Count;
165 });
166161
167162 ASSERT_EQ(3U, VD[0].Count);
168163 ASSERT_EQ(2U, VD[1].Count);
210205
211206 std::unique_ptr VD =
212207 R.get().getValueForSite(IPVK_IndirectCallTarget, 0);
213 // Now sort the target acording to frequency.
214 std::sort(&VD[0], &VD[3],
215 [](const InstrProfValueData &VD1, const InstrProfValueData &VD2) {
216 return VD1.Count > VD2.Count;
217 });
218208 ASSERT_EQ(30U, VD[0].Count);
219209 ASSERT_EQ(20U, VD[1].Count);
220210 ASSERT_EQ(10U, VD[2].Count);
268258
269259 std::unique_ptr VD =
270260 R.get().getValueForSite(IPVK_IndirectCallTarget, 0);
271 // Now sort the target acording to frequency.
272 std::sort(&VD[0], &VD[3],
273 [](const InstrProfValueData &VD1, const InstrProfValueData &VD2) {
274 return VD1.Count > VD2.Count;
275 });
276261 ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), StringRef("callee3"));
277262 ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), StringRef("callee2"));
278263 ASSERT_EQ(StringRef((const char *)VD[2].Value, 7), StringRef("callee1"));
364349
365350 std::unique_ptr VD =
366351 R.get().getValueForSite(IPVK_IndirectCallTarget, 0);
367 // Now sort the target acording to frequency.
368 std::sort(&VD[0], &VD[4],
369 [](const InstrProfValueData &VD1, const InstrProfValueData &VD2) {
370 return VD1.Count > VD2.Count;
371 });
372352 ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), StringRef("callee2"));
373353 ASSERT_EQ(7U, VD[0].Count);
374354 ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), StringRef("callee3"));
380360
381361 std::unique_ptr VD_2(
382362 R.get().getValueForSite(IPVK_IndirectCallTarget, 2));
383 std::sort(&VD_2[0], &VD_2[4],
384 [](const InstrProfValueData &VD1, const InstrProfValueData &VD2) {
385 return VD1.Count > VD2.Count;
386 });
387363 ASSERT_EQ(StringRef((const char *)VD_2[0].Value, 7), StringRef("callee3"));
388364 ASSERT_EQ(6U, VD_2[0].Count);
389365 ASSERT_EQ(StringRef((const char *)VD_2[1].Value, 7), StringRef("callee4"));
400376
401377 std::unique_ptr VD_4(
402378 R.get().getValueForSite(IPVK_IndirectCallTarget, 4));
403 std::sort(&VD_4[0], &VD_4[3],
404 [](const InstrProfValueData &VD1, const InstrProfValueData &VD2) {
405 return VD1.Count > VD2.Count;
406 });
407379 ASSERT_EQ(StringRef((const char *)VD_4[0].Value, 7), StringRef("callee3"));
408380 ASSERT_EQ(6U, VD_4[0].Count);
409381 ASSERT_EQ(StringRef((const char *)VD_4[1].Value, 7), StringRef("callee2"));