[llvm] 2375921 - [ProfileData] Use default member initializations (NFC) (#93120)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 22 20:39:00 PDT 2024
Author: Kazu Hirata
Date: 2024-05-22T20:38:57-07:00
New Revision: 2375921d6734016c9079727f798c5585653e858c
URL: https://github.com/llvm/llvm-project/commit/2375921d6734016c9079727f798c5585653e858c
DIFF: https://github.com/llvm/llvm-project/commit/2375921d6734016c9079727f798c5585653e858c.diff
LOG: [ProfileData] Use default member initializations (NFC) (#93120)
This patch uses default member initializations for all the fields in
Header. The intent is to prevent accidental uninitialized fields and
reduce the number of times we need to mention each member variable.
Added:
Modified:
llvm/include/llvm/ProfileData/InstrProf.h
llvm/lib/ProfileData/InstrProfWriter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h
index a57f9e1b7b4a2..2263376a40e70 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -1184,21 +1184,21 @@ inline uint64_t ComputeHash(StringRef K) { return ComputeHash(HashType, K); }
// data file in indexed-format. Please update llvm/docs/InstrProfileFormat.rst
// as appropriate when updating the indexed profile format.
struct Header {
- uint64_t Magic;
+ uint64_t Magic = IndexedInstrProf::Magic;
// The lower 32 bits specify the version of the indexed profile.
// The most significant 32 bits are reserved to specify the variant types of
// the profile.
- uint64_t Version;
- uint64_t Unused; // Becomes unused since version 4
- uint64_t HashType;
+ uint64_t Version = 0;
+ uint64_t Unused = 0; // Becomes unused since version 4
+ uint64_t HashType = static_cast<uint64_t>(IndexedInstrProf::HashType);
// This field records the offset of this hash table's metadata (i.e., the
// number of buckets and entries), which follows right after the payload of
// the entire hash table.
- uint64_t HashOffset;
- uint64_t MemProfOffset;
- uint64_t BinaryIdOffset;
- uint64_t TemporalProfTracesOffset;
- uint64_t VTableNamesOffset;
+ uint64_t HashOffset = 0;
+ uint64_t MemProfOffset = 0;
+ uint64_t BinaryIdOffset = 0;
+ uint64_t TemporalProfTracesOffset = 0;
+ uint64_t VTableNamesOffset = 0;
// New fields should only be added at the end to ensure that the size
// computation is correct. The methods below need to be updated to ensure that
// the new field is read correctly.
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 101992c38353d..86bd9fed902e5 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -682,7 +682,6 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
// Write the header.
IndexedInstrProf::Header Header;
- Header.Magic = IndexedInstrProf::Magic;
Header.Version = WritePrevVersion
? IndexedInstrProf::ProfVersion::Version11
: IndexedInstrProf::ProfVersion::CurrentVersion;
@@ -706,14 +705,6 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
if (static_cast<bool>(ProfileKind & InstrProfKind::TemporalProfile))
Header.Version |= VARIANT_MASK_TEMPORAL_PROF;
- Header.Unused = 0;
- Header.HashType = static_cast<uint64_t>(IndexedInstrProf::HashType);
- Header.HashOffset = 0;
- Header.MemProfOffset = 0;
- Header.BinaryIdOffset = 0;
- Header.TemporalProfTracesOffset = 0;
- Header.VTableNamesOffset = 0;
-
const uint64_t BackPatchStartOffset =
writeHeader(Header, WritePrevVersion, OS);
More information about the llvm-commits
mailing list