Skip to content

Commit beac910

Browse files
[nfc][InstrProfWriter]Wrap vtable writes in a method. (#93081)
- This way `InstrProfWriter::writeImpl` itself is simpler.
1 parent 2375921 commit beac910

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

llvm/include/llvm/ProfileData/InstrProfWriter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ class InstrProfWriter {
218218
// back patching.
219219
uint64_t writeHeader(const IndexedInstrProf::Header &header,
220220
const bool WritePrevVersion, ProfOStream &OS);
221+
222+
// Writes compressed vtable names to profiles.
223+
Error writeVTableNames(ProfOStream &OS);
221224
};
222225

223226
} // end namespace llvm

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,37 @@ uint64_t InstrProfWriter::writeHeader(const IndexedInstrProf::Header &Header,
660660
return BackPatchStartOffset;
661661
}
662662

663+
Error InstrProfWriter::writeVTableNames(ProfOStream &OS) {
664+
std::vector<std::string> VTableNameStrs;
665+
for (StringRef VTableName : VTableNames.keys())
666+
VTableNameStrs.push_back(VTableName.str());
667+
668+
std::string CompressedVTableNames;
669+
if (!VTableNameStrs.empty())
670+
if (Error E = collectGlobalObjectNameStrings(
671+
VTableNameStrs, compression::zlib::isAvailable(),
672+
CompressedVTableNames))
673+
return E;
674+
675+
const uint64_t CompressedStringLen = CompressedVTableNames.length();
676+
677+
// Record the length of compressed string.
678+
OS.write(CompressedStringLen);
679+
680+
// Write the chars in compressed strings.
681+
for (auto &c : CompressedVTableNames)
682+
OS.writeByte(static_cast<uint8_t>(c));
683+
684+
// Pad up to a multiple of 8.
685+
// InstrProfReader could read bytes according to 'CompressedStringLen'.
686+
const uint64_t PaddedLength = alignTo(CompressedStringLen, 8);
687+
688+
for (uint64_t K = CompressedStringLen; K < PaddedLength; K++)
689+
OS.writeByte(0);
690+
691+
return Error::success();
692+
}
693+
663694
Error InstrProfWriter::writeImpl(ProfOStream &OS) {
664695
using namespace IndexedInstrProf;
665696
using namespace support;
@@ -775,34 +806,9 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
775806

776807
uint64_t VTableNamesSectionStart = OS.tell();
777808

778-
if (!WritePrevVersion) {
779-
std::vector<std::string> VTableNameStrs;
780-
for (StringRef VTableName : VTableNames.keys())
781-
VTableNameStrs.push_back(VTableName.str());
782-
783-
std::string CompressedVTableNames;
784-
if (!VTableNameStrs.empty())
785-
if (Error E = collectGlobalObjectNameStrings(
786-
VTableNameStrs, compression::zlib::isAvailable(),
787-
CompressedVTableNames))
788-
return E;
789-
790-
const uint64_t CompressedStringLen = CompressedVTableNames.length();
791-
792-
// Record the length of compressed string.
793-
OS.write(CompressedStringLen);
794-
795-
// Write the chars in compressed strings.
796-
for (auto &c : CompressedVTableNames)
797-
OS.writeByte(static_cast<uint8_t>(c));
798-
799-
// Pad up to a multiple of 8.
800-
// InstrProfReader could read bytes according to 'CompressedStringLen'.
801-
const uint64_t PaddedLength = alignTo(CompressedStringLen, 8);
802-
803-
for (uint64_t K = CompressedStringLen; K < PaddedLength; K++)
804-
OS.writeByte(0);
805-
}
809+
if (!WritePrevVersion)
810+
if (Error E = writeVTableNames(OS))
811+
return E;
806812

807813
uint64_t TemporalProfTracesSectionStart = 0;
808814
if (static_cast<bool>(ProfileKind & InstrProfKind::TemporalProfile)) {

0 commit comments

Comments
 (0)