[llvm] [nfc][InstrFDO]Encapsulate header writes in a class member function (PR #90142)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Thu May 16 19:07:10 PDT 2024


================
@@ -552,6 +552,41 @@ static Error writeMemProf(
               memprof::MaximumSupportedVersion));
 }
 
+size_t InstrProfWriter::writeHeader(IndexedInstrProf::Header &Header,
+                                    const bool WritePrevVersion,
+                                    ProfOStream &OS,
+                                    size_t &BackPatchStartOffset) {
+  // Records the offset before writing any fields.
+  const uint64_t StartOffset = OS.tell();
+  // Only write out the first four fields. We need to remember the offset of the
+  // remaining fields to allow back patching later.
+  for (int I = 0; I < 4; I++)
+    OS.write(reinterpret_cast<uint64_t *>(&Header)[I]);
+
+  BackPatchStartOffset = OS.tell();
+
+  // Reserve the space for HashOffset field.
----------------
kazutakahirata wrote:

nit: Could we shorten comments?

```
// Reserve space for offsets to be patched later.
OS.write(0);  // MemProf
OS.write(0);  // BinaryIdOffset
OS.write(0);  // Temporal profile
 if (!WritePrevVersion)
  OS.write(0);  // VTable names
```

This way, the code looks like a table and avoids repetitive comments.

https://github.com/llvm/llvm-project/pull/90142


More information about the llvm-commits mailing list