Skip to content

Commit

Permalink
[FIRRTL] InferWidths: add value accessor for KnownExpr
Browse files Browse the repository at this point in the history
The KnownExpr always has a known width, but it stores this width using
the Expr base class' memoized solution field.  To make things a bit
clearer, add an accessor for this value that doesn't return an
optional width.
  • Loading branch information
youngar committed Oct 9, 2024
1 parent 1459316 commit 02d4520
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/Dialect/FIRRTL/Transforms/InferWidths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ struct KnownExpr : public ExprBase<KnownExpr, Expr::Kind::Known> {
llvm::hash_code hash_value() const {
return llvm::hash_combine(Expr::hash_value(), *getSolution());
}
int32_t getValue() const { return *getSolution(); }
};

/// A unary expression. Contains the actual data. Concrete subclasses are merely
Expand Down Expand Up @@ -794,7 +795,7 @@ LinIneq ConstraintSolver::checkCycles(VarExpr *var, Expr *expr,
auto ineq =
TypeSwitch<Expr *, LinIneq>(expr)
.Case<KnownExpr>(
[&](auto *expr) { return LinIneq(*expr->getSolution()); })
[&](auto *expr) { return LinIneq(expr->getValue()); })
.Case<VarExpr>([&](auto *expr) {
if (expr == var)
return LinIneq(1, 0); // x >= 1*x + 0
Expand Down Expand Up @@ -962,7 +963,7 @@ static ExprSolution solveExpr(Expr *expr, SmallPtrSetImpl<Expr *> &seenVars,

TypeSwitch<Expr *>(frame.expr)
.Case<KnownExpr>([&](auto *expr) {
setSolution(ExprSolution{*expr->getSolution(), false});
setSolution(ExprSolution{expr->getValue(), false});
})
.Case<VarExpr>([&](auto *expr) {
if (solvedExprs.contains(expr->constraint)) {
Expand Down

0 comments on commit 02d4520

Please sign in to comment.