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

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri May 17 13:40:13 PDT 2024


================
@@ -552,6 +552,29 @@ static Error writeMemProf(
               memprof::MaximumSupportedVersion));
 }
 
+uint64_t InstrProfWriter::writeHeader(const IndexedInstrProf::Header &Header,
+                                      const bool WritePrevVersion,
+                                      ProfOStream &OS) {
+  // 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<const uint64_t *>(&Header)[I]);
+
+  auto BackPatchStartOffset = OS.tell();
----------------
kazutakahirata wrote:

Consider moving the second sentence later.

```suggestion
  // Only write out the first four fields.
  for (int I = 0; I < 4; I++)
    OS.write(reinterpret_cast<const uint64_t *>(&Header)[I]);

  // Remember the offset of the remaining fields to allow back patching later.
  auto BackPatchStartOffset = OS.tell();
```

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


More information about the llvm-commits mailing list