Skip to content
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

Preserve the original name when renaming declarations in the inlining pass. #4683

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 9 additions & 9 deletions frontends/p4/inlining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,26 @@ class Substitutions : public SubstituteParameters {
}
const IR::Node *postorder(IR::P4Table *table) override {
auto orig = getOriginal<IR::IDeclaration>();
cstring newName = renameMap->getName(orig);
cstring extName = renameMap->getExtName(orig);
auto newName = renameMap->getName(orig);
auto extName = renameMap->getExtName(orig);
LOG3("Renaming " << dbp(orig) << " to " << newName << " (" << extName << ")");
auto annos = setNameAnnotation(extName, table->annotations);
auto result = new IR::P4Table(table->srcInfo, newName, annos, table->properties);
return result;
}
const IR::Node *postorder(IR::P4ValueSet *set) override {
auto orig = getOriginal<IR::IDeclaration>();
cstring newName = renameMap->getName(orig);
cstring extName = renameMap->getExtName(orig);
auto newName = renameMap->getName(orig);
auto extName = renameMap->getExtName(orig);
LOG3("Renaming " << dbp(orig) << " to " << newName << "(" << extName << ")");
auto annos = setNameAnnotation(extName, set->annotations);
auto result = new IR::P4ValueSet(set->srcInfo, newName, annos, set->elementType, set->size);
return result;
}
const IR::Node *postorder(IR::P4Action *action) override {
auto orig = getOriginal<IR::IDeclaration>();
cstring newName = renameMap->getName(orig);
cstring extName = renameMap->getExtName(orig);
auto newName = renameMap->getName(orig);
auto extName = renameMap->getExtName(orig);
LOG3("Renaming " << dbp(orig) << " to " << newName << "(" << extName << ")");
auto annos = setNameAnnotation(extName, action->annotations);
auto result =
Expand All @@ -273,8 +273,8 @@ class Substitutions : public SubstituteParameters {
}
const IR::Node *postorder(IR::Declaration_Instance *instance) override {
auto orig = getOriginal<IR::IDeclaration>();
cstring newName = renameMap->getName(orig);
cstring extName = renameMap->getExtName(orig);
auto newName = renameMap->getName(orig);
auto extName = renameMap->getExtName(orig);
LOG3("Renaming " << dbp(orig) << " to " << newName << "(" << extName << ")");
auto annos = setNameAnnotation(extName, instance->annotations);
instance->name = newName;
Expand Down Expand Up @@ -303,7 +303,7 @@ class Substitutions : public SubstituteParameters {
return value;
}

cstring newName;
IR::ID newName;
if (renameMap->isRenamed(decl))
newName = renameMap->getName(decl);
else
Expand Down
12 changes: 6 additions & 6 deletions frontends/p4/inlining.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,25 @@ struct CallInfo : public IHasDbPrint {
};

class SymRenameMap {
std::map<const IR::IDeclaration *, cstring> internalName;
std::map<const IR::IDeclaration *, cstring> externalName;
std::map<const IR::IDeclaration *, IR::ID> internalName;
std::map<const IR::IDeclaration *, IR::ID> externalName;

public:
void setNewName(const IR::IDeclaration *decl, cstring name, cstring extName) {
CHECK_NULL(decl);
BUG_CHECK(!name.isNullOrEmpty() && !extName.isNullOrEmpty(), "Empty name");
LOG3("setNewName " << dbp(decl) << " to " << name);
if (internalName.find(decl) != internalName.end()) BUG("%1%: already renamed", decl);
internalName.emplace(decl, name);
externalName.emplace(decl, extName);
internalName.emplace(decl, IR::ID(name, decl->toString()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we shuld rather do something like decl->name.originalName here? Using toString might be fragile.

externalName.emplace(decl, IR::ID(extName, decl->externalName()));
}
cstring getName(const IR::IDeclaration *decl) const {
IR::ID getName(const IR::IDeclaration *decl) const {
CHECK_NULL(decl);
BUG_CHECK(internalName.find(decl) != internalName.end(), "%1%: no new name", decl);
auto result = ::P4::get(internalName, decl);
return result;
}
cstring getExtName(const IR::IDeclaration *decl) const {
IR::ID getExtName(const IR::IDeclaration *decl) const {
CHECK_NULL(decl);
BUG_CHECK(externalName.find(decl) != externalName.end(), "%1%: no external name", decl);
auto result = ::P4::get(externalName, decl);
Expand Down
Loading