Skip to content

Commit fdb946e

Browse files
authored
[MooreToCore] Lower moore.array_create op (#8364)
Fixes #8128.
1 parent 349517e commit fdb946e

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/Conversion/MooreToCore/MooreToCore.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,19 @@ struct DynExtractRefOpConversion : public OpConversionPattern<DynExtractRefOp> {
898898
}
899899
};
900900

901+
struct ArrayCreateOpConversion : public OpConversionPattern<ArrayCreateOp> {
902+
using OpConversionPattern::OpConversionPattern;
903+
904+
LogicalResult
905+
matchAndRewrite(ArrayCreateOp op, OpAdaptor adaptor,
906+
ConversionPatternRewriter &rewriter) const override {
907+
Type resultType = typeConverter->convertType(op.getResult().getType());
908+
rewriter.replaceOpWithNewOp<hw::ArrayCreateOp>(op, resultType,
909+
adaptor.getElements());
910+
return success();
911+
}
912+
};
913+
901914
struct StructCreateOpConversion : public OpConversionPattern<StructCreateOp> {
902915
using OpConversionPattern::OpConversionPattern;
903916

@@ -1780,7 +1793,7 @@ static void populateOpConversion(RewritePatternSet &patterns,
17801793
ExtractOpConversion, DynExtractOpConversion, DynExtractRefOpConversion,
17811794
ReadOpConversion,
17821795
StructExtractOpConversion, StructExtractRefOpConversion,
1783-
ExtractRefOpConversion, StructCreateOpConversion, ConditionalOpConversion,
1796+
ExtractRefOpConversion, StructCreateOpConversion, ConditionalOpConversion, ArrayCreateOpConversion,
17841797
YieldOpConversion, OutputOpConversion, StringConstantOpConv,
17851798

17861799
// Patterns of unary operations.

test/Conversion/MooreToCore/basic.mlir

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,28 @@ moore.module @Struct(in %a : !moore.i32, in %b : !moore.i32, in %arg0 : !moore.s
533533
moore.output %0, %3, %4 : !moore.i32, !moore.struct<{exp_bits: i32, man_bits: i32}>, !moore.struct<{exp_bits: i32, man_bits: i32}>
534534
}
535535

536+
// CHECK-LABEL: func @ArrayCreate
537+
// CHECK-SAME: () -> !hw.array<2xi8>
538+
func.func @ArrayCreate() -> !moore.array<2x!moore.i8> {
539+
// CHECK-NEXT: %c42_i8 = hw.constant 42 : i8
540+
%c0 = moore.constant 42 : !moore.i8
541+
// CHECK-NEXT: [[ARR:%.*]] = hw.array_create %c42_i8, %c42_i8 : i8
542+
%arr = moore.array_create %c0, %c0 : !moore.i8, !moore.i8 -> !moore.array<2x!moore.i8>
543+
// CHECK-NEXT: return [[ARR:%.*]] : !hw.array<2xi8>
544+
return %arr : !moore.array<2x!moore.i8>
545+
}
546+
547+
// CHECK-LABEL: func @UnpackedArrayCreate
548+
// CHECK-SAME: () -> !hw.array<2xi8>
549+
func.func @UnpackedArrayCreate() -> !moore.uarray<2x!moore.i8> {
550+
// CHECK-NEXT: %c7_i8 = hw.constant 7 : i8
551+
%a = moore.constant 7 : !moore.i8
552+
// CHECK-NEXT: [[ARR:%.*]] = hw.array_create %c7_i8, %c7_i8 : i8
553+
%arr = moore.array_create %a, %a : !moore.i8, !moore.i8 -> !moore.uarray<2x!moore.i8>
554+
// CHECK-NEXT: return [[ARR:%.*]] : !hw.array<2xi8>
555+
return %arr : !moore.uarray<2x!moore.i8>
556+
}
557+
536558
// CHECK-LABEL: hw.module @UnpackedStruct
537559
moore.module @UnpackedStruct() {
538560
// CHECK: %[[C1_32:.*]] = hw.constant 1 : i32

0 commit comments

Comments
 (0)