[llvm] [memprof] Use linear IDs for Frames and call stacks (PR #93740)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu May 30 14:25:38 PDT 2024
================
@@ -485,6 +489,42 @@ static uint64_t writeMemProfFrames(
return FrameTableGenerator.Emit(OS.OS);
}
+// Serialize MemProfFrameData. Return the mapping from FrameIds to their
+// indexes within the frame array.
+static llvm::DenseMap<memprof::FrameId, uint32_t> writeMemProfFrameArray(
+ ProfOStream &OS,
+ llvm::MapVector<memprof::FrameId, memprof::Frame> &MemProfFrameData) {
+ // Mappings from FrameIds to array indexes.
+ llvm::DenseMap<memprof::FrameId, uint32_t> MemProfFrameIndexes;
+
+ // Sort the FrameIDs for stability.
+ std::vector<memprof::FrameId> FrameIdOrder;
+ FrameIdOrder.reserve(MemProfFrameData.size());
+ for (const auto &KV : MemProfFrameData)
+ FrameIdOrder.push_back(KV.first);
+ assert(MemProfFrameData.size() == FrameIdOrder.size());
+ llvm::sort(FrameIdOrder);
+
+ // Serialize all frames while creating mappings from linear IDs to FrameIds.
+ uint64_t Index = 0;
+ MemProfFrameIndexes.reserve(FrameIdOrder.size());
+ for (memprof::FrameId Id : FrameIdOrder) {
+ auto Iter = MemProfFrameData.find(Id);
----------------
kazutakahirata wrote:
Good point! Fixed in the latest iteration.
https://github.com/llvm/llvm-project/pull/93740
More information about the llvm-commits
mailing list