[PATCH] D120093: [memprof] Fix frame deserialization on big endian systems.
Snehasish Kumar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 17 15:25:12 PST 2022
snehasish updated this revision to Diff 409804.
snehasish added a comment.
Add comments for each field.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D120093/new/
https://reviews.llvm.org/D120093
Files:
llvm/include/llvm/ProfileData/MemProf.h
llvm/lib/ProfileData/MemProf.cpp
Index: llvm/lib/ProfileData/MemProf.cpp
===================================================================
--- llvm/lib/ProfileData/MemProf.cpp
+++ llvm/lib/ProfileData/MemProf.cpp
@@ -15,7 +15,7 @@
for (const MemProfRecord &MR : Records) {
LE.write<uint64_t>(MR.CallStack.size());
for (const MemProfRecord::Frame &F : MR.CallStack) {
- F.write(OS);
+ F.serialize(OS);
}
MR.Info.serialize(Schema, OS);
}
@@ -33,8 +33,8 @@
const uint64_t NumFrames =
endian::readNext<uint64_t, little, unaligned>(Ptr);
for (uint64_t J = 0; J < NumFrames; J++) {
- const auto F = *reinterpret_cast<const MemProfRecord::Frame *>(Ptr);
- Ptr += sizeof(MemProfRecord::Frame);
+ const auto F = MemProfRecord::Frame::deserialize(Ptr);
+ Ptr += MemProfRecord::Frame::serializedSize();
MR.CallStack.push_back(F);
}
MR.Info.deserialize(Schema, Ptr);
Index: llvm/include/llvm/ProfileData/MemProf.h
===================================================================
--- llvm/include/llvm/ProfileData/MemProf.h
+++ llvm/include/llvm/ProfileData/MemProf.h
@@ -161,7 +161,7 @@
bool operator!=(const Frame &Other) const { return !operator==(Other); }
// Write the contents of the frame to the ostream \p OS.
- void write(raw_ostream & OS) const {
+ void serialize(raw_ostream & OS) const {
using namespace support;
endian::Writer LE(OS, little);
@@ -176,6 +176,22 @@
LE.write<uint32_t>(Column);
LE.write<bool>(IsInlineFrame);
}
+
+ // Read a frame from char data which has been serialized as little endian.
+ static Frame deserialize(const unsigned char *Ptr) {
+ using namespace support;
+ return Frame(
+ /*Function=*/endian::readNext<uint64_t, little, unaligned>(Ptr),
+ /*LineOffset=*/endian::readNext<uint32_t, little, unaligned>(Ptr),
+ /*Column=*/endian::readNext<uint32_t, little, unaligned>(Ptr),
+ /*IsInlineFrame*/ endian::readNext<bool, little, unaligned>(Ptr));
+ }
+
+ // Returns the size of the frame information.
+ static constexpr size_t serializedSize() {
+ return sizeof(Frame::Function) + sizeof(Frame::LineOffset) +
+ sizeof(Frame::Column) + sizeof(Frame::IsInlineFrame);
+ }
});
// The dynamic calling context for the allocation.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120093.409804.patch
Type: text/x-patch
Size: 2355 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220217/658ba574/attachment.bin>
More information about the llvm-commits
mailing list