[llvm] r264879 - [PGO] Use ArrayRef in annotateValueSite()

Rong Xu via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 30 09:56:32 PDT 2016


Author: xur
Date: Wed Mar 30 11:56:31 2016
New Revision: 264879

URL: http://llvm.org/viewvc/llvm-project?rev=264879&view=rev
Log:
[PGO] Use ArrayRef in annotateValueSite()

Using ArrayRef in annotateValueSite's parameter instead of using an array
and it's size.

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

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=264879&r1=264878&r2=264879&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/InstrProf.h (original)
+++ llvm/trunk/include/llvm/ProfileData/InstrProf.h Wed Mar 30 11:56:31 2016
@@ -229,10 +229,9 @@ 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.
+/// Same as the above interface but using an ArrayRef, as well as \p Sum.
 void annotateValueSite(Module &M, Instruction &Inst,
-                       const InstrProfValueData VD[], uint32_t NV,
+                       ArrayRef<InstrProfValueData> VDs,
                        uint64_t Sum, InstrProfValueKind ValueKind,
                        uint32_t MaxMDCount);
 

Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=264879&r1=264878&r2=264879&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProf.cpp Wed Mar 30 11:56:31 2016
@@ -606,11 +606,12 @@ void annotateValueSite(Module &M, Instru
   std::unique_ptr<InstrProfValueData[]> VD =
       InstrProfR.getValueForSite(ValueKind, SiteIdx, &Sum);
 
-  annotateValueSite(M, Inst, VD.get(), NV, Sum, ValueKind, MaxMDCount);
+  ArrayRef<InstrProfValueData> VDs(VD.get(), NV);
+  annotateValueSite(M, Inst, VDs, Sum, ValueKind, MaxMDCount);
 }
 
 void annotateValueSite(Module &M, Instruction &Inst,
-                       const InstrProfValueData VD[], uint32_t NV,
+                       ArrayRef<InstrProfValueData> VDs,
                        uint64_t Sum, InstrProfValueKind ValueKind,
                        uint32_t MaxMDCount) {
   LLVMContext &Ctx = M.getContext();
@@ -627,11 +628,11 @@ void annotateValueSite(Module &M, Instru
 
   // Value Profile Data
   uint32_t MDCount = MaxMDCount;
-  for (uint32_t I = 0; I < NV; ++I) {
+  for (auto &VD : VDs) {
     Vals.push_back(MDHelper.createConstant(
-        ConstantInt::get(Type::getInt64Ty(Ctx), VD[I].Value)));
+        ConstantInt::get(Type::getInt64Ty(Ctx), VD.Value)));
     Vals.push_back(MDHelper.createConstant(
-        ConstantInt::get(Type::getInt64Ty(Ctx), VD[I].Count)));
+        ConstantInt::get(Type::getInt64Ty(Ctx), VD.Count)));
     if (--MDCount == 0)
       break;
   }

Modified: llvm/trunk/unittests/ProfileData/InstrProfTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/InstrProfTest.cpp?rev=264879&r1=264878&r2=264879&view=diff
==============================================================================
--- llvm/trunk/unittests/ProfileData/InstrProfTest.cpp (original)
+++ llvm/trunk/unittests/ProfileData/InstrProfTest.cpp Wed Mar 30 11:56:31 2016
@@ -330,7 +330,8 @@ TEST_P(MaybeSparseInstrProfTest, annotat
   // 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);
+  annotateValueSite(*M, *Inst, makeArrayRef(VD0Sorted).slice(2), 10,
+                    IPVK_IndirectCallTarget, 5);
   Res = getValueProfDataFromInst(*Inst, IPVK_IndirectCallTarget, 5,
                                       ValueData, N, T);
   ASSERT_TRUE(Res);




More information about the llvm-commits mailing list