Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 34be7e6

Browse files
committed
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264879 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7725fd8 commit 34be7e6

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

include/llvm/ProfileData/InstrProf.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,9 @@ void annotateValueSite(Module &M, Instruction &Inst,
229229
const InstrProfRecord &InstrProfR,
230230
InstrProfValueKind ValueKind, uint32_t SiteIndx,
231231
uint32_t MaxMDCount = 3);
232-
/// Same as the above interface but using the ValueData array directly, as
233-
/// well as \p Sum.
232+
/// Same as the above interface but using an ArrayRef, as well as \p Sum.
234233
void annotateValueSite(Module &M, Instruction &Inst,
235-
const InstrProfValueData VD[], uint32_t NV,
234+
ArrayRef<InstrProfValueData> VDs,
236235
uint64_t Sum, InstrProfValueKind ValueKind,
237236
uint32_t MaxMDCount);
238237

lib/ProfileData/InstrProf.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,12 @@ void annotateValueSite(Module &M, Instruction &Inst,
606606
std::unique_ptr<InstrProfValueData[]> VD =
607607
InstrProfR.getValueForSite(ValueKind, SiteIdx, &Sum);
608608

609-
annotateValueSite(M, Inst, VD.get(), NV, Sum, ValueKind, MaxMDCount);
609+
ArrayRef<InstrProfValueData> VDs(VD.get(), NV);
610+
annotateValueSite(M, Inst, VDs, Sum, ValueKind, MaxMDCount);
610611
}
611612

612613
void annotateValueSite(Module &M, Instruction &Inst,
613-
const InstrProfValueData VD[], uint32_t NV,
614+
ArrayRef<InstrProfValueData> VDs,
614615
uint64_t Sum, InstrProfValueKind ValueKind,
615616
uint32_t MaxMDCount) {
616617
LLVMContext &Ctx = M.getContext();
@@ -627,11 +628,11 @@ void annotateValueSite(Module &M, Instruction &Inst,
627628

628629
// Value Profile Data
629630
uint32_t MDCount = MaxMDCount;
630-
for (uint32_t I = 0; I < NV; ++I) {
631+
for (auto &VD : VDs) {
631632
Vals.push_back(MDHelper.createConstant(
632-
ConstantInt::get(Type::getInt64Ty(Ctx), VD[I].Value)));
633+
ConstantInt::get(Type::getInt64Ty(Ctx), VD.Value)));
633634
Vals.push_back(MDHelper.createConstant(
634-
ConstantInt::get(Type::getInt64Ty(Ctx), VD[I].Count)));
635+
ConstantInt::get(Type::getInt64Ty(Ctx), VD.Count)));
635636
if (--MDCount == 0)
636637
break;
637638
}

unittests/ProfileData/InstrProfTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ TEST_P(MaybeSparseInstrProfTest, annotate_vp_data) {
330330
// Annotate with 4 records.
331331
InstrProfValueData VD0Sorted[] = {{1000, 6}, {2000, 5}, {3000, 4}, {4000, 3},
332332
{5000, 2}, {6000, 1}};
333-
annotateValueSite(*M, *Inst, &VD0Sorted[2], 4, 10, IPVK_IndirectCallTarget, 5);
333+
annotateValueSite(*M, *Inst, makeArrayRef(VD0Sorted).slice(2), 10,
334+
IPVK_IndirectCallTarget, 5);
334335
Res = getValueProfDataFromInst(*Inst, IPVK_IndirectCallTarget, 5,
335336
ValueData, N, T);
336337
ASSERT_TRUE(Res);

0 commit comments

Comments
 (0)