Skip to content

[memprof] Clean up writer traits (NFC) #88549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions llvm/lib/ProfileData/InstrProfWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,29 +428,27 @@ static uint64_t writeMemProfRecords(
llvm::MapVector<GlobalValue::GUID, memprof::IndexedMemProfRecord>
&MemProfRecordData,
memprof::MemProfSchema *Schema) {
auto RecordWriter =
std::make_unique<memprof::RecordWriterTrait>(memprof::Version1);
RecordWriter->Schema = Schema;
memprof::RecordWriterTrait RecordWriter(memprof::Version1);
RecordWriter.Schema = Schema;
OnDiskChainedHashTableGenerator<memprof::RecordWriterTrait>
RecordTableGenerator;
for (auto &[GUID, Record] : MemProfRecordData) {
// Insert the key (func hash) and value (memprof record).
RecordTableGenerator.insert(GUID, Record, *RecordWriter.get());
RecordTableGenerator.insert(GUID, Record, RecordWriter);
}
// Release the memory of this MapVector as it is no longer needed.
MemProfRecordData.clear();

// The call to Emit invokes RecordWriterTrait::EmitData which destructs
// the memprof record copies owned by the RecordTableGenerator. This works
// because the RecordTableGenerator is not used after this point.
return RecordTableGenerator.Emit(OS.OS, *RecordWriter);
return RecordTableGenerator.Emit(OS.OS, RecordWriter);
}

// Serialize MemProfFrameData. Return FrameTableOffset.
static uint64_t writeMemProfFrames(
ProfOStream &OS,
llvm::MapVector<memprof::FrameId, memprof::Frame> &MemProfFrameData) {
auto FrameWriter = std::make_unique<memprof::FrameWriterTrait>();
OnDiskChainedHashTableGenerator<memprof::FrameWriterTrait>
FrameTableGenerator;
for (auto &[FrameId, Frame] : MemProfFrameData) {
Expand All @@ -460,7 +458,7 @@ static uint64_t writeMemProfFrames(
// Release the memory of this MapVector as it is no longer needed.
MemProfFrameData.clear();

return FrameTableGenerator.Emit(OS.OS, *FrameWriter);
return FrameTableGenerator.Emit(OS.OS);
}

static Error writeMemProfV0(
Expand Down