Skip to content

[memprof] Replace uint32_t with LinearCallStackId where appropriate (NFC) #94023

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
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions llvm/include/llvm/ProfileData/MemProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -563,14 +563,15 @@ class RecordWriterTrait {
IndexedVersion Version;

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

public:
// We do not support the default constructor, which does not set Version.
RecordWriterTrait() = delete;
RecordWriterTrait(
const MemProfSchema *Schema, IndexedVersion V,
llvm::DenseMap<memprof::CallStackId, uint32_t> *MemProfCallStackIndexes)
RecordWriterTrait(const MemProfSchema *Schema, IndexedVersion V,
llvm::DenseMap<memprof::CallStackId, LinearCallStackId>
*MemProfCallStackIndexes)
: Schema(Schema), Version(V),
MemProfCallStackIndexes(MemProfCallStackIndexes) {}

Expand Down
18 changes: 10 additions & 8 deletions llvm/lib/ProfileData/InstrProfWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ static uint64_t writeMemProfRecords(
llvm::MapVector<GlobalValue::GUID, memprof::IndexedMemProfRecord>
&MemProfRecordData,
memprof::MemProfSchema *Schema, memprof::IndexedVersion Version,
llvm::DenseMap<memprof::CallStackId, uint32_t> *MemProfCallStackIndexes =
nullptr) {
llvm::DenseMap<memprof::CallStackId, memprof::LinearCallStackId>
*MemProfCallStackIndexes = nullptr) {
memprof::RecordWriterTrait RecordWriter(Schema, Version,
MemProfCallStackIndexes);
OnDiskChainedHashTableGenerator<memprof::RecordWriterTrait>
Expand Down Expand Up @@ -536,18 +536,20 @@ static uint64_t writeMemProfCallStacks(
return CallStackTableGenerator.Emit(OS.OS);
}

static llvm::DenseMap<memprof::CallStackId, uint32_t>
static llvm::DenseMap<memprof::CallStackId, memprof::LinearCallStackId>
writeMemProfCallStackArray(
ProfOStream &OS,
llvm::MapVector<memprof::CallStackId, llvm::SmallVector<memprof::FrameId>>
&MemProfCallStackData,
llvm::DenseMap<memprof::FrameId, uint32_t> &MemProfFrameIndexes) {
llvm::DenseMap<memprof::CallStackId, uint32_t> MemProfCallStackIndexes;
llvm::DenseMap<memprof::CallStackId, memprof::LinearCallStackId>
MemProfCallStackIndexes;

MemProfCallStackIndexes.reserve(MemProfCallStackData.size());
uint64_t CallStackBase = OS.tell();
for (const auto &[CSId, CallStack] : MemProfCallStackData) {
uint64_t CallStackIndex = (OS.tell() - CallStackBase) / sizeof(uint32_t);
memprof::LinearCallStackId CallStackIndex =
(OS.tell() - CallStackBase) / sizeof(memprof::LinearCallStackId);
MemProfCallStackIndexes.insert({CSId, CallStackIndex});
const llvm::SmallVector<memprof::FrameId> CS = CallStack;
OS.write32(CS.size());
Expand Down Expand Up @@ -712,9 +714,9 @@ static Error writeMemProfV3(ProfOStream &OS,
writeMemProfFrameArray(OS, MemProfData.FrameData);

uint64_t CallStackPayloadOffset = OS.tell();
llvm::DenseMap<memprof::CallStackId, uint32_t> MemProfCallStackIndexes =
writeMemProfCallStackArray(OS, MemProfData.CallStackData,
MemProfFrameIndexes);
llvm::DenseMap<memprof::CallStackId, memprof::LinearCallStackId>
MemProfCallStackIndexes = writeMemProfCallStackArray(
OS, MemProfData.CallStackData, MemProfFrameIndexes);

uint64_t RecordPayloadOffset = OS.tell();
uint64_t RecordTableOffset =
Expand Down
17 changes: 9 additions & 8 deletions llvm/lib/ProfileData/MemProf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,32 +169,32 @@ static void serializeV2(const IndexedMemProfRecord &Record,
LE.write<CallStackId>(CSId);
}

static void
serializeV3(const IndexedMemProfRecord &Record, const MemProfSchema &Schema,
raw_ostream &OS,
llvm::DenseMap<CallStackId, uint32_t> &MemProfCallStackIndexes) {
static void serializeV3(
const IndexedMemProfRecord &Record, const MemProfSchema &Schema,
raw_ostream &OS,
llvm::DenseMap<CallStackId, LinearCallStackId> &MemProfCallStackIndexes) {
using namespace support;

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

LE.write<uint64_t>(Record.AllocSites.size());
for (const IndexedAllocationInfo &N : Record.AllocSites) {
assert(MemProfCallStackIndexes.contains(N.CSId));
LE.write<uint32_t>(MemProfCallStackIndexes[N.CSId]);
LE.write<LinearCallStackId>(MemProfCallStackIndexes[N.CSId]);
N.Info.serialize(Schema, OS);
}

// Related contexts.
LE.write<uint64_t>(Record.CallSiteIds.size());
for (const auto &CSId : Record.CallSiteIds) {
assert(MemProfCallStackIndexes.contains(CSId));
LE.write<uint32_t>(MemProfCallStackIndexes[CSId]);
LE.write<LinearCallStackId>(MemProfCallStackIndexes[CSId]);
}
}

void IndexedMemProfRecord::serialize(
const MemProfSchema &Schema, raw_ostream &OS, IndexedVersion Version,
llvm::DenseMap<CallStackId, uint32_t> *MemProfCallStackIndexes) {
llvm::DenseMap<CallStackId, LinearCallStackId> *MemProfCallStackIndexes) {
switch (Version) {
case Version0:
case Version1:
Expand Down Expand Up @@ -297,7 +297,8 @@ static IndexedMemProfRecord deserializeV3(const MemProfSchema &Schema,
Record.AllocSites.reserve(NumNodes);
for (uint64_t I = 0; I < NumNodes; I++) {
IndexedAllocationInfo Node;
Node.CSId = endian::readNext<uint32_t, llvm::endianness::little>(Ptr);
Node.CSId =
endian::readNext<LinearCallStackId, llvm::endianness::little>(Ptr);
Node.Info.deserialize(Schema, Ptr);
Ptr += PortableMemInfoBlock::serializedSize(Schema);
Record.AllocSites.push_back(Node);
Expand Down
Loading