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

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Fri May 17 11:51:52 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.
+  OS.write(0);
+
+  // Reserve space for the MemProf table field to be patched later if this
+  // profile contains memory profile information.
+  OS.write(0);
+
+  // Reserve space for the BinaryIdOffset field to be patched later if this
+  // profile contains binary ids.
+  OS.write(0);
+
+  // Reserve space for temporal profile traces for back patching later.
+  OS.write(0);
+
+  // Reserve space for vtable names for back patching later.
+  if (!WritePrevVersion)
+    OS.write(0);
+
+  // Returns the number of bytes written in the header section.
+  return OS.tell() - StartOffset;
----------------
minglotus-6 wrote:

done.

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


More information about the llvm-commits mailing list