Skip to content

[MooreToCore] Lower moore.array_create Op #8364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/Conversion/MooreToCore/MooreToCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,19 @@ struct DynExtractRefOpConversion : public OpConversionPattern<DynExtractRefOp> {
}
};

struct ArrayCreateOpConversion : public OpConversionPattern<ArrayCreateOp> {
using OpConversionPattern::OpConversionPattern;

LogicalResult
matchAndRewrite(ArrayCreateOp op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
Type resultType = typeConverter->convertType(op.getResult().getType());
rewriter.replaceOpWithNewOp<hw::ArrayCreateOp>(op, resultType,
adaptor.getElements());
return success();
}
};

struct StructCreateOpConversion : public OpConversionPattern<StructCreateOp> {
using OpConversionPattern::OpConversionPattern;

Expand Down Expand Up @@ -1780,7 +1793,7 @@ static void populateOpConversion(RewritePatternSet &patterns,
ExtractOpConversion, DynExtractOpConversion, DynExtractRefOpConversion,
ReadOpConversion,
StructExtractOpConversion, StructExtractRefOpConversion,
ExtractRefOpConversion, StructCreateOpConversion, ConditionalOpConversion,
ExtractRefOpConversion, StructCreateOpConversion, ConditionalOpConversion, ArrayCreateOpConversion,
YieldOpConversion, OutputOpConversion, StringConstantOpConv,

// Patterns of unary operations.
Expand Down
22 changes: 22 additions & 0 deletions test/Conversion/MooreToCore/basic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,28 @@ moore.module @Struct(in %a : !moore.i32, in %b : !moore.i32, in %arg0 : !moore.s
moore.output %0, %3, %4 : !moore.i32, !moore.struct<{exp_bits: i32, man_bits: i32}>, !moore.struct<{exp_bits: i32, man_bits: i32}>
}

// CHECK-LABEL: func @ArrayCreate
// CHECK-SAME: () -> !hw.array<2xi8>
func.func @ArrayCreate() -> !moore.array<2x!moore.i8> {
// CHECK-NEXT: %c42_i8 = hw.constant 42 : i8
%c0 = moore.constant 42 : !moore.i8
// CHECK-NEXT: [[ARR:%.*]] = hw.array_create %c42_i8, %c42_i8 : i8
%arr = moore.array_create %c0, %c0 : !moore.i8, !moore.i8 -> !moore.array<2x!moore.i8>
// CHECK-NEXT: return [[ARR:%.*]] : !hw.array<2xi8>
return %arr : !moore.array<2x!moore.i8>
}

// CHECK-LABEL: func @UnpackedArrayCreate
// CHECK-SAME: () -> !hw.array<2xi8>
func.func @UnpackedArrayCreate() -> !moore.uarray<2x!moore.i8> {
// CHECK-NEXT: %c7_i8 = hw.constant 7 : i8
%a = moore.constant 7 : !moore.i8
// CHECK-NEXT: [[ARR:%.*]] = hw.array_create %c7_i8, %c7_i8 : i8
%arr = moore.array_create %a, %a : !moore.i8, !moore.i8 -> !moore.uarray<2x!moore.i8>
// CHECK-NEXT: return [[ARR:%.*]] : !hw.array<2xi8>
return %arr : !moore.uarray<2x!moore.i8>
}

// CHECK-LABEL: hw.module @UnpackedStruct
moore.module @UnpackedStruct() {
// CHECK: %[[C1_32:.*]] = hw.constant 1 : i32
Expand Down