|
CIRCT 23.0.0git
|
Iterative Tarjan SCC analysis on a sparse subgraph of MLIR operations. More...
#include <SparseOpSCC.h>

Classes | |
| struct | BackwardFrame |
| struct | ForwardFrame |
Public Member Functions | |
| SparseOpSCC (OpSCCFilter shouldTraverseFn={}) | |
| void | reset () |
| Clear all accumulated state. | |
| void | visit (mlir::Operation *op) |
Seed op into the DFS if it has not already been discovered. | |
| void | visit (llvm::ArrayRef< mlir::Operation * > ops) |
Visit each operation in ops, skipping already-discovered ones. | |
| bool | hasDiscovered (mlir::Operation *op) const |
Return true if op was discovered (as a seed or transitively) by any previous visit() call. | |
| OpSCC | getSCC (mlir::Operation *op) const |
Return the SCC that op belongs to. | |
| unsigned | getNumDiscovered () const |
| Number of operations discovered so far across all visit() calls. | |
| unsigned | getNumSCCs () const |
| Total number of SCC entries emitted (trivial ops + cyclic groups). | |
| unsigned | getNumCyclicSCCs () const |
| Number of cyclic SCC groups (excludes trivial ops). | |
| auto | topological () const |
| Iterate over SCCs in topological order (sources/seeds first, leaves last). | |
| auto | topological_begin () const |
| auto | topological_end () const |
| auto | reverseTopological () const |
| Iterate over SCCs in reverse topological order (leaves first). | |
| auto | reverseTopological_begin () const |
| auto | reverseTopological_end () const |
Private Types | |
| using | FrameT = std::conditional_t< Direction==OpSCCDirection::Forward, ForwardFrame, BackwardFrame > |
Private Member Functions | |
| void | tarjanImpl (mlir::Operation *startOp) |
Private Attributes | |
| OpSCCFilter | shouldTraverseFn |
| Optional edge filter supplied at construction time. | |
| llvm::SmallDenseMap< mlir::Operation *, unsigned, NumInlineElts > | opToSccIndex |
Maps each visited op to the index of its SCC in sccs. | |
| llvm::SmallVector< detail::OpOrIndex, NumInlineElts > | sccs |
| Flat list of SCC entries emitted by Tarjan, in emission order. | |
| llvm::SmallVector< detail::CyclicOpSCCStorage, 0 > | cyclicSccs |
| Backing storage for cyclic SCCs; CyclicOpSCC holds a pointer into here. | |
Iterative Tarjan SCC analysis on a sparse subgraph of MLIR operations.
Call visit() with one or more seed operations to trigger the DFS. Results accumulate across multiple visit() calls, so the discovered subgraph can be expanded incrementally.
The optional filter passed to the constructor is applied to every discovered edge before it is traversed. An edge that fails the filter is treated as if it did not exist in the graph.
Iterators obtained from topological() and reverseTopological() hold a reference into this object and are invalidated by calling visit() or
Definition at line 270 of file SparseOpSCC.h.
|
private |
Definition at line 425 of file SparseOpSCC.h.
|
inlineexplicit |
Definition at line 272 of file SparseOpSCC.h.
|
inline |
Number of cyclic SCC groups (excludes trivial ops).
Definition at line 318 of file SparseOpSCC.h.
References circt::SparseOpSCC< Direction, NumInlineElts >::cyclicSccs.
|
inline |
Number of operations discovered so far across all visit() calls.
Definition at line 314 of file SparseOpSCC.h.
References circt::SparseOpSCC< Direction, NumInlineElts >::opToSccIndex.
|
inline |
Total number of SCC entries emitted (trivial ops + cyclic groups).
Definition at line 316 of file SparseOpSCC.h.
References circt::SparseOpSCC< Direction, NumInlineElts >::sccs.
|
inline |
Return the SCC that op belongs to.
If the operation has not been discovered, it returns a nullptr sentinel.
Definition at line 302 of file SparseOpSCC.h.
References circt::SparseOpSCC< Direction, NumInlineElts >::cyclicSccs, circt::SparseOpSCC< Direction, NumInlineElts >::opToSccIndex, and circt::SparseOpSCC< Direction, NumInlineElts >::sccs.
|
inline |
Return true if op was discovered (as a seed or transitively) by any previous visit() call.
Definition at line 296 of file SparseOpSCC.h.
References circt::SparseOpSCC< Direction, NumInlineElts >::opToSccIndex.
|
inline |
Clear all accumulated state.
Definition at line 276 of file SparseOpSCC.h.
References circt::SparseOpSCC< Direction, NumInlineElts >::cyclicSccs, circt::SparseOpSCC< Direction, NumInlineElts >::opToSccIndex, and circt::SparseOpSCC< Direction, NumInlineElts >::sccs.
|
inline |
Iterate over SCCs in reverse topological order (leaves first).
Definition at line 348 of file SparseOpSCC.h.
References circt::SparseOpSCC< Direction, NumInlineElts >::reverseTopological_begin(), and circt::SparseOpSCC< Direction, NumInlineElts >::reverseTopological_end().
|
inline |
Definition at line 354 of file SparseOpSCC.h.
References circt::SparseOpSCC< Direction, NumInlineElts >::cyclicSccs, circt::Forward, and circt::SparseOpSCC< Direction, NumInlineElts >::sccs.
Referenced by circt::SparseOpSCC< Direction, NumInlineElts >::reverseTopological().
|
inline |
Definition at line 365 of file SparseOpSCC.h.
References circt::SparseOpSCC< Direction, NumInlineElts >::cyclicSccs, circt::Forward, and circt::SparseOpSCC< Direction, NumInlineElts >::sccs.
Referenced by circt::SparseOpSCC< Direction, NumInlineElts >::reverseTopological().
|
inlineprivate |
Definition at line 428 of file SparseOpSCC.h.
References assert(), circt::SparseOpSCC< Direction, NumInlineElts >::cyclicSccs, circt::SparseOpSCC< Direction, NumInlineElts >::opToSccIndex, circt::SparseOpSCC< Direction, NumInlineElts >::sccs, and circt::SparseOpSCC< Direction, NumInlineElts >::shouldTraverseFn.
Referenced by circt::SparseOpSCC< Direction, NumInlineElts >::visit().
|
inline |
Iterate over SCCs in topological order (sources/seeds first, leaves last).
Definition at line 321 of file SparseOpSCC.h.
References circt::SparseOpSCC< Direction, NumInlineElts >::topological_begin(), and circt::SparseOpSCC< Direction, NumInlineElts >::topological_end().
|
inline |
Definition at line 326 of file SparseOpSCC.h.
References circt::Backward, circt::SparseOpSCC< Direction, NumInlineElts >::cyclicSccs, and circt::SparseOpSCC< Direction, NumInlineElts >::sccs.
Referenced by circt::SparseOpSCC< Direction, NumInlineElts >::topological().
|
inline |
Definition at line 337 of file SparseOpSCC.h.
References circt::Backward, circt::SparseOpSCC< Direction, NumInlineElts >::cyclicSccs, and circt::SparseOpSCC< Direction, NumInlineElts >::sccs.
Referenced by circt::SparseOpSCC< Direction, NumInlineElts >::topological().
|
inline |
Visit each operation in ops, skipping already-discovered ones.
Definition at line 289 of file SparseOpSCC.h.
References circt::SparseOpSCC< Direction, NumInlineElts >::visit().
|
inline |
Seed op into the DFS if it has not already been discovered.
Definition at line 283 of file SparseOpSCC.h.
References circt::SparseOpSCC< Direction, NumInlineElts >::opToSccIndex, and circt::SparseOpSCC< Direction, NumInlineElts >::tarjanImpl().
Referenced by circt::SparseOpSCC< Direction, NumInlineElts >::visit().
|
private |
Backing storage for cyclic SCCs; CyclicOpSCC holds a pointer into here.
Definition at line 519 of file SparseOpSCC.h.
Referenced by circt::SparseOpSCC< Direction, NumInlineElts >::getNumCyclicSCCs(), circt::SparseOpSCC< Direction, NumInlineElts >::getSCC(), circt::SparseOpSCC< Direction, NumInlineElts >::reset(), circt::SparseOpSCC< Direction, NumInlineElts >::reverseTopological_begin(), circt::SparseOpSCC< Direction, NumInlineElts >::reverseTopological_end(), circt::SparseOpSCC< Direction, NumInlineElts >::tarjanImpl(), circt::SparseOpSCC< Direction, NumInlineElts >::topological_begin(), and circt::SparseOpSCC< Direction, NumInlineElts >::topological_end().
|
private |
Maps each visited op to the index of its SCC in sccs.
Persists across visit() calls and is the authoritative "already visited" guard.
Definition at line 513 of file SparseOpSCC.h.
Referenced by circt::SparseOpSCC< Direction, NumInlineElts >::getNumDiscovered(), circt::SparseOpSCC< Direction, NumInlineElts >::getSCC(), circt::SparseOpSCC< Direction, NumInlineElts >::hasDiscovered(), circt::SparseOpSCC< Direction, NumInlineElts >::reset(), circt::SparseOpSCC< Direction, NumInlineElts >::tarjanImpl(), and circt::SparseOpSCC< Direction, NumInlineElts >::visit().
|
private |
Flat list of SCC entries emitted by Tarjan, in emission order.
Trivial SCCs are stored directly. Cyclic SCCs are stored as index into the cyclicSccs vector.
Definition at line 517 of file SparseOpSCC.h.
Referenced by circt::SparseOpSCC< Direction, NumInlineElts >::getNumSCCs(), circt::SparseOpSCC< Direction, NumInlineElts >::getSCC(), circt::SparseOpSCC< Direction, NumInlineElts >::reset(), circt::SparseOpSCC< Direction, NumInlineElts >::reverseTopological_begin(), circt::SparseOpSCC< Direction, NumInlineElts >::reverseTopological_end(), circt::SparseOpSCC< Direction, NumInlineElts >::tarjanImpl(), circt::SparseOpSCC< Direction, NumInlineElts >::topological_begin(), and circt::SparseOpSCC< Direction, NumInlineElts >::topological_end().
|
private |
Optional edge filter supplied at construction time.
Definition at line 509 of file SparseOpSCC.h.
Referenced by circt::SparseOpSCC< Direction, NumInlineElts >::ForwardFrame::nextChild(), circt::SparseOpSCC< Direction, NumInlineElts >::BackwardFrame::nextChild(), and circt::SparseOpSCC< Direction, NumInlineElts >::tarjanImpl().