From a156c90eb463059c0bb167f4565af4d80c9c91a2 Mon Sep 17 00:00:00 2001 From: Martin Erhart Date: Fri, 4 Oct 2024 11:07:50 +0100 Subject: [PATCH] [FIRRTL] Add integer shift left conversion to LowerClasses (#7660) --- .../FIRRTL/Transforms/LowerClasses.cpp | 14 +++++++++++++ test/Dialect/FIRRTL/lower-classes.mlir | 20 ++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/Dialect/FIRRTL/Transforms/LowerClasses.cpp b/lib/Dialect/FIRRTL/Transforms/LowerClasses.cpp index 99ebd1446063..1b816e9323d9 100644 --- a/lib/Dialect/FIRRTL/Transforms/LowerClasses.cpp +++ b/lib/Dialect/FIRRTL/Transforms/LowerClasses.cpp @@ -1660,6 +1660,19 @@ struct IntegerShrOpConversion } }; +struct IntegerShlOpConversion + : public OpConversionPattern { + using OpConversionPattern::OpConversionPattern; + + LogicalResult + matchAndRewrite(firrtl::IntegerShlOp op, OpAdaptor adaptor, + ConversionPatternRewriter &rewriter) const override { + rewriter.replaceOpWithNewOp(op, adaptor.getLhs(), + adaptor.getRhs()); + return success(); + } +}; + struct PathOpConversion : public OpConversionPattern { PathOpConversion(TypeConverter &typeConverter, MLIRContext *context, @@ -2114,6 +2127,7 @@ static void populateRewritePatterns( patterns.add(converter, patterns.getContext()); patterns.add(converter, patterns.getContext()); patterns.add(converter, patterns.getContext()); + patterns.add(converter, patterns.getContext()); } // Convert to OM ops and types in Classes or Modules. diff --git a/test/Dialect/FIRRTL/lower-classes.mlir b/test/Dialect/FIRRTL/lower-classes.mlir index 82f518075c6b..a719561eb229 100644 --- a/test/Dialect/FIRRTL/lower-classes.mlir +++ b/test/Dialect/FIRRTL/lower-classes.mlir @@ -372,18 +372,20 @@ firrtl.circuit "DownwardReferences" { // CHECK-LABEL: firrtl.circuit "IntegerArithmetic" firrtl.circuit "IntegerArithmetic" { - firrtl.module @IntegerArithmetic() { - %0 = firrtl.integer 1 - %1 = firrtl.integer 2 + firrtl.module @IntegerArithmetic() {} + + firrtl.class @IntegerArithmeticClass(in %in0: !firrtl.integer, in %in1: !firrtl.integer) { + // CHECK: om.integer.add %in0, %in1 : !om.integer + %0 = firrtl.integer.add %in0, %in1 : (!firrtl.integer, !firrtl.integer) -> !firrtl.integer - // CHECK: om.integer.add %0, %1 : !om.integer - %2 = firrtl.integer.add %0, %1 : (!firrtl.integer, !firrtl.integer) -> !firrtl.integer + // CHECK: om.integer.mul %in0, %in1 : !om.integer + %1 = firrtl.integer.mul %in0, %in1 : (!firrtl.integer, !firrtl.integer) -> !firrtl.integer - // CHECK: om.integer.mul %0, %1 : !om.integer - %3 = firrtl.integer.mul %0, %1 : (!firrtl.integer, !firrtl.integer) -> !firrtl.integer + // CHECK: om.integer.shr %in0, %in1 : !om.integer + %2 = firrtl.integer.shr %in0, %in1 : (!firrtl.integer, !firrtl.integer) -> !firrtl.integer - // CHECK: om.integer.shr %0, %1 : !om.integer - %4 = firrtl.integer.shr %0, %1 : (!firrtl.integer, !firrtl.integer) -> !firrtl.integer + // CHECK: om.integer.shl %in0, %in1 : !om.integer + %3 = firrtl.integer.shl %in0, %in1 : (!firrtl.integer, !firrtl.integer) -> !firrtl.integer } }