From d01998e8b9dc9bc4709e5dc6c621a24783fa535d Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Mon, 9 Sep 2024 15:42:43 -0700 Subject: [PATCH] Improve const-correctness Signed-off-by: Anton Korobeynikov --- frontends/p4/def_use.cpp | 9 ++++----- frontends/p4/def_use.h | 14 +++++++------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/frontends/p4/def_use.cpp b/frontends/p4/def_use.cpp index f5bbdab6fe..0c15b27450 100644 --- a/frontends/p4/def_use.cpp +++ b/frontends/p4/def_use.cpp @@ -396,7 +396,7 @@ void ComputeWriteSet::enterScope(const IR::ParameterList *parameters, if (parameters != nullptr) { for (auto p : parameters->parameters) { - StorageLocation *loc = allDefinitions->getOrAddStorage(p); + const StorageLocation *loc = allDefinitions->getOrAddStorage(p); if (loc == nullptr) continue; if (p->direction == IR::Direction::In || p->direction == IR::Direction::InOut || p->direction == IR::Direction::None) @@ -410,8 +410,7 @@ void ComputeWriteSet::enterScope(const IR::ParameterList *parameters, if (locals != nullptr) { for (auto d : *locals) { if (d->is()) { - StorageLocation *loc = allDefinitions->getOrAddStorage(d); - if (loc != nullptr) { + if (const StorageLocation *loc = allDefinitions->getOrAddStorage(d)) { defs->setDefinition(loc, uninit); defs->setDefinition(loc->getValidBits(), startPoints); defs->setDefinition(loc->getLastIndexField(), startPoints); @@ -434,7 +433,7 @@ void ComputeWriteSet::exitScope(const IR::ParameterList *parameters, currentDefinitions = currentDefinitions->cloneDefinitions(); if (parameters != nullptr) { for (auto p : parameters->parameters) { - StorageLocation *loc = allDefinitions->getStorage(p); + const StorageLocation *loc = allDefinitions->getStorage(p); if (loc != nullptr) { LOG5("Removing location " << loc); currentDefinitions->removeLocation(loc); @@ -444,7 +443,7 @@ void ComputeWriteSet::exitScope(const IR::ParameterList *parameters, if (locals != nullptr) { for (auto d : *locals) { if (d->is()) { - StorageLocation *loc = allDefinitions->getStorage(d); + const StorageLocation *loc = allDefinitions->getStorage(d); if (loc != nullptr) { LOG5("Removing location " << loc); currentDefinitions->removeLocation(loc); diff --git a/frontends/p4/def_use.h b/frontends/p4/def_use.h index f6fdd80383..2a7f50eec8 100644 --- a/frontends/p4/def_use.h +++ b/frontends/p4/def_use.h @@ -355,7 +355,7 @@ class LocationSet : public IHasDbPrint { /// Maps a declaration to its associated storage. class StorageMap : public IHasDbPrint { /// Storage location for each declaration. - hvec_map storage; + hvec_map storage; StorageFactory factory; public: @@ -366,19 +366,19 @@ class StorageMap : public IHasDbPrint { CHECK_NULL(refMap); CHECK_NULL(typeMap); } - StorageLocation *add(const IR::IDeclaration *decl) { + const StorageLocation *add(const IR::IDeclaration *decl) { CHECK_NULL(decl); auto type = typeMap->getType(decl->getNode(), true); auto loc = factory.create(type, decl->getName() + "/" + decl->externalName()); if (loc != nullptr) storage.emplace(decl, loc); return loc; } - StorageLocation *getOrAdd(const IR::IDeclaration *decl) { - auto s = getStorage(decl); + const StorageLocation *getOrAdd(const IR::IDeclaration *decl) { + const auto *s = getStorage(decl); if (s != nullptr) return s; return add(decl); } - StorageLocation *getStorage(const IR::IDeclaration *decl) const { + const StorageLocation *getStorage(const IR::IDeclaration *decl) const { CHECK_NULL(decl); auto result = ::P4::get(storage, decl); return result; @@ -580,11 +580,11 @@ class AllDefinitions : public IHasDbPrint { atPoint[point] = defs; } - StorageLocation *getStorage(const IR::IDeclaration *decl) const { + const StorageLocation *getStorage(const IR::IDeclaration *decl) const { return storageMap.getStorage(decl); } - StorageLocation *getOrAddStorage(const IR::IDeclaration *decl) { + const StorageLocation *getOrAddStorage(const IR::IDeclaration *decl) { return storageMap.getOrAdd(decl); }