Skip to content

Commit 83dc419

Browse files
[memprof] Clean up writer traits (NFC) (#88549)
RecordWriter does not live past the end of writeMemProfRecords, so it can be safely on stack. The constructor of FrameWriter does not take any parameter, so we can let OnDiskChainedHashTableGenerator::Emit (with a single parameter) default-construct an instance of the writer trait inside Emit.
1 parent 4b0beb4 commit 83dc419

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,29 +428,27 @@ static uint64_t writeMemProfRecords(
428428
llvm::MapVector<GlobalValue::GUID, memprof::IndexedMemProfRecord>
429429
&MemProfRecordData,
430430
memprof::MemProfSchema *Schema) {
431-
auto RecordWriter =
432-
std::make_unique<memprof::RecordWriterTrait>(memprof::Version1);
433-
RecordWriter->Schema = Schema;
431+
memprof::RecordWriterTrait RecordWriter(memprof::Version1);
432+
RecordWriter.Schema = Schema;
434433
OnDiskChainedHashTableGenerator<memprof::RecordWriterTrait>
435434
RecordTableGenerator;
436435
for (auto &[GUID, Record] : MemProfRecordData) {
437436
// Insert the key (func hash) and value (memprof record).
438-
RecordTableGenerator.insert(GUID, Record, *RecordWriter.get());
437+
RecordTableGenerator.insert(GUID, Record, RecordWriter);
439438
}
440439
// Release the memory of this MapVector as it is no longer needed.
441440
MemProfRecordData.clear();
442441

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

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

463-
return FrameTableGenerator.Emit(OS.OS, *FrameWriter);
461+
return FrameTableGenerator.Emit(OS.OS);
464462
}
465463

466464
static Error writeMemProfV0(

0 commit comments

Comments
 (0)