diff --git a/src/V3Ast.h b/src/V3Ast.h index cb4a2806e3..8715dac7cd 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -1568,12 +1568,9 @@ class VNVisitor VL_NOT_FINAL : public VNVisitorConst { /// Return edited nodep; see comments in V3Ast.cpp inline AstNode* iterateSubtreeReturnEdits(AstNode* nodep); - inline void pushDeletep(AstNode* nodep) { - deleter.pushDeletep(nodep); - } - inline void doDeletes() { - deleter.doDeletes(); - } + inline VNDeleter& getDeleter() { return deleter; } + inline void pushDeletep(AstNode* nodep) { deleter.pushDeletep(nodep); } + inline void doDeletes() { deleter.doDeletes(); } }; //###################################################################### diff --git a/src/V3Const.cpp b/src/V3Const.cpp index eb56d922d6..e52b8cff0f 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -673,7 +673,7 @@ class ConstBitOpTreeVisitor final : public VNVisitorConst { // Reduction ops are transformed in the same way. // &{v[0], v[1]} => 2'b11 == (2'b11 & v) static AstNodeExpr* simplify(AstNodeExpr* nodep, int resultWidth, unsigned externalOps, - VDouble0& reduction) { + VDouble0& reduction, VNDeleter& deleter) { UASSERT_OBJ(1 <= resultWidth && resultWidth <= 64, nodep, "resultWidth out of range"); // Walk tree, gathering all terms referenced in expression @@ -716,7 +716,7 @@ class ConstBitOpTreeVisitor final : public VNVisitorConst { } // Set width and widthMin precisely resultp->dtypeChgWidth(resultWidth, 1); - for (AstNode* const termp : termps) termp->deleteTree(); + for (AstNode* const termp : termps) deleter.pushDeletep(termp); return resultp; } const ResultTerm result = v->getResultTerm(); @@ -792,7 +792,7 @@ class ConstBitOpTreeVisitor final : public VNVisitorConst { // Only substitute the result if beneficial as determined by operation count if (visitor.m_ops <= resultOps) { - for (AstNode* const termp : termps) termp->deleteTree(); + for (AstNode* const termp : termps) deleter.pushDeletep(termp); return nullptr; } @@ -1175,9 +1175,11 @@ class ConstVisitor final : public VNVisitor { const AstAnd* const andp = VN_CAST(nodep, And); const int width = nodep->width(); if (andp && isConst(andp->lhsp(), 1)) { // 1 & BitOpTree - newp = ConstBitOpTreeVisitor::simplify(andp->rhsp(), width, 1, m_statBitOpReduction); + newp = ConstBitOpTreeVisitor::simplify(andp->rhsp(), width, 1, m_statBitOpReduction, + getDeleter()); } else { // BitOpTree - newp = ConstBitOpTreeVisitor::simplify(nodep, width, 0, m_statBitOpReduction); + newp = ConstBitOpTreeVisitor::simplify(nodep, width, 0, m_statBitOpReduction, + getDeleter()); } if (newp) {