[llvm] [ProfileData] Use default member initializations (NFC) (PR #93120)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed May 22 18:06:08 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/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.
>From ff719a63397150f32a2f1ac8fe14ce9ccd45fced Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 22 May 2024 17:26:56 -0700
Subject: [PATCH] [ProfileData] Use default member initializations (NFC)
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.
---
llvm/include/llvm/ProfileData/InstrProf.h | 18 +++++++++---------
llvm/lib/ProfileData/InstrProfWriter.cpp | 9 ---------
2 files changed, 9 insertions(+), 18 deletions(-)
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