Skip to content
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

[HW][FlattenIO] Flatten io arrays #6996

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

hovind
Copy link
Contributor

@hovind hovind commented May 7, 2024

This is an attempt at following @uenoku's suggestions in #6557 (comment), by extending the FlattenIO pass flatten hw::ArrayType in addition to hw::StructType.

@mortbopet how does this agree with your usage of FlattenIO with ESI? According to 062eab3:

My specific usecase for this is to be able to correctly lower ESI ports that are nested within a struct.

Is this specific usecase covered by a test?

diff --git a/test/Dialect/ESI/lowering.mlir b/test/Dialect/ESI/lowering.mlir
index b28197bcc..06d248133 100644
--- a/test/Dialect/ESI/lowering.mlir
+++ b/test/Dialect/ESI/lowering.mlir
@@ -1,6 +1,6 @@
 // RUN: circt-opt %s --lower-esi-to-physical -verify-diagnostics | circt-opt -verify-diagnostics | FileCheck %s
 // RUN: circt-opt %s --lower-esi-ports -verify-diagnostics | circt-opt -verify-diagnostics | FileCheck --check-prefix=IFACE %s
-// RUN: circt-opt %s --lower-esi-to-physical --lower-esi-ports --hw-flatten-io --lower-esi-to-hw -verify-diagnostics | circt-opt -verify-diagnostics | FileCheck --check-prefix=HW %s
+// RUN: circt-opt %s --lower-esi-to-physical --lower-esi-ports --lower-esi-to-hw -verify-diagnostics | circt-opt -verify-diagnostics | FileCheck --check-prefix=HW %s
 
 hw.module.extern @Sender(in %clk: !seq.clock, out x: !esi.channel<i4>, out y: i8) attributes {esi.bundle}
 hw.module.extern @ArrSender(out x: !esi.channel<!hw.array<4xi64>>) attributes {esi.bundle}
@@ -67,7 +67,7 @@ hw.module @add11(in %clk: !seq.clock, in %ints: !esi.channel<i32>, out mutatedIn
 }
 // HW-LABEL: hw.module @add11(in %clk : !seq.clock, in %ints : i32, in %ints_valid : i1, in %mutatedInts_ready : i1, out ints_ready : i1, out mutatedInts : i32, out mutatedInts_valid : i1, out c4 : i4) {
 // HW:   %{{.+}} = hw.constant 11 : i32
-// HW:   [[RES0:%.+]] = comb.add %ints, %{{.+}} : i32
+// HW:   [[RES0:%.+]] = comb.add %{{.+}}, %ints : i32
 // HW:   %{{.+}} = hw.constant 0 : i4
 // HW:   hw.output %mutatedInts_ready, [[RES0]], %ints_valid, %{{.+}} : i1, i32, i1, i4

The above changes seem to make the tests pass, but I imagine that I might be breaking something that I don't quite understand.

Would it be preferable to template the FlattenIO pass over an aggregate type (hw::StructType or hw::ArrayType in practice)? Or to provide parameters to the pass describing what aggregate types to flatten? Any advice would be appreciated.

@mortbopet
Copy link
Contributor

Good catch; there's actually no test for lowering ESI channels to HW inside test/Dialect/ESI/lowering.mlir, which should definitely be added (CC @teqdruid). I don't think ArrayType in I/O has been an issue for us yet.

Would it be preferable to template the FlattenIO pass over an aggregate type (hw::StructType or hw::ArrayType in practice)? Or to provide parameters to the pass describing what aggregate types to flatten? Any advice would be appreciated.

Personally, i think opting in to enabling the specific types to be flattened is preferred.

@uenoku
Copy link
Member

uenoku commented May 7, 2024

Thank you for doing this! Please feel free to merge HWLegalizeModule change.

@hovind hovind force-pushed the dev/hovind/flatten-io-arrays branch from 68da07a to ea6569b Compare May 9, 2024 12:33
@teqdruid
Copy link
Contributor

I don't think ArrayType in I/O has been an issue for us yet.

Lowering an Array of channels is actually something I was working on recently. In that case, it's not so much flattening as lowering to Arrays of data/valid/ready signals.

Good catch; there's actually no test for lowering ESI channels to HW inside test/Dialect/ESI/lowering.mlir, which should definitely be added (CC @teqdruid).

There is:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants