CIRCT  19.0.0git
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | List of all members
circt::igraph::InstanceGraph Class Reference

This graph tracks modules and where they are instantiated. More...

#include <InstanceGraph.h>

Inheritance diagram for circt::igraph::InstanceGraph:
Inheritance graph
[legend]
Collaboration diagram for circt::igraph::InstanceGraph:
Collaboration graph
[legend]

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
 
InstanceGraphNodelookup (ModuleOpInterface op)
 Look up an InstanceGraphNode for a module. More...
 
InstanceGraphNodelookup (StringAttr name)
 Lookup an module by name. More...
 
InstanceGraphNodeoperator[] (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 InstanceGraphNodegetTopLevelNode ()
 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 InstanceGraphNodeaddModule (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)
 
InstanceGraphNodegetOrAddNode (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...
 

Detailed Description

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.

Member Typedef Documentation

◆ iterator

Iterate through all modules.

Definition at line 234 of file InstanceGraph.h.

◆ NodeList

This is the list of InstanceGraphNodes in the graph.

Definition at line 194 of file InstanceGraph.h.

Constructor & Destructor Documentation

◆ InstanceGraph() [1/2]

circt::igraph::InstanceGraph::InstanceGraph ( Operation *  parent)

Create a new module graph of a circuit.

Must be called on the parent operation of ModuleOpInterface ops.

◆ InstanceGraph() [2/2]

circt::igraph::InstanceGraph::InstanceGraph ( const InstanceGraph )
delete

◆ ~InstanceGraph()

virtual circt::igraph::InstanceGraph::~InstanceGraph ( )
virtualdefault

Member Function Documentation

◆ addModule()

InstanceGraphNode * InstanceGraph::addModule ( ModuleOpInterface  module)
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().

◆ begin()

iterator circt::igraph::InstanceGraph::begin ( )
inline

◆ end()

iterator circt::igraph::InstanceGraph::end ( )
inline

◆ erase()

virtual void circt::igraph::InstanceGraph::erase ( InstanceGraphNode node)
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().

◆ getInferredTopLevelNodes()

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.

◆ getOrAddNode()

InstanceGraphNode * InstanceGraph::getOrAddNode ( StringAttr  name)
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.

References nodeMap, and nodes.

◆ getParent()

Operation* circt::igraph::InstanceGraph::getParent ( )
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().

◆ getReferencedModuleImpl()

ModuleOpInterface circt::igraph::InstanceGraph::getReferencedModuleImpl ( InstanceOpInterface  op)
protected

◆ getSublistAccess()

static NodeList InstanceGraph::* circt::igraph::InstanceGraph::getSublistAccess ( Operation *  )
inlinestatic

Returns pointer to member of operation list.

Definition at line 229 of file InstanceGraph.h.

References nodes.

◆ getTopLevelNode()

virtual InstanceGraphNode* circt::igraph::InstanceGraph::getTopLevelNode ( )
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().

◆ isAncestor()

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().

◆ lookup() [1/2]

InstanceGraphNode * InstanceGraph::lookup ( ModuleOpInterface  op)

◆ lookup() [2/2]

InstanceGraphNode * InstanceGraph::lookup ( StringAttr  name)

Lookup an module by name.

Definition at line 109 of file InstanceGraph.cpp.

References assert(), and nodeMap.

◆ operator[]()

InstanceGraphNode* circt::igraph::InstanceGraph::operator[] ( ModuleOpInterface  op)
inline

Lookup an InstanceGraphNode for a module.

Definition at line 210 of file InstanceGraph.h.

References lookup().

◆ replaceInstance()

void InstanceGraph::replaceInstance ( InstanceOpInterface  inst,
InstanceOpInterface  newInst 
)
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().

Member Data Documentation

◆ inferredTopLevelNodes

llvm::SmallVector<InstanceGraphNode *> circt::igraph::InstanceGraph::inferredTopLevelNodes
protected

A caching of the inferred top level module(s).

Definition at line 276 of file InstanceGraph.h.

Referenced by getInferredTopLevelNodes().

◆ nodeMap

llvm::DenseMap<Attribute, InstanceGraphNode *> circt::igraph::InstanceGraph::nodeMap
protected

This maps each operation to its graph node.

Definition at line 273 of file InstanceGraph.h.

Referenced by addModule(), getOrAddNode(), and lookup().

◆ nodes

NodeList circt::igraph::InstanceGraph::nodes
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().

◆ parent

Operation* circt::igraph::InstanceGraph::parent
protected

The node under which all modules are nested.

Definition at line 267 of file InstanceGraph.h.

Referenced by getParent(), and isAncestor().


The documentation for this class was generated from the following files: