[llvm] [memprof] Rename the members of IndexedMemProfData (NFC) (PR #94873)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 8 14:01:13 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/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.
>From bb00fe4e86253fdc34dd5c03216622056ac0c71e Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 8 Jun 2024 13:29:50 -0700
Subject: [PATCH] [memprof] Rename the members of IndexedMemProfData (NFC)
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.
---
llvm/include/llvm/ProfileData/MemProf.h | 6 +--
llvm/lib/ProfileData/InstrProfWriter.cpp | 50 ++++++++++++------------
2 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/llvm/include/llvm/ProfileData/MemProf.h b/llvm/include/llvm/ProfileData/MemProf.h
index 53ddfd1923410..e54bb27d5a03f 100644
--- a/llvm/include/llvm/ProfileData/MemProf.h
+++ b/llvm/include/llvm/ProfileData/MemProf.h
@@ -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 {
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 1a9add109a360..9454f79107390 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -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;
@@ -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
@@ -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
@@ -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);
}
}
@@ -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)}});
@@ -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)}});
@@ -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,
@@ -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,
More information about the llvm-commits
mailing list