<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thanks!<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 11, 2016, at 10:18 AM, Xinliang David Li <<a href="mailto:davidxl@google.com" class="">davidxl@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Done.<div class=""><br class=""></div><div class="">David</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Apr 11, 2016 at 10:12 AM, Adam Nemet <span dir="ltr" class=""><<a href="mailto:anemet@apple.com" target="_blank" class="">anemet@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br class="">
> On Apr 9, 2016, at 8:32 PM, Xinliang David Li via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a>> wrote:<br class="">
><br class="">
> Author: davidxl<br class="">
> Date: Sat Apr  9 22:32:02 2016<br class="">
> New Revision: 265890<br class="">
><br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=265890&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=265890&view=rev</a><br class="">
> Log:<br class="">
> [PGO] Fix deserialize bug<br class="">
><br class="">
> Raw function pointer collected by value<br class="">
> profile data may be from external functions<br class="">
> that are not instrumented. They won't have<br class="">
> mapping data to be used by the deserializer.<br class="">
> Force the value to be 0 in this case.<br class="">
<br class="">
Please also add this comment to the code as well.<br class="">
<br class="">
Adam<br class="">
<br class="">
><br class="">
> Modified:<br class="">
>    llvm/trunk/lib/ProfileData/InstrProf.cpp<br class="">
>    llvm/trunk/unittests/ProfileData/InstrProfTest.cpp<br class="">
><br class="">
> Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=265890&r1=265889&r2=265890&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=265890&r1=265889&r2=265890&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)<br class="">
> +++ llvm/trunk/lib/ProfileData/InstrProf.cpp Sat Apr  9 22:32:02 2016<br class="">
> @@ -398,8 +398,10 @@ uint64_t InstrProfRecord::remapValue(uin<br class="">
>         std::lower_bound(ValueMap->begin(), ValueMap->end(), Value,<br class="">
>                          [](const std::pair<uint64_t, uint64_t> &LHS,<br class="">
>                             uint64_t RHS) { return LHS.first < RHS; });<br class="">
> -    if (Result != ValueMap->end())<br class="">
> +    if (Result != ValueMap->end() && Result->first == Value)<br class="">
>       Value = (uint64_t)Result->second;<br class="">
> +    else<br class="">
> +      Value = 0;<br class="">
>     break;<br class="">
>   }<br class="">
>   }<br class="">
><br class="">
> Modified: llvm/trunk/unittests/ProfileData/InstrProfTest.cpp<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/InstrProfTest.cpp?rev=265890&r1=265889&r2=265890&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/InstrProfTest.cpp?rev=265890&r1=265889&r2=265890&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- llvm/trunk/unittests/ProfileData/InstrProfTest.cpp (original)<br class="">
> +++ llvm/trunk/unittests/ProfileData/InstrProfTest.cpp Sat Apr  9 22:32:02 2016<br class="">
> @@ -752,6 +752,46 @@ TEST_P(MaybeSparseInstrProfTest, runtime<br class="">
>   free(VPData);<br class="">
> }<br class="">
><br class="">
> +static uint16_t NumValueSites2[IPVK_Last + 1] = {1};<br class="">
> +TEST_P(MaybeSparseInstrProfTest, runtime_value_prof_data_read_write_mapping) {<br class="">
> +  ValueProfRuntimeRecord RTRecord;<br class="">
> +  initializeValueProfRuntimeRecord(&RTRecord, &NumValueSites2[0],<br class="">
> +                                   &ValueProfNodes[0]);<br class="">
> +<br class="">
> +  ValueProfData *VPData = serializeValueProfDataFromRT(&RTRecord, nullptr);<br class="">
> +<br class="">
> +  InstrProfRecord Record("caller", 0x1234, {1ULL << 31, 2});<br class="">
> +  InstrProfSymtab Symtab;<br class="">
> +  Symtab.mapAddress(uint64_t(callee1), 0x1000ULL);<br class="">
> +  Symtab.mapAddress(uint64_t(callee2), 0x2000ULL);<br class="">
> +  Symtab.mapAddress(uint64_t(callee3), 0x3000ULL);<br class="">
> +  Symtab.mapAddress(uint64_t(callee4), 0x4000ULL);<br class="">
> +  // Missing mapping for callee5<br class="">
> +  Symtab.finalizeSymtab();<br class="">
> +<br class="">
> +  VPData->deserializeTo(Record, &Symtab.getAddrHashMap());<br class="">
> +<br class="">
> +  // Now read data from Record and sanity check the data<br class="">
> +  ASSERT_EQ(1U, Record.getNumValueSites(IPVK_IndirectCallTarget));<br class="">
> +  ASSERT_EQ(5U, Record.getNumValueDataForSite(IPVK_IndirectCallTarget, 0));<br class="">
> +<br class="">
> +  auto Cmp = [](const InstrProfValueData &VD1, const InstrProfValueData &VD2) {<br class="">
> +    return VD1.Count > VD2.Count;<br class="">
> +  };<br class="">
> +  std::unique_ptr<InstrProfValueData[]> VD_0(<br class="">
> +      Record.getValueForSite(IPVK_IndirectCallTarget, 0));<br class="">
> +  std::sort(&VD_0[0], &VD_0[5], Cmp);<br class="">
> +  ASSERT_EQ(VD_0[0].Value, 0x2000ULL);<br class="">
> +  ASSERT_EQ(1000U, VD_0[0].Count);<br class="">
> +  ASSERT_EQ(VD_0[1].Value, 0x3000ULL);<br class="">
> +  ASSERT_EQ(500U, VD_0[1].Count);<br class="">
> +  ASSERT_EQ(VD_0[2].Value, 0x1000ULL);<br class="">
> +  ASSERT_EQ(400U, VD_0[2].Count);<br class="">
> +<br class="">
> +  // callee5 does not have a mapped value -- default to 0.<br class="">
> +  ASSERT_EQ(VD_0[4].Value, 0ULL);<br class="">
> +}<br class="">
> +<br class="">
> TEST_P(MaybeSparseInstrProfTest, get_max_function_count) {<br class="">
>   InstrProfRecord Record1("foo", 0x1234, {1ULL << 31, 2});<br class="">
>   InstrProfRecord Record2("bar", 0, {1ULL << 63});<br class="">
><br class="">
><br class="">
> _______________________________________________<br class="">
> llvm-commits mailing list<br class="">
> <a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="">
<br class="">
</blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></body></html>