[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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260450 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rong Xu 2016-02-10 22:19:43 +00:00
parent 6bf8999e3a
commit 2465700839
3 changed files with 37 additions and 13 deletions

View File

@ -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.

View File

@ -591,7 +591,8 @@ void ValueProfData::swapBytesFromHost(support::endianness Endianness) {
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, Instruction &Inst,
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)));

View File

@ -229,8 +229,9 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write) {
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, annotate_vp_data) {
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) {