circt
circt copied to clipboard
[firrtl] Add Connection Graph
Add iterators for walking connections in FIRRTL. This adds two levels of iterators:
-
A ConnectionIterator which wraps an inner iterator (2)
-
One of several types of iterators specialized to handle FIRRTL operations:
a. A FModuleOpIterator for walking all operations inside a module. (This acts like a "root node" that is the parent of everything.)
b. A FConnectLikeIterator for walking connection destinations.
c. A ResultIterator for generically walking results. (This is the default walker for everything that isn't a connect, e.g., instances and memories fall into this category.)
GraphTraits for FIRRTLOperations (just an mlir::Operation) are then added that iterate using the ConnectionIterator.
This is heavily inspired by the old @hanchenye approach for CheckCombCycles patch: https://github.com/llvm/circt/pull/1388
For how this is intended to be used, see: https://github.com/llvm/circt/pull/6492 Because graph traits are provided, scc_iterator can then be used to compute SCCs of FIRRTL operations in a module. This has been tested to be "fast" on internal designs (it runs with the same speed as other passes that traverse the complete IR of every module in parallel).
This is currently deficient for aggregate connections. Specifically, this will not properly compute SCCs for connections involving destinations that are subaccess/subfield/subindex operations of aggregates. I have some ideas on how to fix this... I'd like to land this version (which works for anything where all internal flips and types are lowered).