Fix randc cyclic behavior broken with constraints (#7029) (#7035)

This commit is contained in:
Yilou Wang
2026-02-12 10:58:04 -05:00
committed by GitHub
parent 446bec3d1a
commit 9b1b9a5b3b
6 changed files with 438 additions and 5 deletions
+18 -2
View File
@@ -1135,6 +1135,20 @@ class ConstraintExprVisitor final : public VNVisitor {
}
}
initTaskp->addStmtsp(methodp->makeStmt());
// If randc, also emit markRandc() for cyclic tracking
if (varp->isRandC()) {
AstCMethodHard* const markp = new AstCMethodHard{
varp->fileline(),
new AstVarRef{varp->fileline(), VN_AS(m_genp->user2p(), NodeModule),
m_genp, VAccess::READWRITE},
VCMethod::RANDOMIZER_MARK_RANDC};
markp->dtypeSetVoid();
AstNodeExpr* const nameExprp = new AstCExpr{
varp->fileline(), AstCExpr::Pure{}, "\"" + smtName + "\"", varp->width()};
nameExprp->dtypep(varp->dtypep());
markp->addPinsp(nameExprp);
initTaskp->addStmtsp(markp->makeStmt());
}
}
} else {
// Variable already written, clean up cloned membersel if any
@@ -3194,7 +3208,8 @@ class RandomizeVisitor final : public VNVisitor {
stmtp = stmtp->nextp()) {
bool foundClearConstraints = false;
stmtp->foreach([&](AstCMethodHard* methodp) {
if (methodp->method() == VCMethod::RANDOMIZER_WRITE_VAR) {
if (methodp->method() == VCMethod::RANDOMIZER_WRITE_VAR
|| methodp->method() == VCMethod::RANDOMIZER_MARK_RANDC) {
randomizep->addStmtsp(stmtp->cloneTree(false));
} else if (methodp->method()
== VCMethod::RANDOMIZER_CLEARCONSTRAINTS) {
@@ -3544,7 +3559,8 @@ class RandomizeVisitor final : public VNVisitor {
for (AstNode* stmtp = mainRandomizep->stmtsp(); stmtp; stmtp = stmtp->nextp()) {
bool foundClearConstraints = false;
stmtp->foreach([&](AstCMethodHard* methodp) {
if (methodp->method() == VCMethod::RANDOMIZER_WRITE_VAR) {
if (methodp->method() == VCMethod::RANDOMIZER_WRITE_VAR
|| methodp->method() == VCMethod::RANDOMIZER_MARK_RANDC) {
randomizeFuncp->addStmtsp(stmtp->cloneTree(false));
} else if (methodp->method() == VCMethod::RANDOMIZER_CLEARCONSTRAINTS) {
foundClearConstraints = true;