[llvm] r260741 - [PGO] Add another interface for annotateValueSite

Rong Xu via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 12 13:36:18 PST 2016


Author: xur
Date: Fri Feb 12 15:36:17 2016
New Revision: 260741

URL: http://llvm.org/viewvc/llvm-project?rev=260741&view=rev
Log:
[PGO] Add another interface for annotateValueSite

Add another interface to function annotateValueSite() which directly uses the
VauleData array.

Differential Revision: http://reviews.llvm.org/D17108

Modified:
    llvm/trunk/include/llvm/ProfileData/InstrProf.h
    llvm/trunk/lib/ProfileData/InstrProf.cpp
    llvm/trunk/unittests/ProfileData/InstrProfTest.cpp

Modified: llvm/trunk/include/llvm/ProfileData/InstrProf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProf.h?rev=260741&r1=260740&r2=260741&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/InstrProf.h (original)
+++ llvm/trunk/include/llvm/ProfileData/InstrProf.h Fri Feb 12 15:36:17 2016
@@ -219,6 +219,13 @@ void annotateValueSite(Module &M, Instru
                        const InstrProfRecord &InstrProfR,
                        InstrProfValueKind ValueKind, uint32_t SiteIndx,
                        uint32_t MaxMDCount = 3);
+/// Same as the above interface but using the ValueData array directly, as
+/// well as \p Sum.
+void annotateValueSite(Module &M, Instruction &Inst,
+                       const InstrProfValueData VD[], uint32_t NV,
+                       uint64_t Sum, InstrProfValueKind ValueKind,
+                       uint32_t MaxMDCount);
+
 /// Extract the value profile data from \p Inst which is annotated with
 /// value profile meta data. Return false if there is no value data annotated,
 /// otherwise  return true.

Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=260741&r1=260740&r2=260741&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProf.cpp Fri Feb 12 15:36:17 2016
@@ -599,6 +599,13 @@ void annotateValueSite(Module &M, Instru
   std::unique_ptr<InstrProfValueData[]> VD =
       InstrProfR.getValueForSite(ValueKind, SiteIdx, &Sum);
 
+  annotateValueSite(M, Inst, VD.get(), NV, Sum, ValueKind, MaxMDCount);
+}
+
+void annotateValueSite(Module &M, Instruction &Inst,
+                       const InstrProfValueData VD[], uint32_t NV,
+                       uint64_t Sum, InstrProfValueKind ValueKind,
+                       uint32_t MaxMDCount) {
   LLVMContext &Ctx = M.getContext();
   MDBuilder MDHelper(Ctx);
   SmallVector<Metadata *, 3> Vals;

Modified: llvm/trunk/unittests/ProfileData/InstrProfTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/InstrProfTest.cpp?rev=260741&r1=260740&r2=260741&view=diff
==============================================================================
--- llvm/trunk/unittests/ProfileData/InstrProfTest.cpp (original)
+++ llvm/trunk/unittests/ProfileData/InstrProfTest.cpp Fri Feb 12 15:36:17 2016
@@ -299,6 +299,26 @@ TEST_P(MaybeSparseInstrProfTest, annotat
   ASSERT_EQ(3U, ValueData[3].Count);
   ASSERT_EQ(2000U, ValueData[4].Value);
   ASSERT_EQ(2U, ValueData[4].Count);
+
+  // Remove the MD_prof metadata 
+  Inst->setMetadata(LLVMContext::MD_prof, 0);
+  // Annotate with 4 records.
+  InstrProfValueData VD0Sorted[] = {{1000, 6}, {2000, 5}, {3000, 4}, {4000, 3},
+                              {5000, 2}, {6000, 1}};
+  annotateValueSite(*M, *Inst, &VD0Sorted[2], 4, 10, IPVK_IndirectCallTarget, 5);
+  Res = getValueProfDataFromInst(*Inst, IPVK_IndirectCallTarget, 5,
+                                      ValueData, N, T);
+  ASSERT_TRUE(Res);
+  ASSERT_EQ(4U, N);
+  ASSERT_EQ(10U, T);
+  ASSERT_EQ(3000U, ValueData[0].Value);
+  ASSERT_EQ(4U, ValueData[0].Count);
+  ASSERT_EQ(4000U, ValueData[1].Value);
+  ASSERT_EQ(3U, ValueData[1].Count);
+  ASSERT_EQ(5000U, ValueData[2].Value);
+  ASSERT_EQ(2U, ValueData[2].Count);
+  ASSERT_EQ(6000U, ValueData[3].Value);
+  ASSERT_EQ(1U, ValueData[3].Count);
 }
 
 TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_with_weight) {




More information about the llvm-commits mailing list