Skip to content

Commit 93fd3eb

Browse files
resolve comments
1 parent bfc2b57 commit 93fd3eb

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

llvm/include/llvm/ProfileData/SampleProf.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ enum class sampleprof_error {
6363
zlib_unavailable,
6464
hash_mismatch,
6565
illegal_line_offset,
66-
duplicate_vtable_type
6766
};
6867

6968
inline std::error_code make_error_code(sampleprof_error E) {
@@ -1023,14 +1022,17 @@ class FunctionSamples {
10231022
return VirtualCallsiteTypeCounts;
10241023
}
10251024

1026-
/// Returns the vtable access samples for the C++ types at the un-drifted
1027-
/// location of \p Loc.
1025+
/// Returns the vtable access samples for the C++ types for \p Loc.
1026+
/// Under the hood, the caller-specified \p Loc will be un-drifted before the
1027+
/// type sample lookup if possible.
10281028
TypeCountMap &getTypeSamplesAt(const LineLocation &Loc) {
10291029
return VirtualCallsiteTypeCounts[mapIRLocToProfileLoc(Loc)];
10301030
}
10311031

10321032
/// Scale \p Other sample counts by \p Weight and add the scaled result to the
1033-
/// type samples for the undrifted location of \p Loc.
1033+
/// type samples for \p Loc. Under the hoold, the caller-provided \p Loc will
1034+
/// be un-drifted before the type sample lookup if possible.
1035+
/// typename T is either a std::map or a DenseMap.
10341036
template <typename T>
10351037
sampleprof_error addCallsiteVTableTypeProfAt(const LineLocation &Loc,
10361038
const T &Other,

llvm/lib/ProfileData/SampleProf.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ class SampleProfErrorCategoryType : public std::error_category {
111111
return "Function hash mismatch";
112112
case sampleprof_error::illegal_line_offset:
113113
return "Illegal line offset in sample profile data";
114-
case sampleprof_error::duplicate_vtable_type:
115-
return "Duplicate vtable type in one map";
116114
}
117115
llvm_unreachable("A value of sampleprof_error has no message.");
118116
}

llvm/lib/ProfileData/SampleProfReader.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ enum class LineType {
200200
VirtualCallTypeProfile,
201201
};
202202

203+
// Parse `Input` as a white-space separated list of `vtable:count` pairs. An
204+
// example input line is `_ZTVbar:1471 _ZTVfoo:630`.
203205
static bool parseTypeCountMap(StringRef Input,
204206
DenseMap<StringRef, uint64_t> &TypeCountMap) {
205207
for (size_t Index = Input.find_first_not_of(' '); Index != StringRef::npos;) {
@@ -312,7 +314,6 @@ static bool ParseLine(const StringRef &Input, LineType &LineTy, uint32_t &Depth,
312314
n4 = AfterColon.find_first_of(' ');
313315
n4 = (n4 != StringRef::npos) ? n3 + n4 + 1 : Rest.size();
314316
StringRef WordAfterColon = Rest.substr(n3 + 1, n4 - n3 - 1);
315-
// Break the loop if parsing integer succeeded.
316317
if (!WordAfterColon.getAsInteger(10, count))
317318
break;
318319

@@ -642,17 +643,25 @@ SampleProfileReaderBinary::readVTableTypeCountMap(TypeCountMap &M) {
642643
auto VTableSamples = readNumber<uint64_t>();
643644
if (std::error_code EC = VTableSamples.getError())
644645
return EC;
645-
646-
if (!M.insert(std::make_pair(*VTableType, *VTableSamples)).second)
647-
return sampleprof_error::duplicate_vtable_type;
646+
// The source profile should not have duplicate vtable records at the same
647+
// location. In case duplicate vtables are found, reader can emit a warning
648+
// but continue processing the profile.
649+
if (!M.insert(std::make_pair(*VTableType, *VTableSamples)).second) {
650+
Ctx.diagnose(DiagnosticInfoSampleProfile(
651+
Buffer->getBufferIdentifier(), 0,
652+
"Duplicate vtable type " + VTableType->str() +
653+
" at the same location. Additional counters will be ignored.",
654+
DS_Warning));
655+
continue;
656+
}
648657
}
649658
return sampleprof_error::success;
650659
}
651660

652661
std::error_code
653662
SampleProfileReaderBinary::readCallsiteVTableProf(FunctionSamples &FProfile) {
654-
if (!ReadVTableProf)
655-
return sampleprof_error::success;
663+
assert(ReadVTableProf &&
664+
"Cannot read vtable profiles if ReadVTableProf is false");
656665

657666
// Read the vtable type profile for the callsite.
658667
auto NumCallsites = readNumber<uint32_t>();
@@ -761,7 +770,10 @@ SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) {
761770
return EC;
762771
}
763772

764-
return readCallsiteVTableProf(FProfile);
773+
if (ReadVTableProf)
774+
return readCallsiteVTableProf(FProfile);
775+
776+
return sampleprof_error::success;
765777
}
766778

767779
std::error_code

llvm/lib/ProfileData/SampleProfWriter.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,9 @@ std::error_code SampleProfileWriterExtBinaryBase::writeHeader(
855855

856856
std::error_code SampleProfileWriterBinary::writeCallsiteVTableProf(
857857
const CallsiteTypeMap &CallsiteTypeMap, raw_ostream &OS) {
858-
if (!WriteVTableProf)
859-
return sampleprof_error::success;
858+
assert(WriteVTableProf &&
859+
"writeCallsiteVTableProf should not be called if WriteVTableProf is "
860+
"false");
860861

861862
encodeULEB128(CallsiteTypeMap.size(), OS);
862863
for (const auto &[Loc, TypeMap] : CallsiteTypeMap) {
@@ -912,7 +913,10 @@ std::error_code SampleProfileWriterBinary::writeBody(const FunctionSamples &S) {
912913
return EC;
913914
}
914915

915-
return writeCallsiteVTableProf(S.getCallsiteTypeCounts(), OS);
916+
if (WriteVTableProf)
917+
return writeCallsiteVTableProf(S.getCallsiteTypeCounts(), OS);
918+
919+
return sampleprof_error::success;
916920
}
917921

918922
/// Write samples of a top-level function to a binary file.

0 commit comments

Comments
 (0)