Skip to content

Commit

Permalink
[Seq] Fix the canonicalization of seq registers with a clock type (#6274
Browse files Browse the repository at this point in the history
)
  • Loading branch information
nandor authored Oct 10, 2023
1 parent 0d7cd67 commit 225e26e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/Dialect/Seq/SeqOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,15 @@ LogicalResult FirRegOp::canonicalize(FirRegOp op, PatternRewriter &rewriter) {
// If the register has a reset value, we can replace it with that.
rewriter.replaceOp(op, resetValue);
} else {
auto constant = rewriter.create<hw::ConstantOp>(
op.getLoc(), APInt::getZero(hw::getBitWidth(op.getType())));
rewriter.replaceOpWithNewOp<hw::BitcastOp>(op, op.getType(), constant);
if (op.getType().isa<seq::ClockType>()) {
rewriter.replaceOpWithNewOp<seq::ConstClockOp>(
op,
seq::ClockConstAttr::get(rewriter.getContext(), ClockConst::Low));
} else {
auto constant = rewriter.create<hw::ConstantOp>(
op.getLoc(), APInt::getZero(hw::getBitWidth(op.getType())));
rewriter.replaceOpWithNewOp<hw::BitcastOp>(op, op.getType(), constant);
}
}
return success();
}
Expand Down
8 changes: 8 additions & 0 deletions test/Dialect/Seq/canonicalization.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,12 @@ hw.module @const_clock(out clock_true : !seq.clock, out clock_false : !seq.clock

// CHECK: hw.output [[CLOCK_FALSE]], [[CLOCK_TRUE]]
hw.output %clock_false, %clock_true : !seq.clock, !seq.clock
}

// CHECK-LABEL: @const_clock_reg
hw.module @const_clock_reg(in %clock : !seq.clock, out r_data : !seq.clock) {
// CHECK: seq.const_clock low
%0 = seq.const_clock low
%1 = seq.firreg %1 clock %0 : !seq.clock
hw.output %1 : !seq.clock
}

0 comments on commit 225e26e

Please sign in to comment.