[llvm] 521238d - [ProfileData] Refactor VTableNamePtr and CompressedVTableNamesLen (NFC) (#94859)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 9 15:33:03 PDT 2024
Author: Kazu Hirata
Date: 2024-06-09T15:33:00-07:00
New Revision: 521238d19b53f4860aa07198ed84e9816d69d7a0
URL: https://github.com/llvm/llvm-project/commit/521238d19b53f4860aa07198ed84e9816d69d7a0
DIFF: https://github.com/llvm/llvm-project/commit/521238d19b53f4860aa07198ed84e9816d69d7a0.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/ProfileData/InstrProfReader.h
llvm/lib/ProfileData/InstrProfReader.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/InstrProfReader.h b/llvm/include/llvm/ProfileData/InstrProfReader.h
index f89e6eab9fdaf..ae0fd257bb05f 100644
--- a/llvm/include/llvm/ProfileData/InstrProfReader.h
+++ b/llvm/include/llvm/ProfileData/InstrProfReader.h
@@ -693,15 +693,10 @@ class IndexedInstrProfReader : public InstrProfReader {
/// Context sensitive profile summary data.
std::unique_ptr<ProfileSummary> CS_Summary;
IndexedMemProfReader MemProfReader;
- /// VTableNamePtr points to the beginning of compressed vtable names.
- /// When a symtab is constructed from profiles by llvm-profdata, the list of
- /// names could be decompressed based on `VTableNamePtr` and
- /// `CompressedVTableNamesLen`.
+ /// The compressed vtable names, to be used for symtab construction.
/// A compiler that reads indexed profiles could construct symtab from module
/// IR so it doesn't need the decompressed names.
- const char *VTableNamePtr = nullptr;
- /// The length of compressed vtable names.
- uint64_t CompressedVTableNamesLen = 0;
+ StringRef VTableName;
/// Total size of binary ids.
uint64_t BinaryIdsSize{0};
/// Start address of binary id length and data pairs.
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp
index dad42007c1aec..ca2fe4af94528 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -1397,14 +1397,16 @@ Error IndexedInstrProfReader::readHeader() {
if (Header->getIndexedProfileVersion() >= 12) {
const unsigned char *Ptr = Start + Header->VTableNamesOffset;
- CompressedVTableNamesLen =
+ uint64_t CompressedVTableNamesLen =
support::endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
// Writer first writes the length of compressed string, and then the actual
// content.
- VTableNamePtr = (const char *)Ptr;
+ const char *VTableNamePtr = (const char *)Ptr;
if (VTableNamePtr > (const char *)DataBuffer->getBufferEnd())
return make_error<InstrProfError>(instrprof_error::truncated);
+
+ VTableName = StringRef(VTableNamePtr, CompressedVTableNamesLen);
}
if (Header->getIndexedProfileVersion() >= 10 &&
@@ -1460,8 +1462,7 @@ InstrProfSymtab &IndexedInstrProfReader::getSymtab() {
auto NewSymtab = std::make_unique<InstrProfSymtab>();
- if (Error E = NewSymtab->initVTableNamesFromCompressedStrings(
- StringRef(VTableNamePtr, CompressedVTableNamesLen))) {
+ if (Error E = NewSymtab->initVTableNamesFromCompressedStrings(VTableName)) {
auto [ErrCode, Msg] = InstrProfError::take(std::move(E));
consumeError(error(ErrCode, Msg));
}
More information about the llvm-commits
mailing list