[llvm] 83dc419 - [memprof] Clean up writer traits (NFC) (#88549)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 12 11:14:24 PDT 2024
Author: Kazu Hirata
Date: 2024-04-12T11:14:20-07:00
New Revision: 83dc41992dc602070f5429e2717352f60aad931c
URL: https://github.com/llvm/llvm-project/commit/83dc41992dc602070f5429e2717352f60aad931c
DIFF: https://github.com/llvm/llvm-project/commit/83dc41992dc602070f5429e2717352f60aad931c.diff
LOG: [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.
Added:
Modified:
llvm/lib/ProfileData/InstrProfWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 7c56cde3e6cedd..ede042dd6b9c3c 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -428,14 +428,13 @@ 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();
@@ -443,14 +442,13 @@ static uint64_t writeMemProfRecords(
// 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) {
@@ -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(
More information about the llvm-commits
mailing list