Support unpacked structs (#3802)

This commit is contained in:
Aleksander Kiryk
2022-12-20 19:22:42 -05:00
committed by GitHub
parent c3b4bc85fa
commit c2b09e35f8
43 changed files with 541 additions and 95 deletions
+25 -5
View File
@@ -72,6 +72,7 @@ private:
std::vector<AstScope*> m_scopesp;
std::vector<AstCell*> m_cellsp;
std::vector<AstClass*> m_classesp;
std::vector<AstTypedef*> m_typedefsp;
AssignMap m_assignMap; // List of all simple assignments for each variable
const bool m_elimUserVars; // Allow removal of user's vars
@@ -234,6 +235,11 @@ private:
if (nodep->fromp()->dtypep()) nodep->fromp()->dtypep()->user1Inc(); // classref
checkAll(nodep);
}
void visit(AstStructSel* nodep) override {
iterateChildren(nodep);
if (nodep->fromp()->dtypep()) nodep->fromp()->dtypep()->user1Inc(); // structdtype
checkAll(nodep);
}
void visit(AstModport* nodep) override {
iterateChildren(nodep);
if (m_elimCells) {
@@ -253,11 +259,8 @@ private:
}
void visit(AstTypedef* nodep) override {
iterateChildren(nodep);
if (m_elimCells && !nodep->attrPublic()) {
VL_DO_DANGLING(pushDeletep(nodep->unlinkFrBack()), nodep);
return;
}
checkAll(nodep);
m_typedefsp.push_back(nodep);
// Don't let packages with only public variables disappear
// Normal modules may disappear, e.g. if they are parameterized then removed
if (nodep->attrPublic() && m_modp && VN_IS(m_modp, Package)) m_modp->user1Inc();
@@ -306,6 +309,22 @@ private:
}
// METHODS
void deadCheckTypedefs() {
for (AstTypedef* typedefp : m_typedefsp) {
if (shouldDeleteTypedef(typedefp)) {
VL_DO_DANGLING(pushDeletep(typedefp->unlinkFrBack()), typedefp);
continue;
}
checkAll(typedefp);
}
}
bool shouldDeleteTypedef(AstTypedef* typedefp) {
if (auto* structp = VN_CAST(typedefp->subDTypep(), StructDType)) {
if (structp->user1() && !structp->packed()) return false;
}
return m_elimCells && !typedefp->attrPublic();
}
void deadCheckMod() {
// Kill any unused modules
// V3LinkCells has a graph that is capable of this too, but we need to do it
@@ -490,6 +509,7 @@ public:
vscp->varp()->user1Inc();
}
deadCheckTypedefs();
deadCheckVar();
// We only eliminate scopes when in a flattened structure
// Otherwise we have no easy way to know if a scope is used