This is a thought I’ve been toying with and mentioned before, so I want to start a discussion thread. It’s not really an RFC yet, but I am happy to make a full proposal if the gist of what I’m talking about seems generally useful.
There are situations where we may want to lower the arithmetic and binary operations in the Standard dialect into corresponding operations in combinational logic. For example
std.addi gets lowered to
firrtl.add in HandshakeToFIRRTL, as do several other operations. Another example is related to the work to lower SCFToCalyx, which has a need to convert Standard operations into something Calyx understands. A proposal is to create a library of Calyx primitives (which is what the existing Rust compiler does).
My thought is we could approach this how Linalg does it. Specifically, I’m talking about one of the properties of structured linalg ops: “Property 5: May Map To an External Library Call”. A structured Linalg op can be lowered into a well-defined loop nest and standard operations, or it can be lowered into a library call. The analogy in CIRCT would be to lower Standard operations into Comb logic, or a set of primitives.
To roughly sketch how this could work, I’m imagining a library with a bunch of RewritePatterns for converting Standard ops we care about into Comb ops. It would also have a mechanism to register primitives to lower into (which could also be accomplished with RewritePatterns, for example). We could expose a function to run the conversion, which would either use the primitives or fall back to generating Comb logic. This could be put into a standalone
-lower-standard pass, or used directly by other things that need it.
Besides just lowering, such a library could provide other important information about what the operations lower into. For example, implementations (either in Comb or primitives) could have an associated latency, which the Scheduling infrastructure could query.
Any thoughts or feedback welcome. I’m hoping this could be useful for several things in tree: HandshakeToFIRRTL, SCFToCalyx, and upcoming Scheduling work.