diff --git a/lib/Conversion/MooreToCore/MooreToCore.cpp b/lib/Conversion/MooreToCore/MooreToCore.cpp index 7853e71c0630..a12082b2f661 100644 --- a/lib/Conversion/MooreToCore/MooreToCore.cpp +++ b/lib/Conversion/MooreToCore/MooreToCore.cpp @@ -1447,6 +1447,15 @@ static void populateTypeConversion(TypeConverter &typeConverter) { return {}; }); + // FIXME: Unpacked arrays support more element types than their packed + // variants, and as such, mapping them to hw::Array is somewhat naive. See + // also the analogous note below concerning unpacked struct type conversion. + typeConverter.addConversion([&](UnpackedArrayType type) -> std::optional { + if (auto elementType = typeConverter.convertType(type.getElementType())) + return hw::ArrayType::get(elementType, type.getSize()); + return {}; + }); + typeConverter.addConversion([&](StructType type) -> std::optional { SmallVector fields; for (auto field : type.getMembers()) { diff --git a/test/Conversion/MooreToCore/basic.mlir b/test/Conversion/MooreToCore/basic.mlir index ea1baf413d2c..98ae27752090 100644 --- a/test/Conversion/MooreToCore/basic.mlir +++ b/test/Conversion/MooreToCore/basic.mlir @@ -425,6 +425,28 @@ moore.module @Net() { moore.assign %a, %3 : i32 } +// CHECK-LABEL: hw.module @UnpackedArray +moore.module @UnpackedArray(in %arr : !moore.uarray<2 x i32>, in %sel : !moore.i1, out c : !moore.i32) { + // CHECK: hw.array_get %arr[%sel] : !hw.array<2xi32>, i1 + %0 = moore.dyn_extract %arr from %sel : !moore.uarray<2 x i32>, !moore.i1 -> !moore.i32 + + // CHECK: [[TRUE:%.+]] = hw.constant true + // CHECK: hw.array_get %arr[[[TRUE]]] : !hw.array<2xi32>, i1 + %1 = moore.extract %arr from 1 : !moore.uarray<2 x i32> -> !moore.i32 + + // CHECK: [[C0:%.+]] = hw.constant 0 : i128 + // CHECK: [[INIT:%.+]] = hw.bitcast [[C0]] : (i128) -> !hw.array<4xi32> + // CHECK: [[SIG:%.+]] = llhd.sig [[INIT]] : !hw.array<4xi32> + %2 = moore.variable : > + + // CHECK: [[C1:%.+]] = hw.constant 1 : i2 + // CHECK: llhd.sig.array_get [[SIG]][[[C1]]] : !hw.inout> + %3 = moore.extract_ref %2 from 1 : !moore.ref> -> !moore.ref + moore.assign %3, %0 : i32 + + moore.output %0 : !moore.i32 +} + // CHECK-LABEL: hw.module @Struct moore.module @Struct(in %a : !moore.i32, in %b : !moore.i32, in %arg0 : !moore.struct<{exp_bits: i32, man_bits: i32}>, in %arg1 : !moore.ref>, out a : !moore.i32, out b : !moore.struct<{exp_bits: i32, man_bits: i32}>, out c : !moore.struct<{exp_bits: i32, man_bits: i32}>) { // CHECK: hw.struct_extract %arg0["exp_bits"] : !hw.struct