Skip to content

Commit

Permalink
Use set instead of user3 pointer
Browse files Browse the repository at this point in the history
Signed-off-by: Ryszard Rozak <[email protected]>
  • Loading branch information
RRozak committed Dec 10, 2024
1 parent 31089bf commit cfedf5e
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/V3Randomize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,6 @@ class RandomizeMarkVisitor final : public VNVisitor {

class ConstraintExprVisitor final : public VNVisitor {
// NODE STATE
// AstVar::user3() -> int. 0 - unconstrained, 1 - constrained by class constraints,
// higher value - constrained by with clause of randomize
// AstNodeExpr::user1() -> bool. Depending on a randomized variable
// VNuser3InUse m_inuser3; (Allocated for use in RandomizeVisitor)

Expand Down Expand Up @@ -1086,7 +1084,6 @@ class RandomizeVisitor final : public VNVisitor {
// AstEnumDType::user2() -> AstVar*. Pointer to table with enum values
// AstConstraint::user2p() -> AstTask*. Pointer to constraint setup procedure
// AstClass::user2p() -> AstVar*. Rand mode state variable
// AstVar::user3() -> int. Handled in constraints
// AstConstraint::user3p() -> AstTask*. Pointer to resize procedure
// AstClass::user4p() -> AstVar*. Constraint mode state variable
// AstVar::user4p() -> AstVar*. Size variable for constrained queues
Expand All @@ -1113,12 +1110,9 @@ class RandomizeVisitor final : public VNVisitor {
std::map<AstClass*, std::set<AstVar*>>
m_constrainedVars; // Variables constrained by constraints defined in class
AstConstraint* m_constraintp = nullptr; // Current constraint
int m_withCnt = 1; // AstWith count, 1 is for class constraints

// METHODS
void addWriteVar(AstVar* const varp, const int cnt, AstVar* const genp,
AstFunc* const randomizeFuncp) {
varp->user3(cnt);
void addWriteVar(AstVar* const varp, AstVar* const genp, AstFunc* const randomizeFuncp) {
AstCMethodHard* const methodp = new AstCMethodHard{
varp->fileline(), new AstVarRef{varp->fileline(), genp, VAccess::READWRITE},
"write_var"};
Expand Down Expand Up @@ -1670,15 +1664,15 @@ class RandomizeVisitor final : public VNVisitor {
});
}
void addBasicRandomizeBody(AstFunc* const basicRandomizep, AstClass* const nodep,
const int withCnt) {
const std::set<AstVar*>& constrainedVars) {
FileLine* const fl = nodep->fileline();
AstVar* const basicFvarp = VN_AS(basicRandomizep->fvarp(), Var);
AstVarRef* const basicFvarRefp = new AstVarRef{fl, basicFvarp, VAccess::WRITE};
AstConst* const beginBasicValp = new AstConst{fl, AstConst::WidthedValue{}, 32, 1};
basicRandomizep->addStmtsp(new AstAssign{fl, basicFvarRefp, beginBasicValp});
nodep->foreachMember([&](AstClass* classp, AstVar* memberVarp) {
if (!memberVarp->rand().isRandomizable()) return;
if (memberVarp->user3() == 1 || memberVarp->user3() == withCnt) {
if (constrainedVars.find(memberVarp) != constrainedVars.end()) {
return; // Handled in constraints
}
const AstNodeDType* const dtypep = memberVarp->dtypep()->skipRefp();
Expand Down Expand Up @@ -1918,7 +1912,7 @@ class RandomizeVisitor final : public VNVisitor {
}
constrCopyp->deleteTree();
}
for (auto varp : m_constrainedVars[nodep]) addWriteVar(varp, 1, genp, randomizep);
for (auto varp : m_constrainedVars[nodep]) addWriteVar(varp, genp, randomizep);
AstTask* const setupTaskp = VN_AS(constrp->user2p(), Task);
AstTaskRef* const setupRefp = new AstTaskRef{
fl, setupTaskp->name(),
Expand Down Expand Up @@ -1954,7 +1948,7 @@ class RandomizeVisitor final : public VNVisitor {
AstFunc* const basicRandomizep
= V3Randomize::newRandomizeFunc(m_memberMap, nodep, "__Vbasic_randomize");
handleRandMode(nodep, randModeVarp);
addBasicRandomizeBody(basicRandomizep, nodep, 1);
addBasicRandomizeBody(basicRandomizep, nodep, m_constrainedVars[nodep]);
AstFuncRef* const basicRandomizeCallp = new AstFuncRef{fl, "__Vbasic_randomize", nullptr};
basicRandomizeCallp->taskp(basicRandomizep);
basicRandomizeCallp->dtypep(basicRandomizep->dtypep());
Expand Down Expand Up @@ -2075,7 +2069,6 @@ class RandomizeVisitor final : public VNVisitor {
return;
}
withp->unlinkFrBack();
++m_withCnt;

iterateChildren(nodep);

Expand Down Expand Up @@ -2128,9 +2121,7 @@ class RandomizeVisitor final : public VNVisitor {
for (AstNode* itemp = capturedTreep; itemp; itemp = itemp->nextp()) {
fillConstrainedSetRecurse(itemp, constrainedVars);
}
for (auto varp : constrainedVars) {
addWriteVar(varp, m_withCnt, localGenp, randomizeFuncp);
}
for (auto varp : constrainedVars) addWriteVar(varp, localGenp, randomizeFuncp);

// Get constraints from the class
classp->foreachMember([&](AstClass* const clp, AstConstraint* const constrp) {
Expand Down Expand Up @@ -2169,7 +2160,7 @@ class RandomizeVisitor final : public VNVisitor {
= new AstFuncRef{fl, basicRandomizeFuncp->name(), nullptr};
basicRandomizeFuncCallp->taskp(basicRandomizeFuncp);
basicRandomizeFuncCallp->dtypep(basicRandomizeFuncp->dtypep());
addBasicRandomizeBody(basicRandomizeFuncp, classp, m_withCnt);
addBasicRandomizeBody(basicRandomizeFuncp, classp, constrainedVars);

randomizeFuncp->addStmtsp(new AstAssign{
fl, fvarWriteRefp->cloneTree(false),
Expand Down

0 comments on commit cfedf5e

Please sign in to comment.