Skip to content

Commit

Permalink
[FIRRTL] Add integer shift left conversion to LowerClasses (#7660)
Browse files Browse the repository at this point in the history
  • Loading branch information
maerhart authored Oct 4, 2024
1 parent af10460 commit a156c90
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
14 changes: 14 additions & 0 deletions lib/Dialect/FIRRTL/Transforms/LowerClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,19 @@ struct IntegerShrOpConversion
}
};

struct IntegerShlOpConversion
: public OpConversionPattern<firrtl::IntegerShlOp> {
using OpConversionPattern::OpConversionPattern;

LogicalResult
matchAndRewrite(firrtl::IntegerShlOp op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
rewriter.replaceOpWithNewOp<om::IntegerShlOp>(op, adaptor.getLhs(),
adaptor.getRhs());
return success();
}
};

struct PathOpConversion : public OpConversionPattern<firrtl::PathOp> {

PathOpConversion(TypeConverter &typeConverter, MLIRContext *context,
Expand Down Expand Up @@ -2114,6 +2127,7 @@ static void populateRewritePatterns(
patterns.add<IntegerAddOpConversion>(converter, patterns.getContext());
patterns.add<IntegerMulOpConversion>(converter, patterns.getContext());
patterns.add<IntegerShrOpConversion>(converter, patterns.getContext());
patterns.add<IntegerShlOpConversion>(converter, patterns.getContext());
}

// Convert to OM ops and types in Classes or Modules.
Expand Down
20 changes: 11 additions & 9 deletions test/Dialect/FIRRTL/lower-classes.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit a156c90

Please sign in to comment.