Skip to content

[ProfileData] Add const to a few places (NFC) #94803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/ProfileData/MemProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ struct IndexedMemProfRecord {
void serialize(const MemProfSchema &Schema, raw_ostream &OS,
IndexedVersion Version,
llvm::DenseMap<memprof::CallStackId, LinearCallStackId>
*MemProfCallStackIndexes = nullptr);
*MemProfCallStackIndexes = nullptr) const;

// Deserializes memprof records from the Buffer.
static IndexedMemProfRecord deserialize(const MemProfSchema &Schema,
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/ProfileData/InstrProf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ std::string getPGOFuncName(StringRef Name, GlobalValue::LinkageTypes Linkage,
static StringRef stripDirPrefix(StringRef PathNameStr, uint32_t NumPrefix) {
uint32_t Count = NumPrefix;
uint32_t Pos = 0, LastPos = 0;
for (auto & CI : PathNameStr) {
for (const auto &CI : PathNameStr) {
++Pos;
if (llvm::sys::path::is_separator(CI)) {
LastPos = Pos;
Expand Down Expand Up @@ -1299,7 +1299,7 @@ void annotateValueSite(Module &M, Instruction &Inst,

// Value Profile Data
uint32_t MDCount = MaxMDCount;
for (auto &VD : VDs) {
for (const auto &VD : VDs) {
Vals.push_back(MDHelper.createConstant(
ConstantInt::get(Type::getInt64Ty(Ctx), VD.Value)));
Vals.push_back(MDHelper.createConstant(
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/ProfileData/InstrProfWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ProfOStream {
ProfOStream(raw_string_ostream &STR)
: IsFDOStream(false), OS(STR), LE(STR, llvm::endianness::little) {}

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

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

for (auto BI : BinaryIds) {
for (const auto &BI : BinaryIds) {
uint64_t BILen = BI.size();
// Write binary id length.
OS.write(BILen);
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/ProfileData/MemProf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ static void serializeV3(

void IndexedMemProfRecord::serialize(
const MemProfSchema &Schema, raw_ostream &OS, IndexedVersion Version,
llvm::DenseMap<CallStackId, LinearCallStackId> *MemProfCallStackIndexes) {
llvm::DenseMap<CallStackId, LinearCallStackId> *MemProfCallStackIndexes)
const {
switch (Version) {
case Version0:
case Version1:
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/ProfileData/MemProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Error checkBuffer(const MemoryBuffer &Buffer) {
uint64_t TotalSize = 0;
const char *Next = Buffer.getBufferStart();
while (Next < Buffer.getBufferEnd()) {
auto *H = reinterpret_cast<const Header *>(Next);
const auto *H = reinterpret_cast<const Header *>(Next);
if (H->Version != MEMPROF_RAW_VERSION) {
return make_error<InstrProfError>(instrprof_error::unsupported_version);
}
Expand Down Expand Up @@ -597,7 +597,7 @@ RawMemProfReader::peekBuildIds(MemoryBuffer *DataBuffer) {
llvm::SmallSet<std::string, 10>>
BuildIds;
while (Next < DataBuffer->getBufferEnd()) {
auto *Header = reinterpret_cast<const memprof::Header *>(Next);
const auto *Header = reinterpret_cast<const memprof::Header *>(Next);

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

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

// Read in the segment information, check whether its the same across all
// profiles in this binary file.
Expand Down
Loading