Skip to content

Commit

Permalink
WIP: Fix access modes
Browse files Browse the repository at this point in the history
Signed-off-by: Ryszard Rozak <[email protected]>
  • Loading branch information
RRozak committed Nov 7, 2024
1 parent ec8affe commit 88b56e3
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/V3Randomize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1265,19 +1265,21 @@ class RandomizeVisitor final : public VNVisitor {
AstNodeFTask* const newp = VN_AS(m_memberMap.findMember(classp, "new"), NodeFTask);
UASSERT_OBJ(newp, classp, "No new() in class");
newp->addStmtsp(dynarrayNewp->makeStmt());
newp->addStmtsp(makeModeSetLoop(fl,
new AstVarRef{fl, modeVarModp, modeVarp, VAccess::WRITE},
new AstConst{fl, 1}, true));
}
static AstNode* makeModeSetLoop(FileLine* const fl, AstNodeExpr* const lhsp,
AstNodeExpr* const rhsp, bool inTask) {
AstVar* const iterVarp = new AstVar{fl, VVarType::BLOCKTEMP, "i", lhsp->findUInt32DType()};
newp->addStmtsp(makeModeSetLoop(
fl, new AstVarRef{fl, modeVarModp, modeVarp, VAccess::READ},
new AstVarRef{fl, modeVarModp, modeVarp, VAccess::WRITE}, new AstConst{fl, 1}, true));
}
static AstNode* makeModeSetLoop(FileLine* const fl, AstNodeExpr* const lhsReadp,
AstNodeExpr* const lhsWritep, AstNodeExpr* const rhsp,
bool inTask) {
AstVar* const iterVarp
= new AstVar{fl, VVarType::BLOCKTEMP, "i", lhsReadp->findUInt32DType()};
iterVarp->funcLocal(inTask);
iterVarp->lifetime(VLifetime::AUTOMATIC);
AstCMethodHard* const sizep = new AstCMethodHard{fl, lhsp, "size", nullptr};
AstCMethodHard* const sizep = new AstCMethodHard{fl, lhsReadp, "size", nullptr};
sizep->dtypeSetUInt32();
AstCMethodHard* const setp = new AstCMethodHard{
fl, lhsp->cloneTree(false), "atWrite", new AstVarRef{fl, iterVarp, VAccess::READ}};
fl, lhsWritep, "atWrite", new AstVarRef{fl, iterVarp, VAccess::READ}};
setp->dtypeSetUInt32();
AstNode* const stmtsp = iterVarp;
stmtsp->addNext(
Expand Down Expand Up @@ -1581,18 +1583,19 @@ class RandomizeVisitor final : public VNVisitor {
fl, VVarType::BLOCKTEMP, m_modeUniqueNames.get(randModeVarp), randModeVarp->dtypep()};
randModeTmpVarp->funcLocal(m_ftaskp);
randModeTmpVarp->lifetime(VLifetime::AUTOMATIC);
AstNodeExpr* const siblingReadRefp
= makeSiblingRefp(siblingExprp, randModeVarp, VAccess::READ);
AstNodeExpr* const siblingWriteRefp
= makeSiblingRefp(siblingExprp, randModeVarp, VAccess::WRITE);
storeStmtspr = AstNode::addNext(
storeStmtspr,
new AstAssign{fl, new AstVarRef{fl, randModeTmpVarp, VAccess::WRITE},
makeSiblingRefp(siblingExprp, randModeVarp, VAccess::READ)});
storeStmtspr, new AstAssign{fl, new AstVarRef{fl, randModeTmpVarp, VAccess::WRITE},
siblingReadRefp->cloneTree(false)});
storeStmtspr = AstNode::addNext(
storeStmtspr,
makeModeSetLoop(fl, makeSiblingRefp(siblingExprp, randModeVarp, VAccess::WRITE),
new AstConst{fl, 0}, m_ftaskp));
storeStmtspr, makeModeSetLoop(fl, siblingWriteRefp->cloneTree(false), siblingReadRefp,
new AstConst{fl, 0}, m_ftaskp));
restoreStmtspr = AstNode::addNext(
restoreStmtspr,
new AstAssign{fl, makeSiblingRefp(siblingExprp, randModeVarp, VAccess::WRITE),
new AstVarRef{fl, randModeTmpVarp, VAccess::READ}});
restoreStmtspr, new AstAssign{fl, siblingWriteRefp,
new AstVarRef{fl, randModeTmpVarp, VAccess::READ}});
return randModeTmpVarp;
}
// Returns the common prefix of two hierarchical accesses, or nullptr if there is none
Expand Down Expand Up @@ -1727,7 +1730,7 @@ class RandomizeVisitor final : public VNVisitor {
// For rand_mode: Called on 'this' or a non-rand class instance.
// For constraint_mode: Called on a class instance.
// Set the rand mode of all members
m_stmtp->replaceWith(makeModeSetLoop(fl, lhsp, rhsp, m_ftaskp));
m_stmtp->replaceWith(makeModeSetLoop(fl, lhsp, lhsp, rhsp, m_ftaskp));
}
pushDeletep(m_stmtp);
} else {
Expand Down

0 comments on commit 88b56e3

Please sign in to comment.