Skip to content

Commit bfa937a

Browse files
[ProfileData] Add const to a few places (NFC) (#94803)
1 parent 7520d0c commit bfa937a

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

llvm/include/llvm/ProfileData/MemProf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ struct IndexedMemProfRecord {
440440
void serialize(const MemProfSchema &Schema, raw_ostream &OS,
441441
IndexedVersion Version,
442442
llvm::DenseMap<memprof::CallStackId, LinearCallStackId>
443-
*MemProfCallStackIndexes = nullptr);
443+
*MemProfCallStackIndexes = nullptr) const;
444444

445445
// Deserializes memprof records from the Buffer.
446446
static IndexedMemProfRecord deserialize(const MemProfSchema &Schema,

llvm/lib/ProfileData/InstrProf.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ std::string getPGOFuncName(StringRef Name, GlobalValue::LinkageTypes Linkage,
282282
static StringRef stripDirPrefix(StringRef PathNameStr, uint32_t NumPrefix) {
283283
uint32_t Count = NumPrefix;
284284
uint32_t Pos = 0, LastPos = 0;
285-
for (auto & CI : PathNameStr) {
285+
for (const auto &CI : PathNameStr) {
286286
++Pos;
287287
if (llvm::sys::path::is_separator(CI)) {
288288
LastPos = Pos;
@@ -1299,7 +1299,7 @@ void annotateValueSite(Module &M, Instruction &Inst,
12991299

13001300
// Value Profile Data
13011301
uint32_t MDCount = MaxMDCount;
1302-
for (auto &VD : VDs) {
1302+
for (const auto &VD : VDs) {
13031303
Vals.push_back(MDHelper.createConstant(
13041304
ConstantInt::get(Type::getInt64Ty(Ctx), VD.Value)));
13051305
Vals.push_back(MDHelper.createConstant(

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ProfOStream {
5555
ProfOStream(raw_string_ostream &STR)
5656
: IsFDOStream(false), OS(STR), LE(STR, llvm::endianness::little) {}
5757

58-
uint64_t tell() { return OS.tell(); }
58+
[[nodiscard]] uint64_t tell() const { return OS.tell(); }
5959
void write(uint64_t V) { LE.write<uint64_t>(V); }
6060
void write32(uint32_t V) { LE.write<uint32_t>(V); }
6161
void writeByte(uint8_t V) { LE.write<uint8_t>(V); }
@@ -894,7 +894,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
894894
BinaryIds.erase(std::unique(BinaryIds.begin(), BinaryIds.end()),
895895
BinaryIds.end());
896896

897-
for (auto BI : BinaryIds) {
897+
for (const auto &BI : BinaryIds) {
898898
// Increment by binary id length data type size.
899899
BinaryIdsSectionSize += sizeof(uint64_t);
900900
// Increment by binary id data length, aligned to 8 bytes.
@@ -903,7 +903,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
903903
// Write binary ids section size.
904904
OS.write(BinaryIdsSectionSize);
905905

906-
for (auto BI : BinaryIds) {
906+
for (const auto &BI : BinaryIds) {
907907
uint64_t BILen = BI.size();
908908
// Write binary id length.
909909
OS.write(BILen);

llvm/lib/ProfileData/MemProf.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ static void serializeV3(
194194

195195
void IndexedMemProfRecord::serialize(
196196
const MemProfSchema &Schema, raw_ostream &OS, IndexedVersion Version,
197-
llvm::DenseMap<CallStackId, LinearCallStackId> *MemProfCallStackIndexes) {
197+
llvm::DenseMap<CallStackId, LinearCallStackId> *MemProfCallStackIndexes)
198+
const {
198199
switch (Version) {
199200
case Version0:
200201
case Version1:

llvm/lib/ProfileData/MemProfReader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Error checkBuffer(const MemoryBuffer &Buffer) {
6767
uint64_t TotalSize = 0;
6868
const char *Next = Buffer.getBufferStart();
6969
while (Next < Buffer.getBufferEnd()) {
70-
auto *H = reinterpret_cast<const Header *>(Next);
70+
const auto *H = reinterpret_cast<const Header *>(Next);
7171
if (H->Version != MEMPROF_RAW_VERSION) {
7272
return make_error<InstrProfError>(instrprof_error::unsupported_version);
7373
}
@@ -597,7 +597,7 @@ RawMemProfReader::peekBuildIds(MemoryBuffer *DataBuffer) {
597597
llvm::SmallSet<std::string, 10>>
598598
BuildIds;
599599
while (Next < DataBuffer->getBufferEnd()) {
600-
auto *Header = reinterpret_cast<const memprof::Header *>(Next);
600+
const auto *Header = reinterpret_cast<const memprof::Header *>(Next);
601601

602602
const llvm::SmallVector<SegmentEntry> Entries =
603603
readSegmentEntries(Next + Header->SegmentOffset);
@@ -615,7 +615,7 @@ Error RawMemProfReader::readRawProfile(
615615
const char *Next = DataBuffer->getBufferStart();
616616

617617
while (Next < DataBuffer->getBufferEnd()) {
618-
auto *Header = reinterpret_cast<const memprof::Header *>(Next);
618+
const auto *Header = reinterpret_cast<const memprof::Header *>(Next);
619619

620620
// Read in the segment information, check whether its the same across all
621621
// profiles in this binary file.

0 commit comments

Comments
 (0)