Skip to content

[nfc][InstrProfWriter]Store header fields in a vector and back patch once #93594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 16 additions & 46 deletions llvm/lib/ProfileData/InstrProfWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,52 +841,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())
Expand Down
Loading