[llvm] r260450 - [PGO] Make the number of records for each value site metada adjustable
Rong Xu via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 10 14:19:44 PST 2016
Author: xur
Date: Wed Feb 10 16:19:43 2016
New Revision: 260450
URL: http://llvm.org/viewvc/llvm-project?rev=260450&view=rev
Log:
[PGO] Make the number of records for each value site metada adjustable
The patch adds a parameter in annotateValueSite() to control the max number
of records written to the value profile meta data for each value site. The
default is kept as the current value of 3.
Differential Revision: http://reviews.llvm.org/D17084
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=260450&r1=260449&r2=260450&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/InstrProf.h (original)
+++ llvm/trunk/include/llvm/ProfileData/InstrProf.h Wed Feb 10 16:19:43 2016
@@ -214,9 +214,11 @@ struct InstrProfRecord;
/// Get the value profile data for value site \p SiteIdx from \p InstrProfR
/// and annotate the instruction \p Inst with the value profile meta data.
+/// Annotate up to \p MaxMDCount (default 3) number of records per value site.
void annotateValueSite(Module &M, Instruction &Inst,
const InstrProfRecord &InstrProfR,
- InstrProfValueKind ValueKind, uint32_t SiteIndx);
+ InstrProfValueKind ValueKind, uint32_t SiteIndx,
+ uint32_t MaxMDCount = 3);
/// 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=260450&r1=260449&r2=260450&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProf.cpp Wed Feb 10 16:19:43 2016
@@ -591,7 +591,8 @@ void ValueProfData::swapBytesFromHost(su
void annotateValueSite(Module &M, Instruction &Inst,
const InstrProfRecord &InstrProfR,
- InstrProfValueKind ValueKind, uint32_t SiteIdx) {
+ InstrProfValueKind ValueKind, uint32_t SiteIdx,
+ uint32_t MaxMDCount) {
uint32_t NV = InstrProfR.getNumValueDataForSite(ValueKind, SiteIdx);
uint64_t Sum = 0;
@@ -611,7 +612,7 @@ void annotateValueSite(Module &M, Instru
MDHelper.createConstant(ConstantInt::get(Type::getInt64Ty(Ctx), Sum)));
// Value Profile Data
- uint32_t MDCount = 3;
+ uint32_t MDCount = MaxMDCount;
for (uint32_t I = 0; I < NV; ++I) {
Vals.push_back(MDHelper.createConstant(
ConstantInt::get(Type::getInt64Ty(Ctx), VD[I].Value)));
Modified: llvm/trunk/unittests/ProfileData/InstrProfTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/InstrProfTest.cpp?rev=260450&r1=260449&r2=260450&view=diff
==============================================================================
--- llvm/trunk/unittests/ProfileData/InstrProfTest.cpp (original)
+++ llvm/trunk/unittests/ProfileData/InstrProfTest.cpp Wed Feb 10 16:19:43 2016
@@ -229,8 +229,9 @@ TEST_P(MaybeSparseInstrProfTest, get_ica
TEST_P(MaybeSparseInstrProfTest, annotate_vp_data) {
InstrProfRecord Record("caller", 0x1234, {1, 2});
Record.reserveSites(IPVK_IndirectCallTarget, 1);
- InstrProfValueData VD0[] = {{1000, 1}, {2000, 2}, {3000, 3}};
- Record.addValueData(IPVK_IndirectCallTarget, 0, VD0, 3, nullptr);
+ InstrProfValueData VD0[] = {{1000, 1}, {2000, 2}, {3000, 3}, {5000, 5},
+ {4000, 4}, {6000, 6}};
+ Record.addValueData(IPVK_IndirectCallTarget, 0, VD0, 6, nullptr);
Writer.addRecord(std::move(Record));
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
@@ -261,23 +262,43 @@ TEST_P(MaybeSparseInstrProfTest, annotat
ValueData, N, T);
ASSERT_TRUE(Res);
ASSERT_EQ(3U, N);
- ASSERT_EQ(6U, T);
+ ASSERT_EQ(21U, T);
// The result should be sorted already:
- ASSERT_EQ(3000U, ValueData[0].Value);
- ASSERT_EQ(3U, ValueData[0].Count);
- ASSERT_EQ(2000U, ValueData[1].Value);
- ASSERT_EQ(2U, ValueData[1].Count);
- ASSERT_EQ(1000U, ValueData[2].Value);
- ASSERT_EQ(1U, ValueData[2].Count);
+ ASSERT_EQ(6000U, ValueData[0].Value);
+ ASSERT_EQ(6U, ValueData[0].Count);
+ ASSERT_EQ(5000U, ValueData[1].Value);
+ ASSERT_EQ(5U, ValueData[1].Count);
+ ASSERT_EQ(4000U, ValueData[2].Value);
+ ASSERT_EQ(4U, ValueData[2].Count);
Res = getValueProfDataFromInst(*Inst, IPVK_IndirectCallTarget, 1, ValueData,
N, T);
ASSERT_TRUE(Res);
ASSERT_EQ(1U, N);
- ASSERT_EQ(6U, T);
+ ASSERT_EQ(21U, T);
Res = getValueProfDataFromInst(*Inst2, IPVK_IndirectCallTarget, 5, ValueData,
N, T);
ASSERT_FALSE(Res);
+
+ // Remove the MD_prof metadata
+ Inst->setMetadata(LLVMContext::MD_prof, 0);
+ // Annotate 5 records this time.
+ annotateValueSite(*M, *Inst, R.get(), IPVK_IndirectCallTarget, 0, 5);
+ Res = getValueProfDataFromInst(*Inst, IPVK_IndirectCallTarget, 5,
+ ValueData, N, T);
+ ASSERT_TRUE(Res);
+ ASSERT_EQ(5U, N);
+ ASSERT_EQ(21U, T);
+ ASSERT_EQ(6000U, ValueData[0].Value);
+ ASSERT_EQ(6U, ValueData[0].Count);
+ ASSERT_EQ(5000U, ValueData[1].Value);
+ ASSERT_EQ(5U, ValueData[1].Count);
+ ASSERT_EQ(4000U, ValueData[2].Value);
+ ASSERT_EQ(4U, ValueData[2].Count);
+ ASSERT_EQ(3000U, ValueData[3].Value);
+ ASSERT_EQ(3U, ValueData[3].Count);
+ ASSERT_EQ(2000U, ValueData[4].Value);
+ ASSERT_EQ(2U, ValueData[4].Count);
}
TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_with_weight) {
More information about the llvm-commits
mailing list