Skip to content

Commit

Permalink
Pass a deleter to simplify; format code
Browse files Browse the repository at this point in the history
Signed-off-by: Ryszard Rozak <[email protected]>
  • Loading branch information
RRozak committed Oct 16, 2023
1 parent afb3c6b commit 8cda144
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
9 changes: 3 additions & 6 deletions src/V3Ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
};

//######################################################################
Expand Down
12 changes: 7 additions & 5 deletions src/V3Const.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8cda144

Please sign in to comment.