DFG: Remove unconneced variables early

This commit is contained in:
Geza Lore
2022-09-30 11:53:03 +01:00
parent c9d6344f2f
commit cc51966ad1
2 changed files with 30 additions and 6 deletions
+20 -2
View File
@@ -110,8 +110,7 @@ class AstToDfgVisitor final : public VNVisitor {
// Note DfgVertexLValue vertices are not added to m_uncommittedVertices, because we
// want to hold onto them via AstVar::user1p, and the AstVar might be referenced via
// multiple AstVarRef instances, so we will never revert a DfgVertexLValue once
// created. This means we can end up with DfgVertexLValue vertices in the graph which
// have no connections at all (which is fine for later processing).
// created. We will delete unconnected variable vertices at the end.
if (VN_IS(varp->dtypep()->skipRefp(), UnpackArrayDType)) {
DfgVarArray* const vtxp = new DfgVarArray{*m_dfgp, varp};
varp->user1p();
@@ -264,6 +263,13 @@ class AstToDfgVisitor final : public VNVisitor {
// Canonicalize packed variables
void canonicalizePacked() {
for (DfgVarPacked* const varp : m_varPackedps) {
// Delete variables with no sinks nor sources (this can happen due to reverting
// uncommitted vertices, which does not remove variables)
if (!varp->hasSinks() && varp->arity() == 0) {
VL_DO_DANGLING(varp->unlinkDelete(*m_dfgp), varp);
continue;
}
// Gather (and unlink) all drivers
struct Driver {
FileLine* flp;
@@ -328,6 +334,17 @@ class AstToDfgVisitor final : public VNVisitor {
}
}
// Canonicalize array variables
void canonicalizeArray() {
for (DfgVarArray* const varp : m_varArrayps) {
// Delete variables with no sinks nor sources (this can happen due to reverting
// uncommitted vertices, which does not remove variables)
if (!varp->hasSinks() && varp->arity() == 0) {
VL_DO_DANGLING(varp->unlinkDelete(*m_dfgp), varp);
}
}
}
// VISITORS
void visit(AstNode* nodep) override {
// Conservatively treat this node as unhandled
@@ -406,6 +423,7 @@ class AstToDfgVisitor final : public VNVisitor {
// Canonicalize variables
canonicalizePacked();
canonicalizeArray();
}
public: