Skip to content

Commit

Permalink
[memprof] Rename the members of IndexedMemProfData (NFC) (llvm#94873)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kazutakahirata committed Jun 18, 2024
1 parent 66df765 commit 773ee62
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions llvm/include/llvm/ProfileData/MemProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -921,15 +921,15 @@ struct LinearCallStackIdConverter {
struct IndexedMemProfData {
// A map to hold memprof data per function. The lower 64 bits obtained from
// the md5 hash of the function name is used to index into the map.
llvm::MapVector<GlobalValue::GUID, IndexedMemProfRecord> RecordData;
llvm::MapVector<GlobalValue::GUID, IndexedMemProfRecord> Records;

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

// A map to hold call stack id to call stacks.
llvm::MapVector<CallStackId, llvm::SmallVector<FrameId>> CallStackData;
llvm::MapVector<CallStackId, llvm::SmallVector<FrameId>> CallStacks;
};

struct FrameStat {
Expand Down
50 changes: 25 additions & 25 deletions llvm/lib/ProfileData/InstrProfWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void InstrProfWriter::addRecord(StringRef Name, uint64_t Hash,

void InstrProfWriter::addMemProfRecord(
const Function::GUID Id, const memprof::IndexedMemProfRecord &Record) {
auto [Iter, Inserted] = MemProfData.RecordData.insert({Id, Record});
auto [Iter, Inserted] = MemProfData.Records.insert({Id, Record});
// If we inserted a new record then we are done.
if (Inserted) {
return;
Expand All @@ -286,7 +286,7 @@ void InstrProfWriter::addMemProfRecord(
bool InstrProfWriter::addMemProfFrame(const memprof::FrameId Id,
const memprof::Frame &Frame,
function_ref<void(Error)> Warn) {
auto [Iter, Inserted] = MemProfData.FrameData.insert({Id, Frame});
auto [Iter, Inserted] = MemProfData.Frames.insert({Id, Frame});
// If a mapping already exists for the current frame id and it does not
// match the new mapping provided then reset the existing contents and bail
// out. We don't support the merging of memprof data whose Frame -> Id
Expand All @@ -303,7 +303,7 @@ bool InstrProfWriter::addMemProfCallStack(
const memprof::CallStackId CSId,
const llvm::SmallVector<memprof::FrameId> &CallStack,
function_ref<void(Error)> Warn) {
auto [Iter, Inserted] = MemProfData.CallStackData.insert({CSId, CallStack});
auto [Iter, Inserted] = MemProfData.CallStacks.insert({CSId, CallStack});
// If a mapping already exists for the current call stack id and it does not
// match the new mapping provided then reset the existing contents and bail
// out. We don't support the merging of memprof data whose CallStack -> Id
Expand Down Expand Up @@ -390,22 +390,22 @@ void InstrProfWriter::mergeRecordsFromWriter(InstrProfWriter &&IPW,
addTemporalProfileTraces(IPW.TemporalProfTraces,
IPW.TemporalProfTraceStreamSize);

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

MemProfData.CallStackData.reserve(IPW.MemProfData.CallStackData.size());
for (auto &[CSId, CallStack] : IPW.MemProfData.CallStackData) {
MemProfData.CallStacks.reserve(IPW.MemProfData.CallStacks.size());
for (auto &[CSId, CallStack] : IPW.MemProfData.CallStacks) {
if (!addMemProfCallStack(CSId, CallStack, Warn))
return;
}

MemProfData.RecordData.reserve(IPW.MemProfData.RecordData.size());
for (auto &[GUID, Record] : IPW.MemProfData.RecordData) {
MemProfData.Records.reserve(IPW.MemProfData.Records.size());
for (auto &[GUID, Record] : IPW.MemProfData.Records) {
addMemProfRecord(GUID, Record);
}
}
Expand Down Expand Up @@ -605,11 +605,11 @@ static Error writeMemProfV0(ProfOStream &OS,
auto Schema = memprof::getFullSchema();
writeMemProfSchema(OS, Schema);

uint64_t RecordTableOffset = writeMemProfRecords(OS, MemProfData.RecordData,
&Schema, memprof::Version0);
uint64_t RecordTableOffset =
writeMemProfRecords(OS, MemProfData.Records, &Schema, memprof::Version0);

uint64_t FramePayloadOffset = OS.tell();
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.FrameData);
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.Frames);

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

uint64_t RecordTableOffset = writeMemProfRecords(OS, MemProfData.RecordData,
&Schema, memprof::Version1);
uint64_t RecordTableOffset =
writeMemProfRecords(OS, MemProfData.Records, &Schema, memprof::Version1);

uint64_t FramePayloadOffset = OS.tell();
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.FrameData);
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.Frames);

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

uint64_t RecordTableOffset = writeMemProfRecords(OS, MemProfData.RecordData,
&Schema, memprof::Version2);
uint64_t RecordTableOffset =
writeMemProfRecords(OS, MemProfData.Records, &Schema, memprof::Version2);

uint64_t FramePayloadOffset = OS.tell();
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.FrameData);
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.Frames);

uint64_t CallStackPayloadOffset = OS.tell();
uint64_t CallStackTableOffset =
writeMemProfCallStacks(OS, MemProfData.CallStackData);
writeMemProfCallStacks(OS, MemProfData.CallStacks);

uint64_t Header[] = {
RecordTableOffset, FramePayloadOffset, FrameTableOffset,
Expand Down Expand Up @@ -730,21 +730,21 @@ static Error writeMemProfV3(ProfOStream &OS,
writeMemProfSchema(OS, Schema);

llvm::DenseMap<memprof::FrameId, memprof::FrameStat> FrameHistogram =
memprof::computeFrameHistogram(MemProfData.CallStackData);
assert(MemProfData.FrameData.size() == FrameHistogram.size());
memprof::computeFrameHistogram(MemProfData.CallStacks);
assert(MemProfData.Frames.size() == FrameHistogram.size());

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

uint64_t CallStackPayloadOffset = OS.tell();
llvm::DenseMap<memprof::CallStackId, memprof::LinearCallStackId>
MemProfCallStackIndexes = writeMemProfCallStackArray(
OS, MemProfData.CallStackData, MemProfFrameIndexes, FrameHistogram);
OS, MemProfData.CallStacks, MemProfFrameIndexes, FrameHistogram);

uint64_t RecordPayloadOffset = OS.tell();
uint64_t RecordTableOffset =
writeMemProfRecords(OS, MemProfData.RecordData, &Schema,
memprof::Version3, &MemProfCallStackIndexes);
writeMemProfRecords(OS, MemProfData.Records, &Schema, memprof::Version3,
&MemProfCallStackIndexes);

uint64_t Header[] = {
CallStackPayloadOffset,
Expand Down

0 comments on commit 773ee62

Please sign in to comment.