diff options
author | Mingming Liu <mingmingl@google.com> | 2024-05-29 10:50:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-29 10:50:44 -0700 |
commit | c54657887b2cd88f0745c151fec0b15a8a7d1e44 (patch) | |
tree | acdcdc1dea2c1cb22865c7d0dbc82ab89b73624f /llvm/lib/ProfileData/InstrProfWriter.cpp | |
parent | 9595eb10ae9a5661a596dff19bf39365140548e3 (diff) | |
download | llvm-c54657887b2cd88f0745c151fec0b15a8a7d1e44.zip llvm-c54657887b2cd88f0745c151fec0b15a8a7d1e44.tar.gz llvm-c54657887b2cd88f0745c151fec0b15a8a7d1e44.tar.bz2 |
[nfc][InstrProfWriter]Store header fields in a vector and back patch once (#93594)
This is a split of https://github.com/llvm/llvm-project/pull/93346 as
discussed.
Diffstat (limited to 'llvm/lib/ProfileData/InstrProfWriter.cpp')
-rw-r--r-- | llvm/lib/ProfileData/InstrProfWriter.cpp | 62 |
1 files changed, 16 insertions, 46 deletions
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp index b16714a..e732882 100644 --- a/llvm/lib/ProfileData/InstrProfWriter.cpp +++ b/llvm/lib/ProfileData/InstrProfWriter.cpp @@ -893,52 +893,22 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) { } InfoObj->CSSummaryBuilder = nullptr; - const size_t MemProfOffset = BackPatchStartOffset + sizeof(uint64_t); - const size_t BinaryIdOffset = MemProfOffset + sizeof(uint64_t); - const size_t TemporalProfTracesOffset = BinaryIdOffset + sizeof(uint64_t); - const size_t VTableNamesOffset = TemporalProfTracesOffset + sizeof(uint64_t); - if (!WritePrevVersion) { - // Now do the final patch: - PatchItem PatchItems[] = { - // Patch the Header.HashOffset field. - {BackPatchStartOffset, &HashTableStart, 1}, - // Patch the Header.MemProfOffset (=0 for profiles without MemProf - // data). - {MemProfOffset, &MemProfSectionStart, 1}, - // Patch the Header.BinaryIdSectionOffset. - {BinaryIdOffset, &BinaryIdSectionStart, 1}, - // Patch the Header.TemporalProfTracesOffset (=0 for profiles without - // traces). - {TemporalProfTracesOffset, &TemporalProfTracesSectionStart, 1}, - {VTableNamesOffset, &VTableNamesSectionStart, 1}, - // Patch the summary data. - {SummaryOffset, reinterpret_cast<uint64_t *>(TheSummary.get()), - (int)(SummarySize / sizeof(uint64_t))}, - {CSSummaryOffset, reinterpret_cast<uint64_t *>(TheCSSummary.get()), - (int)CSSummarySize}}; - - OS.patch(PatchItems); - } else { - // Now do the final patch: - PatchItem PatchItems[] = { - // Patch the Header.HashOffset field. - {BackPatchStartOffset, &HashTableStart, 1}, - // Patch the Header.MemProfOffset (=0 for profiles without MemProf - // data). - {MemProfOffset, &MemProfSectionStart, 1}, - // Patch the Header.BinaryIdSectionOffset. - {BinaryIdOffset, &BinaryIdSectionStart, 1}, - // Patch the Header.TemporalProfTracesOffset (=0 for profiles without - // traces). - {TemporalProfTracesOffset, &TemporalProfTracesSectionStart, 1}, - // Patch the summary data. - {SummaryOffset, reinterpret_cast<uint64_t *>(TheSummary.get()), - (int)(SummarySize / sizeof(uint64_t))}, - {CSSummaryOffset, reinterpret_cast<uint64_t *>(TheCSSummary.get()), - (int)CSSummarySize}}; - - OS.patch(PatchItems); - } + SmallVector<uint64_t, 8> HeaderOffsets = {HashTableStart, MemProfSectionStart, + BinaryIdSectionStart, + TemporalProfTracesSectionStart}; + if (!WritePrevVersion) + HeaderOffsets.push_back(VTableNamesSectionStart); + + PatchItem PatchItems[] = { + // Patch the Header fields + {BackPatchStartOffset, HeaderOffsets.data(), (int)HeaderOffsets.size()}, + // Patch the summary data. + {SummaryOffset, reinterpret_cast<uint64_t *>(TheSummary.get()), + (int)(SummarySize / sizeof(uint64_t))}, + {CSSummaryOffset, reinterpret_cast<uint64_t *>(TheCSSummary.get()), + (int)CSSummarySize}}; + + OS.patch(PatchItems); for (const auto &I : FunctionData) for (const auto &F : I.getValue()) |