Internals: Replace unnecessary AstSel::widthp() child node with const in node (#6117)

This commit is contained in:
Geza Lore
2025-06-24 11:59:09 -04:00
committed by GitHub
parent a9e9ab50bd
commit 916d473eff
28 changed files with 276 additions and 354 deletions
+14 -12
View File
@@ -503,9 +503,15 @@ class ConstraintExprVisitor final : public VNVisitor {
UASSERT_OBJ(smtExpr != "", nodep,
"Node needs randomization constraint, but no emitSMT: " << nodep);
if (lhsp) lhsp = VN_AS(iterateSubtreeReturnEdits(lhsp->unlinkFrBack()), NodeExpr);
if (rhsp) rhsp = VN_AS(iterateSubtreeReturnEdits(rhsp->unlinkFrBack()), NodeExpr);
if (thsp) thsp = VN_AS(iterateSubtreeReturnEdits(thsp->unlinkFrBack()), NodeExpr);
if (lhsp)
lhsp = VN_AS(iterateSubtreeReturnEdits(lhsp->backp() ? lhsp->unlinkFrBack() : lhsp),
NodeExpr);
if (rhsp)
rhsp = VN_AS(iterateSubtreeReturnEdits(rhsp->backp() ? rhsp->unlinkFrBack() : rhsp),
NodeExpr);
if (thsp)
thsp = VN_AS(iterateSubtreeReturnEdits(thsp->backp() ? thsp->unlinkFrBack() : thsp),
NodeExpr);
AstNodeExpr* argsp = nullptr;
for (string::iterator pos = smtExpr.begin(); pos != smtExpr.end(); ++pos) {
@@ -704,13 +710,11 @@ class ConstraintExprVisitor final : public VNVisitor {
void visit(AstSel* nodep) override {
if (editFormat(nodep)) return;
VNRelinker handle;
AstNodeExpr* const widthp = nodep->widthp()->unlinkFrBack(&handle);
FileLine* const fl = nodep->fileline();
AstNodeExpr* const msbp
= new AstSFormatF{fl, "%1d", false,
new AstAdd{fl, nodep->lsbp()->cloneTreePure(false),
new AstSub{fl, widthp, new AstConst{fl, 1}}}};
handle.relink(msbp);
AstNodeExpr* const msbp = new AstSFormatF{
fl, "%1d", false,
new AstAdd{fl, nodep->lsbp()->cloneTreePure(false),
new AstConst{fl, static_cast<uint32_t>(nodep->widthConst() - 1)}}};
AstNodeExpr* const lsbp
= new AstSFormatF{fl, "%1d", false, nodep->lsbp()->unlinkFrBack(&handle)};
handle.relink(lsbp);
@@ -1562,9 +1566,7 @@ class RandomizeVisitor final : public VNVisitor {
fl,
new AstSub{fl, tempRefp,
new AstConst{fl, static_cast<uint32_t>(aryDTypep->lo())}},
new AstConst{fl, 0},
new AstConst{
fl, static_cast<uint32_t>(V3Number::log2b(aryDTypep->hi()) + 1)}}};
new AstConst{fl, 0}, V3Number::log2b(aryDTypep->hi()) + 1}};
} else if (VN_IS(tempDTypep, AssocArrayDType))
tempElementp = new AstAssocSel{fl, tempExprp, tempRefp};
else if (VN_IS(tempDTypep, QueueDType))