-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:memprof_v3_linear_callstack_id
May 31, 2024
Merged
[memprof] Replace uint32_t with LinearCallStackId where appropriate (NFC) #94023
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:memprof_v3_linear_callstack_id
May 31, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…NFC) 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.
@llvm/pr-subscribers-pgo Author: Kazu Hirata (kazutakahirata) ChangesThis patch replaces uint32_t with LinearCallStackId where appropriate. Full diff: https://github.com/llvm/llvm-project/pull/94023.diff 3 Files Affected:
diff --git a/llvm/include/llvm/ProfileData/MemProf.h b/llvm/include/llvm/ProfileData/MemProf.h
index b19c1b9a051d1..2a7c853cade66 100644
--- a/llvm/include/llvm/ProfileData/MemProf.h
+++ b/llvm/include/llvm/ProfileData/MemProf.h
@@ -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) {}
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 059617a2645c4..9b12922427779 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -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>
@@ -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());
@@ -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 =
diff --git a/llvm/lib/ProfileData/MemProf.cpp b/llvm/lib/ProfileData/MemProf.cpp
index 1c2d760cfeaf2..1d9860e0ea7e8 100644
--- a/llvm/lib/ProfileData/MemProf.cpp
+++ b/llvm/lib/ProfileData/MemProf.cpp
@@ -169,10 +169,10 @@ 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);
@@ -180,7 +180,7 @@ serializeV3(const IndexedMemProfRecord &Record, const MemProfSchema &Schema,
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);
}
@@ -188,13 +188,13 @@ serializeV3(const IndexedMemProfRecord &Record, const MemProfSchema &Schema,
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:
@@ -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);
|
teresajohnson
approved these changes
May 31, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.