llvm.org GIT mirror llvm / 6aa584f
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265890 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 4 years ago
2 changed file(s) with 43 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
397397 std::lower_bound(ValueMap->begin(), ValueMap->end(), Value,
398398 [](const std::pair &LHS,
399399 uint64_t RHS) { return LHS.first < RHS; });
400 if (Result != ValueMap->end())
400 if (Result != ValueMap->end() && Result->first == Value)
401401 Value = (uint64_t)Result->second;
402 else
403 Value = 0;
402404 break;
403405 }
404406 }
751751 free(VPData);
752752 }
753753
754 static uint16_t NumValueSites2[IPVK_Last + 1] = {1};
755 TEST_P(MaybeSparseInstrProfTest, runtime_value_prof_data_read_write_mapping) {
756 ValueProfRuntimeRecord RTRecord;
757 initializeValueProfRuntimeRecord(&RTRecord, &NumValueSites2[0],
758 &ValueProfNodes[0]);
759
760 ValueProfData *VPData = serializeValueProfDataFromRT(&RTRecord, nullptr);
761
762 InstrProfRecord Record("caller", 0x1234, {1ULL << 31, 2});
763 InstrProfSymtab Symtab;
764 Symtab.mapAddress(uint64_t(callee1), 0x1000ULL);
765 Symtab.mapAddress(uint64_t(callee2), 0x2000ULL);
766 Symtab.mapAddress(uint64_t(callee3), 0x3000ULL);
767 Symtab.mapAddress(uint64_t(callee4), 0x4000ULL);
768 // Missing mapping for callee5
769 Symtab.finalizeSymtab();
770
771 VPData->deserializeTo(Record, &Symtab.getAddrHashMap());
772
773 // Now read data from Record and sanity check the data
774 ASSERT_EQ(1U, Record.getNumValueSites(IPVK_IndirectCallTarget));
775 ASSERT_EQ(5U, Record.getNumValueDataForSite(IPVK_IndirectCallTarget, 0));
776
777 auto Cmp = [](const InstrProfValueData &VD1, const InstrProfValueData &VD2) {
778 return VD1.Count > VD2.Count;
779 };
780 std::unique_ptr VD_0(
781 Record.getValueForSite(IPVK_IndirectCallTarget, 0));
782 std::sort(&VD_0[0], &VD_0[5], Cmp);
783 ASSERT_EQ(VD_0[0].Value, 0x2000ULL);
784 ASSERT_EQ(1000U, VD_0[0].Count);
785 ASSERT_EQ(VD_0[1].Value, 0x3000ULL);
786 ASSERT_EQ(500U, VD_0[1].Count);
787 ASSERT_EQ(VD_0[2].Value, 0x1000ULL);
788 ASSERT_EQ(400U, VD_0[2].Count);
789
790 // callee5 does not have a mapped value -- default to 0.
791 ASSERT_EQ(VD_0[4].Value, 0ULL);
792 }
793
754794 TEST_P(MaybeSparseInstrProfTest, get_max_function_count) {
755795 InstrProfRecord Record1("foo", 0x1234, {1ULL << 31, 2});
756796 InstrProfRecord Record2("bar", 0, {1ULL << 63});