14 #include "mlir/Pass/Pass.h"
15 #include "mlir/Transforms/DialectConversion.h"
16 #include "llvm/ADT/TypeSwitch.h"
20 #define GEN_PASS_DEF_LOWERSEQSHIFTREG
21 #include "circt/Dialect/Seq/SeqPasses.h.inc"
25 using namespace circt;
32 using OpConversionPattern::OpConversionPattern;
35 matchAndRewrite(seq::ShiftRegOp op, OpAdaptor adaptor,
36 ConversionPatternRewriter &rewriter)
const final {
37 Value in = adaptor.getInput();
38 auto baseName = op.getName();
40 if (
auto powerOn = adaptor.getPowerOnValue()) {
41 if (
auto op = powerOn.getDefiningOp()) {
42 if (op->hasTrait<mlir::OpTrait::ConstantLike>())
47 return op->emitError() <<
"non-constant initial value is not supported";
50 for (
size_t i = 0; i < op.getNumElements(); ++i) {
52 if (baseName.has_value())
53 name = rewriter.getStringAttr(baseName.value() +
"_sh" + Twine(i + 1));
55 op.getLoc(), in, adaptor.getClk(), adaptor.getClockEnable(),
56 adaptor.getReset(), adaptor.getResetValue(), name, init);
59 rewriter.replaceOp(op, in);
64 struct LowerSeqShiftRegPass
65 :
public circt::seq::impl::LowerSeqShiftRegBase<LowerSeqShiftRegPass> {
66 void runOnOperation()
override;
71 void LowerSeqShiftRegPass::runOnOperation() {
72 MLIRContext &
ctxt = getContext();
73 ConversionTarget target(
ctxt);
75 target.addIllegalOp<seq::ShiftRegOp>();
76 target.addLegalDialect<seq::SeqDialect, hw::HWDialect>();
81 applyPartialConversion(getOperation(), target, std::move(
patterns))))
86 return std::make_unique<LowerSeqShiftRegPass>();
mlir::TypedValue< seq::ImmutableType > createConstantInitialValue(OpBuilder builder, Location loc, mlir::IntegerAttr attr)
std::unique_ptr< mlir::Pass > createLowerSeqShiftRegPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.