[llvm] r257145 - [PGO] Ensure vp data in indexed profile always sorted

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 7 21:45:22 PST 2016


Author: davidxl
Date: Thu Jan  7 23:45:21 2016
New Revision: 257145

URL: http://llvm.org/viewvc/llvm-project?rev=257145&view=rev
Log:
[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.

Modified:
    llvm/trunk/lib/ProfileData/InstrProfWriter.cpp
    llvm/trunk/test/tools/llvm-profdata/value-prof.proftext
    llvm/trunk/unittests/ProfileData/InstrProfTest.cpp

Modified: llvm/trunk/lib/ProfileData/InstrProfWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfWriter.cpp?rev=257145&r1=257144&r2=257145&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProfWriter.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProfWriter.cpp Thu Jan  7 23:45:21 2016
@@ -117,6 +117,8 @@ std::error_code InstrProfWriter::addReco
     Result = Dest.merge(I, Weight);
   }
 
+  Dest.sortValueData();
+
   // We keep track of the max function count as we go for simplicity.
   // Update this statistic no matter the result of the merge.
   if (Dest.Counts[0] > MaxFunctionCount)

Modified: llvm/trunk/test/tools/llvm-profdata/value-prof.proftext
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/value-prof.proftext?rev=257145&r1=257144&r2=257145&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/value-prof.proftext (original)
+++ llvm/trunk/test/tools/llvm-profdata/value-prof.proftext Thu Jan  7 23:45:21 2016
@@ -1,4 +1,4 @@
-# RUN: llvm-profdata show -ic-targets  -all-functions %s | FileCheck %s --check-prefix=IC
+# RUN: llvm-profdata show -ic-targets  -all-functions %s | FileCheck %s --check-prefix=ICTXT
 # RUN: llvm-profdata show -ic-targets -counts -text -all-functions %s | FileCheck %s --check-prefix=ICTEXT
 # RUN: llvm-profdata merge -o %t.profdata  %s
 # RUN: llvm-profdata show -ic-targets  -all-functions %t.profdata | FileCheck %s --check-prefix=IC
@@ -45,10 +45,16 @@ foo2:1000
 1
 foo2:20000
 
+#ICTXT: Indirect Call Site Count: 3
+#ICTXT-NEXT:    Indirect Target Results: 
+#ICTXT-NEXT:	[ 1, foo, 100 ]
+#ICTXT-NEXT:	[ 1, foo2, 1000 ]
+#ICTXT-NEXT:	[ 2, foo2, 20000 ]
+
 #IC: Indirect Call Site Count: 3
 #IC-NEXT:    Indirect Target Results: 
-#IC-NEXT:	[ 1, foo, 100 ]
 #IC-NEXT:	[ 1, foo2, 1000 ]
+#IC-NEXT:	[ 1, foo, 100 ]
 #IC-NEXT:	[ 2, foo2, 20000 ]
 
 #ICTEXT: foo:100

Modified: llvm/trunk/unittests/ProfileData/InstrProfTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/InstrProfTest.cpp?rev=257145&r1=257144&r2=257145&view=diff
==============================================================================
--- llvm/trunk/unittests/ProfileData/InstrProfTest.cpp (original)
+++ llvm/trunk/unittests/ProfileData/InstrProfTest.cpp Thu Jan  7 23:45:21 2016
@@ -159,11 +159,6 @@ TEST_F(InstrProfTest, get_icall_data_rea
 
   std::unique_ptr<InstrProfValueData[]> VD =
       R.get().getValueForSite(IPVK_IndirectCallTarget, 0);
-  // Now sort the target acording to frequency.
-  std::sort(&VD[0], &VD[3],
-            [](const InstrProfValueData &VD1, const InstrProfValueData &VD2) {
-              return VD1.Count > VD2.Count;
-            });
 
   ASSERT_EQ(3U, VD[0].Count);
   ASSERT_EQ(2U, VD[1].Count);
@@ -211,11 +206,6 @@ TEST_F(InstrProfTest, get_icall_data_rea
 
   std::unique_ptr<InstrProfValueData[]> VD =
       R.get().getValueForSite(IPVK_IndirectCallTarget, 0);
-  // Now sort the target acording to frequency.
-  std::sort(&VD[0], &VD[3],
-            [](const InstrProfValueData &VD1, const InstrProfValueData &VD2) {
-              return VD1.Count > VD2.Count;
-            });
   ASSERT_EQ(30U, VD[0].Count);
   ASSERT_EQ(20U, VD[1].Count);
   ASSERT_EQ(10U, VD[2].Count);
@@ -269,11 +259,6 @@ TEST_F(InstrProfTest, get_icall_data_rea
 
   std::unique_ptr<InstrProfValueData[]> VD =
       R.get().getValueForSite(IPVK_IndirectCallTarget, 0);
-  // Now sort the target acording to frequency.
-  std::sort(&VD[0], &VD[3],
-            [](const InstrProfValueData &VD1, const InstrProfValueData &VD2) {
-              return VD1.Count > VD2.Count;
-            });
   ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), StringRef("callee3"));
   ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), StringRef("callee2"));
   ASSERT_EQ(StringRef((const char *)VD[2].Value, 7), StringRef("callee1"));
@@ -365,11 +350,6 @@ TEST_F(InstrProfTest, get_icall_data_mer
 
   std::unique_ptr<InstrProfValueData[]> VD =
       R.get().getValueForSite(IPVK_IndirectCallTarget, 0);
-  // Now sort the target acording to frequency.
-  std::sort(&VD[0], &VD[4],
-            [](const InstrProfValueData &VD1, const InstrProfValueData &VD2) {
-              return VD1.Count > VD2.Count;
-            });
   ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), StringRef("callee2"));
   ASSERT_EQ(7U, VD[0].Count);
   ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), StringRef("callee3"));
@@ -381,10 +361,6 @@ TEST_F(InstrProfTest, get_icall_data_mer
 
   std::unique_ptr<InstrProfValueData[]> VD_2(
       R.get().getValueForSite(IPVK_IndirectCallTarget, 2));
-  std::sort(&VD_2[0], &VD_2[4],
-            [](const InstrProfValueData &VD1, const InstrProfValueData &VD2) {
-              return VD1.Count > VD2.Count;
-            });
   ASSERT_EQ(StringRef((const char *)VD_2[0].Value, 7), StringRef("callee3"));
   ASSERT_EQ(6U, VD_2[0].Count);
   ASSERT_EQ(StringRef((const char *)VD_2[1].Value, 7), StringRef("callee4"));
@@ -401,10 +377,6 @@ TEST_F(InstrProfTest, get_icall_data_mer
 
   std::unique_ptr<InstrProfValueData[]> VD_4(
       R.get().getValueForSite(IPVK_IndirectCallTarget, 4));
-  std::sort(&VD_4[0], &VD_4[3],
-            [](const InstrProfValueData &VD1, const InstrProfValueData &VD2) {
-              return VD1.Count > VD2.Count;
-            });
   ASSERT_EQ(StringRef((const char *)VD_4[0].Value, 7), StringRef("callee3"));
   ASSERT_EQ(6U, VD_4[0].Count);
   ASSERT_EQ(StringRef((const char *)VD_4[1].Value, 7), StringRef("callee2"));




More information about the llvm-commits mailing list