Skip to content

Commit a925b7e

Browse files
merge <vt-call> and <vt-inline>
1 parent 7d064bf commit a925b7e

File tree

6 files changed

+41
-77
lines changed

6 files changed

+41
-77
lines changed

llvm/include/llvm/ProfileData/SampleProf.h

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace llvm {
9292
namespace sampleprof {
9393

9494
constexpr char kBodySampleVTableProfPrefix[] = "<vt-call> ";
95-
constexpr char kInlinedCallsiteVTablerofPrefix[] = "<vt-inline> ";
95+
// constexpr char kInlinedCallsiteVTablerofPrefix[] = "<vt-inline> ";
9696

9797
enum SampleProfileFormat {
9898
SPF_None = 0,
@@ -413,10 +413,6 @@ class SampleRecord {
413413

414414
uint64_t getSamples() const { return NumSamples; }
415415
const CallTargetMap &getCallTargets() const { return CallTargets; }
416-
const TypeCountMap &getVTableAccessCounts() const {
417-
return VTableAccessCounts;
418-
}
419-
TypeCountMap &getVTableAccessCounts() { return VTableAccessCounts; }
420416
const SortedCallTargetSet getSortedCallTargets() const {
421417
return sortCallTargets(CallTargets);
422418
}
@@ -470,8 +466,6 @@ class SampleRecord {
470466
private:
471467
uint64_t NumSamples = 0;
472468
CallTargetMap CallTargets;
473-
// The vtable types and their counts in this sample record.
474-
TypeCountMap VTableAccessCounts;
475469
};
476470

477471
raw_ostream &operator<<(raw_ostream &OS, const SampleRecord &Sample);
@@ -825,16 +819,6 @@ class FunctionSamples {
825819
Func, Num, Weight);
826820
}
827821

828-
sampleprof_error addFunctionBodyTypeSamples(const LineLocation &Loc,
829-
FunctionId Func, uint64_t Num,
830-
uint64_t Weight = 1) {
831-
return BodySamples[Loc].addVTableAccessCount(Func, Num, Weight);
832-
}
833-
834-
TypeCountMap &getFunctionBodyTypeSamples(const LineLocation &Loc) {
835-
return BodySamples[Loc].getVTableAccessCounts();
836-
}
837-
838822
sampleprof_error addSampleRecord(LineLocation Location,
839823
const SampleRecord &SampleRecord,
840824
uint64_t Weight = 1) {
@@ -962,8 +946,8 @@ class FunctionSamples {
962946

963947
/// Returns the TypeCountMap for inlined callsites at the given \p Loc.
964948
const TypeCountMap *findCallsiteTypeSamplesAt(const LineLocation &Loc) const {
965-
auto Iter = VirtualCallsiteTypes.find(mapIRLocToProfileLoc(Loc));
966-
if (Iter == VirtualCallsiteTypes.end())
949+
auto Iter = VirtualCallsiteTypeCounts.find(mapIRLocToProfileLoc(Loc));
950+
if (Iter == VirtualCallsiteTypeCounts.end())
967951
return nullptr;
968952
return &Iter->second;
969953
}
@@ -1032,12 +1016,12 @@ class FunctionSamples {
10321016
/// Return all the callsite type samples collected in the body of the
10331017
/// function.
10341018
const CallsiteTypeMap &getCallsiteTypeCounts() const {
1035-
return VirtualCallsiteTypes;
1019+
return VirtualCallsiteTypeCounts;
10361020
}
10371021

10381022
/// Returns the type samples for the un-drifted location of \p Loc.
10391023
TypeCountMap &getTypeSamplesAt(const LineLocation &Loc) {
1040-
return VirtualCallsiteTypes[mapIRLocToProfileLoc(Loc)];
1024+
return VirtualCallsiteTypeCounts[mapIRLocToProfileLoc(Loc)];
10411025
}
10421026

10431027
/// Scale \p Other sample counts by \p Weight and add the scaled result to the
@@ -1381,7 +1365,7 @@ class FunctionSamples {
13811365
/// }
13821366
/// This map will contain two entries. One with two types for line offset 5
13831367
/// and one with one type for line offset 200.
1384-
CallsiteTypeMap VirtualCallsiteTypes;
1368+
CallsiteTypeMap VirtualCallsiteTypeCounts;
13851369

13861370
/// IR to profile location map generated by stale profile matching.
13871371
///

llvm/lib/ProfileData/SampleProf.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ sampleprof_error SampleRecord::merge(const SampleRecord &Other,
146146
for (const auto &I : Other.getCallTargets()) {
147147
mergeSampleProfErrors(Result, addCalledTarget(I.first, I.second, Weight));
148148
}
149-
for (const auto &[TypeName, Count] : Other.getVTableAccessCounts())
150-
mergeSampleProfErrors(Result,
151-
addVTableAccessCount(TypeName, Count, Weight));
152149

153150
return Result;
154151
}
@@ -171,8 +168,6 @@ SampleRecord::serialize(raw_ostream &OS,
171168
}
172169
encodeULEB128(CalleeSamples, OS);
173170
}
174-
if (SerializeVTableProf)
175-
return serializeTypeMap(VTableAccessCounts, NameTable, OS);
176171
return sampleprof_error::success;
177172
}
178173

@@ -193,11 +188,6 @@ void SampleRecord::print(raw_ostream &OS, unsigned Indent) const {
193188
for (const auto &I : getSortedCallTargets())
194189
OS << " " << I.first << ":" << I.second;
195190
}
196-
if (!VTableAccessCounts.empty()) {
197-
OS << ", vtables:";
198-
for (const auto [Type, Count] : VTableAccessCounts)
199-
OS << " " << Type << ":" << Count;
200-
}
201191
OS << "\n";
202192
}
203193

@@ -216,7 +206,8 @@ sampleprof_error SampleRecord::addCalledTarget(FunctionId F, uint64_t S,
216206

217207
sampleprof_error SampleRecord::addVTableAccessCount(FunctionId F, uint64_t S,
218208
uint64_t Weight) {
219-
return addWeightSample(S, Weight, VTableAccessCounts[F]);
209+
return sampleprof_error::success;
210+
// return addWeightSample(S, Weight, VTableAccessCounts[F]);
220211
}
221212

222213
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
@@ -229,6 +220,18 @@ raw_ostream &llvm::sampleprof::operator<<(raw_ostream &OS,
229220
return OS;
230221
}
231222

223+
template <typename T>
224+
static void printTypeCountMap(raw_ostream &OS, T Loc,
225+
const TypeCountMap &TypeCountMap) {
226+
if (TypeCountMap.empty()) {
227+
return;
228+
}
229+
OS << Loc << ": vtables: ";
230+
for (const auto &[Type, Count] : TypeCountMap)
231+
OS << Type << ":" << Count << " ";
232+
OS << "\n";
233+
}
234+
232235
/// Print the samples collected for a function on stream \p OS.
233236
void FunctionSamples::print(raw_ostream &OS, unsigned Indent) const {
234237
if (getFunctionHash())
@@ -243,7 +246,13 @@ void FunctionSamples::print(raw_ostream &OS, unsigned Indent) const {
243246
SampleSorter<LineLocation, SampleRecord> SortedBodySamples(BodySamples);
244247
for (const auto &SI : SortedBodySamples.get()) {
245248
OS.indent(Indent + 2);
249+
const auto &Loc = SI->first;
246250
OS << SI->first << ": " << SI->second;
251+
if (const TypeCountMap *TypeCountMap =
252+
this->findCallsiteTypeSamplesAt(Loc)) {
253+
OS.indent(Indent + 2);
254+
printTypeCountMap(OS, Loc, *TypeCountMap);
255+
}
247256
}
248257
OS.indent(Indent);
249258
OS << "}\n";
@@ -264,14 +273,10 @@ void FunctionSamples::print(raw_ostream &OS, unsigned Indent) const {
264273
FuncSample.print(OS, Indent + 4);
265274
}
266275
const LineLocation &Loc = CS->first;
267-
auto TypeSamplesIter = VirtualCallsiteTypes.find(Loc);
268-
if (TypeSamplesIter != VirtualCallsiteTypes.end()) {
276+
auto TypeSamplesIter = VirtualCallsiteTypeCounts.find(Loc);
277+
if (TypeSamplesIter != VirtualCallsiteTypeCounts.end()) {
269278
OS.indent(Indent + 2);
270-
OS << Loc << ": vtables: ";
271-
for (const auto &TypeSample : TypeSamplesIter->second) {
272-
OS << TypeSample.first << ":" << TypeSample.second << " ";
273-
}
274-
OS << "\n";
279+
printTypeCountMap(OS, Loc, TypeSamplesIter->second);
275280
}
276281
}
277282
OS.indent(Indent);

llvm/lib/ProfileData/SampleProfReader.cpp

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ enum class LineType {
197197
CallSiteProfile,
198198
BodyProfile,
199199
Metadata,
200-
CallTargetTypeProfile,
201-
CallSiteTypeProfile,
200+
VirtualCallTypeProfile,
202201
};
203202

204203
static bool parseTypeCountMap(StringRef Input,
@@ -332,13 +331,9 @@ static bool ParseLine(const StringRef &Input, LineType &LineTy, uint32_t &Depth,
332331
n3 = n4;
333332
}
334333
} else if (Rest.starts_with(kBodySampleVTableProfPrefix)) {
335-
LineTy = LineType::CallTargetTypeProfile;
334+
LineTy = LineType::VirtualCallTypeProfile;
336335
return parseTypeCountMap(Rest.substr(strlen(kBodySampleVTableProfPrefix)),
337336
TypeCountMap);
338-
} else if (Rest.starts_with(kInlinedCallsiteVTablerofPrefix)) {
339-
LineTy = LineType::CallSiteTypeProfile;
340-
return parseTypeCountMap(
341-
Rest.substr(strlen(kInlinedCallsiteVTablerofPrefix)), TypeCountMap);
342337
} else {
343338
LineTy = LineType::CallSiteProfile;
344339
size_t n3 = Rest.find_last_of(':');
@@ -445,27 +440,13 @@ std::error_code SampleProfileReaderText::readImpl() {
445440
break;
446441
}
447442

448-
case LineType::CallSiteTypeProfile: {
443+
case LineType::VirtualCallTypeProfile: {
449444
mergeSampleProfErrors(
450445
Result, InlineStack.back()->addCallsiteVTableTypeProfAt(
451446
LineLocation(LineOffset, Discriminator), TypeCountMap));
452447
break;
453448
}
454449

455-
case LineType::CallTargetTypeProfile: {
456-
while (InlineStack.size() > Depth) {
457-
InlineStack.pop_back();
458-
}
459-
FunctionSamples &FProfile = *InlineStack.back();
460-
for (const auto &name_count : TypeCountMap) {
461-
mergeSampleProfErrors(
462-
Result, FProfile.addFunctionBodyTypeSamples(
463-
LineLocation(LineOffset, Discriminator),
464-
FunctionId(name_count.first), name_count.second));
465-
}
466-
break;
467-
}
468-
469450
case LineType::BodyProfile: {
470451
FunctionSamples &FProfile = *InlineStack.back();
471452
for (const auto &name_count : TargetCountMap) {
@@ -749,14 +730,6 @@ SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) {
749730
*CalledFunction, *CalledFunctionSamples);
750731
}
751732

752-
if (ReadVTableProf) {
753-
// read vtable type profiles.
754-
if (std::error_code EC =
755-
readVTableTypeCountMap(FProfile.getFunctionBodyTypeSamples(
756-
LineLocation(*LineOffset, DiscriminatorVal))))
757-
return EC;
758-
}
759-
760733
FProfile.addBodySamples(*LineOffset, DiscriminatorVal, *NumSamples);
761734
}
762735

llvm/lib/ProfileData/SampleProfWriter.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -600,16 +600,18 @@ std::error_code SampleProfileWriterText::writeSample(const FunctionSamples &S) {
600600
OS << " " << J.first << ":" << J.second;
601601
OS << "\n";
602602

603-
if (!Sample.getVTableAccessCounts().empty()) {
603+
if (const TypeCountMap *Map = S.findCallsiteTypeSamplesAt(Loc);
604+
Map && !Map->empty()) {
604605
OS.indent(Indent + 1);
605606
Loc.print(OS);
606607
OS << ": ";
607608
OS << kBodySampleVTableProfPrefix;
608-
for (const auto [TypeName, Count] : Sample.getVTableAccessCounts())
609+
for (const auto [TypeName, Count] : *Map) {
609610
OS << TypeName << ":" << Count << " ";
611+
}
610612
OS << "\n";
613+
LineCount++;
611614
}
612-
LineCount++;
613615
}
614616

615617
SampleSorter<LineLocation, FunctionSamplesMap> SortedCallsiteSamples(
@@ -631,7 +633,7 @@ std::error_code SampleProfileWriterText::writeSample(const FunctionSamples &S) {
631633
OS.indent(Indent);
632634
Loc.print(OS);
633635
OS << ": ";
634-
OS << kInlinedCallsiteVTablerofPrefix;
636+
OS << kBodySampleVTableProfPrefix;
635637
for (const auto [TypeId, Count] : *Map) {
636638
OS << TypeId << ":" << Count << " ";
637639
}
@@ -698,7 +700,6 @@ void SampleProfileWriterBinary::addNames(const FunctionSamples &S) {
698700
const SampleRecord &Sample = I.second;
699701
for (const auto &J : Sample.getCallTargets())
700702
addName(J.first);
701-
addTypeNames(Sample.getVTableAccessCounts());
702703
}
703704

704705
// Add all the names in callsite types.

llvm/test/tools/llvm-profdata/Inputs/profile-symbol-list-ext.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Samples collected in the function's body {
66
5.1: 2150
77
6: 4160
88
7: 1068
9-
9: 4128, calls: _Z3bari:2942 _Z3fooi:1262, vtables: _ZTVbar:2942 _ZTVfoo:1260
9+
9: 4128, calls: _Z3bari:2942 _Z3fooi:1262
10+
9: vtables: _ZTVbar:2942 _ZTVfoo:1260
1011
}
1112
Samples collected in inlined callsites {
1213
10: inlined callee: inline1: 2000, 0, 1 sampled lines

llvm/test/tools/llvm-profdata/Inputs/sample-profile-ext.proftext

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ main:184019:0
1111
1: 1000
1212
10: inline2:2000
1313
1: 2000
14-
10: <vt-inline> _ZTVinline1:1000 _ZTVinline2:2000
14+
10: <vt-call> _ZTVinline1:1000 _ZTVinline2:2000
1515
_Z3bari:20301:1437
1616
1: 1437
1717
_Z3fooi:7711:610

0 commit comments

Comments
 (0)