Skip to content

Commit

Permalink
[FIRRTL] InferWidths: Don't need to duplicate InvalidValues
Browse files Browse the repository at this point in the history
We used to duplicate InvalidValues to their uses, so that each use could
be inferred separately.  This was because InvalidValues were considered
constants, and things like CSE might combine many unknown-width invalid
values, and we wanted to counteract this affect.  InvalidValues are no
longer pure, and so will not be CSE'd away this way anymore, making this
code no longer needed.
  • Loading branch information
youngar committed Oct 11, 2024
1 parent 094dca3 commit f4b2e8c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 24 deletions.
15 changes: 0 additions & 15 deletions lib/Dialect/FIRRTL/Transforms/InferWidths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1400,21 +1400,6 @@ LogicalResult InferenceMapping::mapOperation(Operation *op) {
// We must duplicate the invalid value for each use, since each use can
// be inferred to a different width.
declareVars(op.getResult(), op.getLoc(), /*isDerived=*/true);
if (op.use_empty())
return;

auto type = op.getType();
ImplicitLocOpBuilder builder(op->getLoc(), op);
for (auto &use :
llvm::make_early_inc_range(llvm::drop_begin(op->getUses()))) {
// - `make_early_inc_range` since `getUses()` is invalidated upon
// `use.set(...)`.
// - `drop_begin` such that the first use can keep the original op.
auto clone = builder.create<InvalidValueOp>(type);
declareVars(clone.getResult(), clone.getLoc(),
/*isDerived=*/true);
use.set(clone);
}
})
.Case<WireOp, RegOp>(
[&](auto op) { declareVars(op.getResult(), op.getLoc()); })
Expand Down
9 changes: 0 additions & 9 deletions test/Dialect/FIRRTL/infer-widths.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ firrtl.circuit "Foo" {
firrtl.connect %out, %invalid_ui : !firrtl.uint, !firrtl.uint
firrtl.connect %out, %c42_ui : !firrtl.uint, !firrtl.uint

// Check that the invalid values are duplicated, and a corner case where the
// wire won't be updated with a width until after updating the invalid value
// above.
// CHECK: %invalid_ui2 = firrtl.invalidvalue : !firrtl.uint<2>
%w = firrtl.wire : !firrtl.uint
%c2_ui = firrtl.constant 2 : !firrtl.uint
firrtl.connect %w, %invalid_ui : !firrtl.uint, !firrtl.uint
firrtl.connect %w, %c2_ui : !firrtl.uint, !firrtl.uint

// Check that invalid values are inferred to width zero if not used in a
// connect.
// CHECK: firrtl.invalidvalue : !firrtl.uint<0>
Expand Down

0 comments on commit f4b2e8c

Please sign in to comment.