Skip to content

Commit 773ee62

Browse files
[memprof] Rename the members of IndexedMemProfData (NFC) (llvm#94873)
I'm planning to use IndexedMemProfData in MemProfReader and beyond. Before I do so, this patch renames the members of IndexedMemProfData as MemProfData.FrameData is a bit mouthful with "Data" repeated twice. Note that MemProfReader currently has a trio -- IdToFrame, CSIdToCallStack, and FunctionProfileData. Replacing them with an instance of IndexedMemProfData allows us to use the move semantics from the reader to the writer context. More importantly, treating the profile data as one package makes the maintenance easier. In the past, forgetting to update a place dealing with the trio has resulted in a bug where we totally forgot to emit call stacks into the indexed profile.
1 parent 66df765 commit 773ee62

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

llvm/include/llvm/ProfileData/MemProf.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,15 +921,15 @@ struct LinearCallStackIdConverter {
921921
struct IndexedMemProfData {
922922
// A map to hold memprof data per function. The lower 64 bits obtained from
923923
// the md5 hash of the function name is used to index into the map.
924-
llvm::MapVector<GlobalValue::GUID, IndexedMemProfRecord> RecordData;
924+
llvm::MapVector<GlobalValue::GUID, IndexedMemProfRecord> Records;
925925

926926
// A map to hold frame id to frame mappings. The mappings are used to
927927
// convert IndexedMemProfRecord to MemProfRecords with frame information
928928
// inline.
929-
llvm::MapVector<FrameId, Frame> FrameData;
929+
llvm::MapVector<FrameId, Frame> Frames;
930930

931931
// A map to hold call stack id to call stacks.
932-
llvm::MapVector<CallStackId, llvm::SmallVector<FrameId>> CallStackData;
932+
llvm::MapVector<CallStackId, llvm::SmallVector<FrameId>> CallStacks;
933933
};
934934

935935
struct FrameStat {

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ void InstrProfWriter::addRecord(StringRef Name, uint64_t Hash,
274274

275275
void InstrProfWriter::addMemProfRecord(
276276
const Function::GUID Id, const memprof::IndexedMemProfRecord &Record) {
277-
auto [Iter, Inserted] = MemProfData.RecordData.insert({Id, Record});
277+
auto [Iter, Inserted] = MemProfData.Records.insert({Id, Record});
278278
// If we inserted a new record then we are done.
279279
if (Inserted) {
280280
return;
@@ -286,7 +286,7 @@ void InstrProfWriter::addMemProfRecord(
286286
bool InstrProfWriter::addMemProfFrame(const memprof::FrameId Id,
287287
const memprof::Frame &Frame,
288288
function_ref<void(Error)> Warn) {
289-
auto [Iter, Inserted] = MemProfData.FrameData.insert({Id, Frame});
289+
auto [Iter, Inserted] = MemProfData.Frames.insert({Id, Frame});
290290
// If a mapping already exists for the current frame id and it does not
291291
// match the new mapping provided then reset the existing contents and bail
292292
// out. We don't support the merging of memprof data whose Frame -> Id
@@ -303,7 +303,7 @@ bool InstrProfWriter::addMemProfCallStack(
303303
const memprof::CallStackId CSId,
304304
const llvm::SmallVector<memprof::FrameId> &CallStack,
305305
function_ref<void(Error)> Warn) {
306-
auto [Iter, Inserted] = MemProfData.CallStackData.insert({CSId, CallStack});
306+
auto [Iter, Inserted] = MemProfData.CallStacks.insert({CSId, CallStack});
307307
// If a mapping already exists for the current call stack id and it does not
308308
// match the new mapping provided then reset the existing contents and bail
309309
// out. We don't support the merging of memprof data whose CallStack -> Id
@@ -390,22 +390,22 @@ void InstrProfWriter::mergeRecordsFromWriter(InstrProfWriter &&IPW,
390390
addTemporalProfileTraces(IPW.TemporalProfTraces,
391391
IPW.TemporalProfTraceStreamSize);
392392

393-
MemProfData.FrameData.reserve(IPW.MemProfData.FrameData.size());
394-
for (auto &[FrameId, Frame] : IPW.MemProfData.FrameData) {
393+
MemProfData.Frames.reserve(IPW.MemProfData.Frames.size());
394+
for (auto &[FrameId, Frame] : IPW.MemProfData.Frames) {
395395
// If we weren't able to add the frame mappings then it doesn't make sense
396396
// to try to merge the records from this profile.
397397
if (!addMemProfFrame(FrameId, Frame, Warn))
398398
return;
399399
}
400400

401-
MemProfData.CallStackData.reserve(IPW.MemProfData.CallStackData.size());
402-
for (auto &[CSId, CallStack] : IPW.MemProfData.CallStackData) {
401+
MemProfData.CallStacks.reserve(IPW.MemProfData.CallStacks.size());
402+
for (auto &[CSId, CallStack] : IPW.MemProfData.CallStacks) {
403403
if (!addMemProfCallStack(CSId, CallStack, Warn))
404404
return;
405405
}
406406

407-
MemProfData.RecordData.reserve(IPW.MemProfData.RecordData.size());
408-
for (auto &[GUID, Record] : IPW.MemProfData.RecordData) {
407+
MemProfData.Records.reserve(IPW.MemProfData.Records.size());
408+
for (auto &[GUID, Record] : IPW.MemProfData.Records) {
409409
addMemProfRecord(GUID, Record);
410410
}
411411
}
@@ -605,11 +605,11 @@ static Error writeMemProfV0(ProfOStream &OS,
605605
auto Schema = memprof::getFullSchema();
606606
writeMemProfSchema(OS, Schema);
607607

608-
uint64_t RecordTableOffset = writeMemProfRecords(OS, MemProfData.RecordData,
609-
&Schema, memprof::Version0);
608+
uint64_t RecordTableOffset =
609+
writeMemProfRecords(OS, MemProfData.Records, &Schema, memprof::Version0);
610610

611611
uint64_t FramePayloadOffset = OS.tell();
612-
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.FrameData);
612+
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.Frames);
613613

614614
uint64_t Header[] = {RecordTableOffset, FramePayloadOffset, FrameTableOffset};
615615
OS.patch({{HeaderUpdatePos, Header, std::size(Header)}});
@@ -640,11 +640,11 @@ static Error writeMemProfV1(ProfOStream &OS,
640640
auto Schema = memprof::getFullSchema();
641641
writeMemProfSchema(OS, Schema);
642642

643-
uint64_t RecordTableOffset = writeMemProfRecords(OS, MemProfData.RecordData,
644-
&Schema, memprof::Version1);
643+
uint64_t RecordTableOffset =
644+
writeMemProfRecords(OS, MemProfData.Records, &Schema, memprof::Version1);
645645

646646
uint64_t FramePayloadOffset = OS.tell();
647-
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.FrameData);
647+
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.Frames);
648648

649649
uint64_t Header[] = {RecordTableOffset, FramePayloadOffset, FrameTableOffset};
650650
OS.patch({{HeaderUpdatePos, Header, std::size(Header)}});
@@ -683,15 +683,15 @@ static Error writeMemProfV2(ProfOStream &OS,
683683
Schema = memprof::getFullSchema();
684684
writeMemProfSchema(OS, Schema);
685685

686-
uint64_t RecordTableOffset = writeMemProfRecords(OS, MemProfData.RecordData,
687-
&Schema, memprof::Version2);
686+
uint64_t RecordTableOffset =
687+
writeMemProfRecords(OS, MemProfData.Records, &Schema, memprof::Version2);
688688

689689
uint64_t FramePayloadOffset = OS.tell();
690-
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.FrameData);
690+
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.Frames);
691691

692692
uint64_t CallStackPayloadOffset = OS.tell();
693693
uint64_t CallStackTableOffset =
694-
writeMemProfCallStacks(OS, MemProfData.CallStackData);
694+
writeMemProfCallStacks(OS, MemProfData.CallStacks);
695695

696696
uint64_t Header[] = {
697697
RecordTableOffset, FramePayloadOffset, FrameTableOffset,
@@ -730,21 +730,21 @@ static Error writeMemProfV3(ProfOStream &OS,
730730
writeMemProfSchema(OS, Schema);
731731

732732
llvm::DenseMap<memprof::FrameId, memprof::FrameStat> FrameHistogram =
733-
memprof::computeFrameHistogram(MemProfData.CallStackData);
734-
assert(MemProfData.FrameData.size() == FrameHistogram.size());
733+
memprof::computeFrameHistogram(MemProfData.CallStacks);
734+
assert(MemProfData.Frames.size() == FrameHistogram.size());
735735

736736
llvm::DenseMap<memprof::FrameId, memprof::LinearFrameId> MemProfFrameIndexes =
737-
writeMemProfFrameArray(OS, MemProfData.FrameData, FrameHistogram);
737+
writeMemProfFrameArray(OS, MemProfData.Frames, FrameHistogram);
738738

739739
uint64_t CallStackPayloadOffset = OS.tell();
740740
llvm::DenseMap<memprof::CallStackId, memprof::LinearCallStackId>
741741
MemProfCallStackIndexes = writeMemProfCallStackArray(
742-
OS, MemProfData.CallStackData, MemProfFrameIndexes, FrameHistogram);
742+
OS, MemProfData.CallStacks, MemProfFrameIndexes, FrameHistogram);
743743

744744
uint64_t RecordPayloadOffset = OS.tell();
745745
uint64_t RecordTableOffset =
746-
writeMemProfRecords(OS, MemProfData.RecordData, &Schema,
747-
memprof::Version3, &MemProfCallStackIndexes);
746+
writeMemProfRecords(OS, MemProfData.Records, &Schema, memprof::Version3,
747+
&MemProfCallStackIndexes);
748748

749749
uint64_t Header[] = {
750750
CallStackPayloadOffset,

0 commit comments

Comments
 (0)