Skip to content

Commit 521238d

Browse files
[ProfileData] Refactor VTableNamePtr and CompressedVTableNamesLen (NFC) (#94859)
VTableNamePtr and CompressedVTableNamesLen are always used together to create a StringRef in getSymtab. We can create the StringRef ahead of time in readHeader. This way, IndexedInstrProfReader becomes a tiny bit simpler with fewer member variables. Also, StringRef default-constructs itself with its Data and Length set to nullptr and 0, respectively, which is exactly what we need.
1 parent dbe63e3 commit 521238d

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

llvm/include/llvm/ProfileData/InstrProfReader.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -693,15 +693,10 @@ class IndexedInstrProfReader : public InstrProfReader {
693693
/// Context sensitive profile summary data.
694694
std::unique_ptr<ProfileSummary> CS_Summary;
695695
IndexedMemProfReader MemProfReader;
696-
/// VTableNamePtr points to the beginning of compressed vtable names.
697-
/// When a symtab is constructed from profiles by llvm-profdata, the list of
698-
/// names could be decompressed based on `VTableNamePtr` and
699-
/// `CompressedVTableNamesLen`.
696+
/// The compressed vtable names, to be used for symtab construction.
700697
/// A compiler that reads indexed profiles could construct symtab from module
701698
/// IR so it doesn't need the decompressed names.
702-
const char *VTableNamePtr = nullptr;
703-
/// The length of compressed vtable names.
704-
uint64_t CompressedVTableNamesLen = 0;
699+
StringRef VTableName;
705700
/// Total size of binary ids.
706701
uint64_t BinaryIdsSize{0};
707702
/// Start address of binary id length and data pairs.

llvm/lib/ProfileData/InstrProfReader.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,14 +1397,16 @@ Error IndexedInstrProfReader::readHeader() {
13971397
if (Header->getIndexedProfileVersion() >= 12) {
13981398
const unsigned char *Ptr = Start + Header->VTableNamesOffset;
13991399

1400-
CompressedVTableNamesLen =
1400+
uint64_t CompressedVTableNamesLen =
14011401
support::endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
14021402

14031403
// Writer first writes the length of compressed string, and then the actual
14041404
// content.
1405-
VTableNamePtr = (const char *)Ptr;
1405+
const char *VTableNamePtr = (const char *)Ptr;
14061406
if (VTableNamePtr > (const char *)DataBuffer->getBufferEnd())
14071407
return make_error<InstrProfError>(instrprof_error::truncated);
1408+
1409+
VTableName = StringRef(VTableNamePtr, CompressedVTableNamesLen);
14081410
}
14091411

14101412
if (Header->getIndexedProfileVersion() >= 10 &&
@@ -1460,8 +1462,7 @@ InstrProfSymtab &IndexedInstrProfReader::getSymtab() {
14601462

14611463
auto NewSymtab = std::make_unique<InstrProfSymtab>();
14621464

1463-
if (Error E = NewSymtab->initVTableNamesFromCompressedStrings(
1464-
StringRef(VTableNamePtr, CompressedVTableNamesLen))) {
1465+
if (Error E = NewSymtab->initVTableNamesFromCompressedStrings(VTableName)) {
14651466
auto [ErrCode, Msg] = InstrProfError::take(std::move(E));
14661467
consumeError(error(ErrCode, Msg));
14671468
}

0 commit comments

Comments
 (0)