[llvm] r265890 - [PGO] Fix deserialize bug
Adam Nemet via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 11 10:12:51 PDT 2016
> On Apr 9, 2016, at 8:32 PM, Xinliang David Li via llvm-commits <llvm-commits at lists.llvm.org> wrote:
>
> Author: davidxl
> Date: Sat Apr 9 22:32:02 2016
> New Revision: 265890
>
> URL: http://llvm.org/viewvc/llvm-project?rev=265890&view=rev
> Log:
> [PGO] Fix deserialize bug
>
> Raw function pointer collected by value
> profile data may be from external functions
> that are not instrumented. They won't have
> mapping data to be used by the deserializer.
> Force the value to be 0 in this case.
Please also add this comment to the code as well.
Adam
>
> Modified:
> llvm/trunk/lib/ProfileData/InstrProf.cpp
> llvm/trunk/unittests/ProfileData/InstrProfTest.cpp
>
> Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=265890&r1=265889&r2=265890&view=diff
> ==============================================================================
> --- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)
> +++ llvm/trunk/lib/ProfileData/InstrProf.cpp Sat Apr 9 22:32:02 2016
> @@ -398,8 +398,10 @@ uint64_t InstrProfRecord::remapValue(uin
> std::lower_bound(ValueMap->begin(), ValueMap->end(), Value,
> [](const std::pair<uint64_t, uint64_t> &LHS,
> uint64_t RHS) { return LHS.first < RHS; });
> - if (Result != ValueMap->end())
> + if (Result != ValueMap->end() && Result->first == Value)
> Value = (uint64_t)Result->second;
> + else
> + Value = 0;
> break;
> }
> }
>
> Modified: llvm/trunk/unittests/ProfileData/InstrProfTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/InstrProfTest.cpp?rev=265890&r1=265889&r2=265890&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/ProfileData/InstrProfTest.cpp (original)
> +++ llvm/trunk/unittests/ProfileData/InstrProfTest.cpp Sat Apr 9 22:32:02 2016
> @@ -752,6 +752,46 @@ TEST_P(MaybeSparseInstrProfTest, runtime
> free(VPData);
> }
>
> +static uint16_t NumValueSites2[IPVK_Last + 1] = {1};
> +TEST_P(MaybeSparseInstrProfTest, runtime_value_prof_data_read_write_mapping) {
> + ValueProfRuntimeRecord RTRecord;
> + initializeValueProfRuntimeRecord(&RTRecord, &NumValueSites2[0],
> + &ValueProfNodes[0]);
> +
> + ValueProfData *VPData = serializeValueProfDataFromRT(&RTRecord, nullptr);
> +
> + InstrProfRecord Record("caller", 0x1234, {1ULL << 31, 2});
> + InstrProfSymtab Symtab;
> + Symtab.mapAddress(uint64_t(callee1), 0x1000ULL);
> + Symtab.mapAddress(uint64_t(callee2), 0x2000ULL);
> + Symtab.mapAddress(uint64_t(callee3), 0x3000ULL);
> + Symtab.mapAddress(uint64_t(callee4), 0x4000ULL);
> + // Missing mapping for callee5
> + Symtab.finalizeSymtab();
> +
> + VPData->deserializeTo(Record, &Symtab.getAddrHashMap());
> +
> + // Now read data from Record and sanity check the data
> + ASSERT_EQ(1U, Record.getNumValueSites(IPVK_IndirectCallTarget));
> + ASSERT_EQ(5U, Record.getNumValueDataForSite(IPVK_IndirectCallTarget, 0));
> +
> + auto Cmp = [](const InstrProfValueData &VD1, const InstrProfValueData &VD2) {
> + return VD1.Count > VD2.Count;
> + };
> + std::unique_ptr<InstrProfValueData[]> VD_0(
> + Record.getValueForSite(IPVK_IndirectCallTarget, 0));
> + std::sort(&VD_0[0], &VD_0[5], Cmp);
> + ASSERT_EQ(VD_0[0].Value, 0x2000ULL);
> + ASSERT_EQ(1000U, VD_0[0].Count);
> + ASSERT_EQ(VD_0[1].Value, 0x3000ULL);
> + ASSERT_EQ(500U, VD_0[1].Count);
> + ASSERT_EQ(VD_0[2].Value, 0x1000ULL);
> + ASSERT_EQ(400U, VD_0[2].Count);
> +
> + // callee5 does not have a mapped value -- default to 0.
> + ASSERT_EQ(VD_0[4].Value, 0ULL);
> +}
> +
> TEST_P(MaybeSparseInstrProfTest, get_max_function_count) {
> InstrProfRecord Record1("foo", 0x1234, {1ULL << 31, 2});
> InstrProfRecord Record2("bar", 0, {1ULL << 63});
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list