Skip to content

Commit

Permalink
[FIRRTL] Register reset elimination based on invalid can look through…
Browse files Browse the repository at this point in the history
… nodes. (llvm#7069)

This converts wires into nodes when there is one write to the wire and it dominates the reads.  By converting to nodes, this pass does not have to worry about symbols, references, or annotations.  Those are just copied to the node.
  • Loading branch information
darthscsi authored May 22, 2024
1 parent 535f147 commit da2ca8c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/Dialect/FIRRTL/Transforms/InferResets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ static bool getDeclName(Value value, SmallString<32> &string) {
op.getPortName(cast<OpResult>(value).getResultNumber()).getValue();
return true;
})
.Case<WireOp, RegOp, RegResetOp>([&](auto op) {
.Case<WireOp, NodeOp, RegOp, RegResetOp>([&](auto op) {
string += op.getName();
return true;
})
Expand Down
2 changes: 1 addition & 1 deletion lib/Dialect/FIRRTL/Transforms/SFCCompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void SFCCompatPass::runOnOperation() {
// If the `RegResetOp` has an invalidated initialization and we
// are not running FART, then replace it with a `RegOp`.
if (!fullAsyncResetExists &&
walkDrivers(reg.getResetValue(), true, false, false,
walkDrivers(reg.getResetValue(), true, true, false,
[](FieldRef dst, FieldRef src) {
return src.isa<InvalidValueOp>();
})) {
Expand Down
2 changes: 2 additions & 0 deletions test/Dialect/FIRRTL/SFCTests/data-taps.fir
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ circuit Top : %[[
io.d <= d

; CHECK: module Top
; TODO: fix having constants carry names
; CHECK: wire inv = 1'h0
; CHECK: io_b = Top.foo.f_probe;
; CHECK-NEXT: io_c = Top.foo.g_probe;
; CHECK-NEXT: io_d = inv;
Expand Down
2 changes: 1 addition & 1 deletion test/Dialect/FIRRTL/SFCTests/dedup.fir
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ circuit Top18 : %[[
; CHECK: module private @A(
module A :
output x: UInt<1>
; CHECK-NEXT: firrtl.wire
; CHECK: firrtl.wire
; CHECK-SAME: [{class = "firrtl.transforms.DontTouchAnnotation"}]
wire b: UInt<1>
b is invalid
Expand Down
5 changes: 3 additions & 2 deletions test/Dialect/FIRRTL/sfc-compat.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ firrtl.circuit "SFCCompatTests" {
firrtl.connect %q, %r : !firrtl.uint<1>, !firrtl.uint<1>
}

// A regreset invalid value should NOT propagate through a node.
// A regreset invalid value should propagate through a node.
// Change from SFC behavior.
firrtl.module @InvalidNode(in %clock: !firrtl.clock, in %reset: !firrtl.uint<1>, in %d: !firrtl.uint<8>, out %q: !firrtl.uint<8>) {
%inv = firrtl.wire : !firrtl.uint<8>
%invalid_ui8 = firrtl.invalidvalue : !firrtl.uint<8>
firrtl.connect %inv, %invalid_ui8 : !firrtl.uint<8>, !firrtl.uint<8>
%_T = firrtl.node %inv : !firrtl.uint<8>
// CHECK: firrtl.regreset %clock
// CHECK: firrtl.reg %clock
%r = firrtl.regreset %clock, %reset, %_T : !firrtl.clock, !firrtl.uint<1>, !firrtl.uint<8>, !firrtl.uint<8>
firrtl.connect %r, %d : !firrtl.uint<8>, !firrtl.uint<8>
firrtl.connect %q, %r : !firrtl.uint<8>, !firrtl.uint<8>
Expand Down

0 comments on commit da2ca8c

Please sign in to comment.