Skip to content

Commit 9a8b73c

Browse files
[memprof] Replace uint32_t with LinearCallStackId where appropriate (NFC) (#94023)
This patch replaces uint32_t with LinearCallStackId where appropriate. I'm replacing uint64_t with LinearCallStackId in writeMemProfCallStackArray, but that's OK because it's a value to be used as LinearCallStackId anyway.
1 parent 62c61aa commit 9a8b73c

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

llvm/include/llvm/ProfileData/MemProf.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,15 @@ class RecordWriterTrait {
563563
IndexedVersion Version;
564564

565565
// Mappings from CallStackId to the indexes into the call stack array.
566-
llvm::DenseMap<memprof::CallStackId, uint32_t> *MemProfCallStackIndexes;
566+
llvm::DenseMap<memprof::CallStackId, LinearCallStackId>
567+
*MemProfCallStackIndexes;
567568

568569
public:
569570
// We do not support the default constructor, which does not set Version.
570571
RecordWriterTrait() = delete;
571-
RecordWriterTrait(
572-
const MemProfSchema *Schema, IndexedVersion V,
573-
llvm::DenseMap<memprof::CallStackId, uint32_t> *MemProfCallStackIndexes)
572+
RecordWriterTrait(const MemProfSchema *Schema, IndexedVersion V,
573+
llvm::DenseMap<memprof::CallStackId, LinearCallStackId>
574+
*MemProfCallStackIndexes)
574575
: Schema(Schema), Version(V),
575576
MemProfCallStackIndexes(MemProfCallStackIndexes) {}
576577

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,8 @@ static uint64_t writeMemProfRecords(
454454
llvm::MapVector<GlobalValue::GUID, memprof::IndexedMemProfRecord>
455455
&MemProfRecordData,
456456
memprof::MemProfSchema *Schema, memprof::IndexedVersion Version,
457-
llvm::DenseMap<memprof::CallStackId, uint32_t> *MemProfCallStackIndexes =
458-
nullptr) {
457+
llvm::DenseMap<memprof::CallStackId, memprof::LinearCallStackId>
458+
*MemProfCallStackIndexes = nullptr) {
459459
memprof::RecordWriterTrait RecordWriter(Schema, Version,
460460
MemProfCallStackIndexes);
461461
OnDiskChainedHashTableGenerator<memprof::RecordWriterTrait>
@@ -536,18 +536,20 @@ static uint64_t writeMemProfCallStacks(
536536
return CallStackTableGenerator.Emit(OS.OS);
537537
}
538538

539-
static llvm::DenseMap<memprof::CallStackId, uint32_t>
539+
static llvm::DenseMap<memprof::CallStackId, memprof::LinearCallStackId>
540540
writeMemProfCallStackArray(
541541
ProfOStream &OS,
542542
llvm::MapVector<memprof::CallStackId, llvm::SmallVector<memprof::FrameId>>
543543
&MemProfCallStackData,
544544
llvm::DenseMap<memprof::FrameId, uint32_t> &MemProfFrameIndexes) {
545-
llvm::DenseMap<memprof::CallStackId, uint32_t> MemProfCallStackIndexes;
545+
llvm::DenseMap<memprof::CallStackId, memprof::LinearCallStackId>
546+
MemProfCallStackIndexes;
546547

547548
MemProfCallStackIndexes.reserve(MemProfCallStackData.size());
548549
uint64_t CallStackBase = OS.tell();
549550
for (const auto &[CSId, CallStack] : MemProfCallStackData) {
550-
uint64_t CallStackIndex = (OS.tell() - CallStackBase) / sizeof(uint32_t);
551+
memprof::LinearCallStackId CallStackIndex =
552+
(OS.tell() - CallStackBase) / sizeof(memprof::LinearCallStackId);
551553
MemProfCallStackIndexes.insert({CSId, CallStackIndex});
552554
const llvm::SmallVector<memprof::FrameId> CS = CallStack;
553555
OS.write32(CS.size());
@@ -712,9 +714,9 @@ static Error writeMemProfV3(ProfOStream &OS,
712714
writeMemProfFrameArray(OS, MemProfData.FrameData);
713715

714716
uint64_t CallStackPayloadOffset = OS.tell();
715-
llvm::DenseMap<memprof::CallStackId, uint32_t> MemProfCallStackIndexes =
716-
writeMemProfCallStackArray(OS, MemProfData.CallStackData,
717-
MemProfFrameIndexes);
717+
llvm::DenseMap<memprof::CallStackId, memprof::LinearCallStackId>
718+
MemProfCallStackIndexes = writeMemProfCallStackArray(
719+
OS, MemProfData.CallStackData, MemProfFrameIndexes);
718720

719721
uint64_t RecordPayloadOffset = OS.tell();
720722
uint64_t RecordTableOffset =

llvm/lib/ProfileData/MemProf.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,32 +169,32 @@ static void serializeV2(const IndexedMemProfRecord &Record,
169169
LE.write<CallStackId>(CSId);
170170
}
171171

172-
static void
173-
serializeV3(const IndexedMemProfRecord &Record, const MemProfSchema &Schema,
174-
raw_ostream &OS,
175-
llvm::DenseMap<CallStackId, uint32_t> &MemProfCallStackIndexes) {
172+
static void serializeV3(
173+
const IndexedMemProfRecord &Record, const MemProfSchema &Schema,
174+
raw_ostream &OS,
175+
llvm::DenseMap<CallStackId, LinearCallStackId> &MemProfCallStackIndexes) {
176176
using namespace support;
177177

178178
endian::Writer LE(OS, llvm::endianness::little);
179179

180180
LE.write<uint64_t>(Record.AllocSites.size());
181181
for (const IndexedAllocationInfo &N : Record.AllocSites) {
182182
assert(MemProfCallStackIndexes.contains(N.CSId));
183-
LE.write<uint32_t>(MemProfCallStackIndexes[N.CSId]);
183+
LE.write<LinearCallStackId>(MemProfCallStackIndexes[N.CSId]);
184184
N.Info.serialize(Schema, OS);
185185
}
186186

187187
// Related contexts.
188188
LE.write<uint64_t>(Record.CallSiteIds.size());
189189
for (const auto &CSId : Record.CallSiteIds) {
190190
assert(MemProfCallStackIndexes.contains(CSId));
191-
LE.write<uint32_t>(MemProfCallStackIndexes[CSId]);
191+
LE.write<LinearCallStackId>(MemProfCallStackIndexes[CSId]);
192192
}
193193
}
194194

195195
void IndexedMemProfRecord::serialize(
196196
const MemProfSchema &Schema, raw_ostream &OS, IndexedVersion Version,
197-
llvm::DenseMap<CallStackId, uint32_t> *MemProfCallStackIndexes) {
197+
llvm::DenseMap<CallStackId, LinearCallStackId> *MemProfCallStackIndexes) {
198198
switch (Version) {
199199
case Version0:
200200
case Version1:
@@ -297,7 +297,8 @@ static IndexedMemProfRecord deserializeV3(const MemProfSchema &Schema,
297297
Record.AllocSites.reserve(NumNodes);
298298
for (uint64_t I = 0; I < NumNodes; I++) {
299299
IndexedAllocationInfo Node;
300-
Node.CSId = endian::readNext<uint32_t, llvm::endianness::little>(Ptr);
300+
Node.CSId =
301+
endian::readNext<LinearCallStackId, llvm::endianness::little>(Ptr);
301302
Node.Info.deserialize(Schema, Ptr);
302303
Ptr += PortableMemInfoBlock::serializedSize(Schema);
303304
Record.AllocSites.push_back(Node);

0 commit comments

Comments
 (0)