CIRCT
20.0.0git
|
This graph tracks modules and where they are instantiated. More...
#include <InstanceGraph.h>
Public Types | |
using | iterator = detail::AddressIterator< NodeList::iterator > |
Iterate through all modules. More... | |
Public Member Functions | |
InstanceGraph (Operation *parent) | |
Create a new module graph of a circuit. More... | |
InstanceGraph (const InstanceGraph &)=delete | |
virtual | ~InstanceGraph ()=default |
InstanceGraphNode * | lookup (ModuleOpInterface op) |
Look up an InstanceGraphNode for a module. More... | |
InstanceGraphNode * | lookup (StringAttr name) |
Lookup an module by name. More... | |
InstanceGraphNode * | operator[] (ModuleOpInterface op) |
Lookup an InstanceGraphNode for a module. More... | |
bool | isAncestor (ModuleOpInterface child, ModuleOpInterface parent, llvm::function_ref< bool(InstanceRecord *)> skipInstance=[](InstanceRecord *_) { return false;}) |
Check if child is instantiated by a parent. More... | |
virtual InstanceGraphNode * | getTopLevelNode () |
Get the node corresponding to the top-level module of a circuit. More... | |
FailureOr< llvm::ArrayRef< InstanceGraphNode * > > | getInferredTopLevelNodes () |
Get the nodes corresponding to the inferred top-level modules of a circuit. More... | |
Operation * | getParent () |
Return the parent under which all nodes are nested. More... | |
iterator | begin () |
iterator | end () |
virtual InstanceGraphNode * | addModule (ModuleOpInterface module) |
Add a newly created module to the instance graph. More... | |
virtual void | erase (InstanceGraphNode *node) |
Remove this module from the instance graph. More... | |
virtual void | replaceInstance (InstanceOpInterface inst, InstanceOpInterface newInst) |
Replaces an instance of a module with another instance. More... | |
Static Public Member Functions | |
static NodeList InstanceGraph::* | getSublistAccess (Operation *) |
Returns pointer to member of operation list. More... | |
Protected Member Functions | |
ModuleOpInterface | getReferencedModuleImpl (InstanceOpInterface op) |
InstanceGraphNode * | getOrAddNode (StringAttr name) |
Get the node corresponding to the module. More... | |
Protected Attributes | |
Operation * | parent |
The node under which all modules are nested. More... | |
NodeList | nodes |
The storage for graph nodes, with deterministic iteration. More... | |
llvm::DenseMap< Attribute, InstanceGraphNode * > | nodeMap |
This maps each operation to its graph node. More... | |
llvm::SmallVector< InstanceGraphNode * > | inferredTopLevelNodes |
A caching of the inferred top level module(s). More... | |
Private Types | |
using | NodeList = llvm::iplist< InstanceGraphNode > |
This is the list of InstanceGraphNodes in the graph. More... | |
This graph tracks modules and where they are instantiated.
This is intended to be used as a cached analysis on circuits. This class can be used to walk the modules efficiently in a bottom-up or top-down order.
To use this class, retrieve a cached copy from the analysis manager: auto &instanceGraph = getAnalysis<InstanceGraph>(getOperation());
Definition at line 192 of file InstanceGraph.h.
using circt::igraph::InstanceGraph::iterator = detail::AddressIterator<NodeList::iterator> |
Iterate through all modules.
Definition at line 234 of file InstanceGraph.h.
|
private |
This is the list of InstanceGraphNodes in the graph.
Definition at line 194 of file InstanceGraph.h.
circt::igraph::InstanceGraph::InstanceGraph | ( | Operation * | parent | ) |
Create a new module graph of a circuit.
Must be called on the parent operation of ModuleOpInterface ops.
|
delete |
|
virtualdefault |
|
virtual |
Add a newly created module to the instance graph.
Definition at line 90 of file InstanceGraph.cpp.
References assert(), nodeMap, and nodes.
Referenced by circt::hw::InstanceGraph::addHWModule().
|
inline |
Definition at line 235 of file InstanceGraph.h.
References nodes.
Referenced by getInferredTopLevelNodes(), and llvm::GraphTraits< circt::igraph::InstanceGraph * >::nodes_begin().
|
inline |
Definition at line 236 of file InstanceGraph.h.
References nodes.
Referenced by getInferredTopLevelNodes(), and llvm::GraphTraits< circt::igraph::InstanceGraph * >::nodes_end().
|
virtual |
Remove this module from the instance graph.
This will also remove all InstanceRecords in this module. All instances of this module must have been removed from the graph.
Reimplemented in circt::hw::InstanceGraph.
Referenced by circt::hw::InstanceGraph::erase().
FailureOr< llvm::ArrayRef< InstanceGraphNode * > > InstanceGraph::getInferredTopLevelNodes | ( | ) |
Get the nodes corresponding to the inferred top-level modules of a circuit.
Topologically sort the instance graph.
Definition at line 166 of file InstanceGraph.cpp.
References assert(), begin(), end(), circt::igraph::InstanceGraphNode::getModule(), getParent(), and inferredTopLevelNodes.
|
protected |
Get the node corresponding to the module.
If the node has does not exist yet, it will be created.
Definition at line 43 of file InstanceGraph.cpp.
|
inline |
Return the parent under which all nodes are nested.
Definition at line 226 of file InstanceGraph.h.
References parent.
Referenced by getInferredTopLevelNodes(), and circt::firrtl::InstanceGraph::InstanceGraph().
|
protected |
|
inlinestatic |
Returns pointer to member of operation list.
Definition at line 229 of file InstanceGraph.h.
References nodes.
|
inlinevirtual |
Get the node corresponding to the top-level module of a circuit.
Reimplemented in circt::hw::InstanceGraph, and circt::firrtl::InstanceGraph.
Definition at line 219 of file InstanceGraph.h.
Referenced by llvm::GraphTraits< circt::igraph::InstanceGraph * >::getEntryNode().
bool InstanceGraph::isAncestor | ( | ModuleOpInterface | child, |
ModuleOpInterface | parent, | ||
llvm::function_ref< bool(InstanceRecord *)> | skipInstance = [](InstanceRecord *_) { return false; } |
||
) |
Check if child is instantiated by a parent.
Definition at line 139 of file InstanceGraph.cpp.
References circt::igraph::InstanceGraphNode::getModule(), lookup(), parent, and circt::igraph::InstanceGraphNode::uses().
InstanceGraphNode * InstanceGraph::lookup | ( | ModuleOpInterface | op | ) |
Look up an InstanceGraphNode for a module.
Definition at line 115 of file InstanceGraph.cpp.
Referenced by circt::firrtl::addPortsToModule(), circt::firrtl::InstanceGraph::InstanceGraph(), isAncestor(), circt::firrtl::OwningModuleCache::lookup(), lowerInternalPathAnno(), operator[](), and replaceInstance().
InstanceGraphNode * InstanceGraph::lookup | ( | StringAttr | name | ) |
Lookup an module by name.
Definition at line 109 of file InstanceGraph.cpp.
|
inline |
Lookup an InstanceGraphNode for a module.
Definition at line 210 of file InstanceGraph.h.
References lookup().
|
virtual |
Replaces an instance of a module with another instance.
The target module of both InstanceOps must be the same.
Definition at line 119 of file InstanceGraph.cpp.
References assert(), lookup(), and circt::igraph::InstanceGraphNode::uses().
Referenced by updateInstanceInModule().
|
protected |
A caching of the inferred top level module(s).
Definition at line 276 of file InstanceGraph.h.
Referenced by getInferredTopLevelNodes().
|
protected |
This maps each operation to its graph node.
Definition at line 273 of file InstanceGraph.h.
Referenced by addModule(), getOrAddNode(), and lookup().
|
protected |
The storage for graph nodes, with deterministic iteration.
Definition at line 270 of file InstanceGraph.h.
Referenced by addModule(), begin(), end(), getOrAddNode(), getSublistAccess(), and circt::hw::InstanceGraph::InstanceGraph().
|
protected |
The node under which all modules are nested.
Definition at line 267 of file InstanceGraph.h.
Referenced by getParent(), and isAncestor().