CIRCT  19.0.0git
Public Member Functions | Private Member Functions | Private Attributes | List of all members
circt::firrtl::NLATable Class Reference

This table tracks nlas and what modules participate in them. More...

#include <NLATable.h>

Collaboration diagram for circt::firrtl::NLATable:
Collaboration graph
[legend]

Public Member Functions

 NLATable (Operation *operation)
 Create a new NLA table of a circuit. More...
 
ArrayRef< hw::HierPathOp > lookup (Operation *op)
 Lookup all NLAs an operation participates in. More...
 
ArrayRef< hw::HierPathOp > lookup (StringAttr name)
 Lookup all NLAs an operation participates in. More...
 
hw::HierPathOp getNLA (StringAttr name)
 Resolve a symbol to an NLA. More...
 
FModuleLike getModule (StringAttr name)
 Resolve a symbol to a Module. More...
 
void commonNLAs (StringAttr mod1, StringAttr mod2, DenseSet< hw::HierPathOp > &common)
 Compute the NLAs that are common between the two modules, mod1 and mod2 and insert them into the set common. More...
 
void getInstanceNLAs (InstanceOp inst, DenseSet< hw::HierPathOp > &nlas)
 Get the NLAs that the InstanceOp participates in, insert it to the DenseSet nlas. More...
 
void getNLAsInModule (StringAttr modName, DenseSet< hw::HierPathOp > &nlas)
 Get the NLAs that the module modName particiaptes in, and insert them into the DenseSet nlas. More...
 
void addNLA (hw::HierPathOp nla)
 Insert a new NLA. More...
 
void erase (hw::HierPathOp nlaOp, SymbolTable *symbolTable=nullptr)
 Remove the NLA from the analysis. More...
 
void addModule (FModuleLike mod)
 Record a new FModuleLike operation. More...
 
void eraseModule (StringAttr name)
 Stop tracking a module. More...
 
void updateModuleInNLA (StringAttr nlaName, StringAttr oldModule, StringAttr newModule)
 Replace the module oldModule with newModule in the namepath of the nla nlaName. More...
 
void updateModuleInNLA (hw::HierPathOp nlaOp, StringAttr oldModule, StringAttr newModule)
 Replace the module oldModule with newModule in the namepath of the nla nlaOp. More...
 
void renameModule (StringAttr oldModName, StringAttr newModName)
 Rename a module, this updates the name to module tracking and the name to NLA tracking. More...
 
void renameModuleAndInnerRef (StringAttr newModName, StringAttr oldModName, const DenseMap< StringAttr, StringAttr > &innerSymRenameMap)
 Replace the module oldModName with newModName in the namepath of any NLA. More...
 
void removeNLAfromModule (hw::HierPathOp nla, StringAttr mod)
 Remove the NLA from the Module. More...
 
void removeNLAsfromModule (const DenseSet< hw::HierPathOp > &nlas, StringAttr mod)
 Remove all the nlas in the set nlas from the module. More...
 
void addNLAtoModule (hw::HierPathOp nla, StringAttr mod)
 Add the nla to the module. More...
 

Private Member Functions

 NLATable (const NLATable &)=delete
 

Private Attributes

llvm::DenseMap< StringAttr, SmallVector< hw::HierPathOp, 4 > > nodeMap
 Map modules to the NLA's that target them. More...
 
llvm::DenseMap< StringAttr, Operation * > symToOp
 Map symbol names to module and NLA operations. More...
 

Detailed Description

This table tracks nlas and what modules participate in them.

To use this class, retrieve a cached copy from the analysis manager: auto &nlaTable = getAnalysis<NLATable>(getOperation());

Definition at line 29 of file NLATable.h.

Constructor & Destructor Documentation

◆ NLATable() [1/2]

NLATable::NLATable ( Operation *  operation)
explicit

Create a new NLA table of a circuit.

This must be called on a FIRRTL CircuitOp or MLIR ModuleOp. To ensure that the analysis does not return stale data while a pass is running, it should be kept up-to-date when modules are added or renamed and NLAs are updated.

Definition at line 17 of file NLATable.cpp.

References addNLA(), and symToOp.

◆ NLATable() [2/2]

circt::firrtl::NLATable::NLATable ( const NLATable )
privatedelete

Member Function Documentation

◆ addModule()

void circt::firrtl::NLATable::addModule ( FModuleLike  mod)
inline

Record a new FModuleLike operation.

This updates the Module name to Module operation map.

Definition at line 125 of file NLATable.h.

References symToOp.

◆ addNLA()

void NLATable::addNLA ( hw::HierPathOp  nla)

Insert a new NLA.

This updates two internal records,

  1. Update the map for the nlaOp name to the Operation.
  2. For each module in the NLA namepath, insert the NLA into the list of hwHierPathOps that participate in the corresponding module. This does not update the module name to module op map, if any potentially new module in the namepath does not already exist in the record.

Definition at line 58 of file NLATable.cpp.

References nodeMap, and symToOp.

Referenced by NLATable().

◆ addNLAtoModule()

void circt::firrtl::NLATable::addNLAtoModule ( hw::HierPathOp  nla,
StringAttr  mod 
)
inline

Add the nla to the module.

This ensures that the list of NLAs that the module participates in is updated. This will be required if mod is added to the namepath of nla.

Definition at line 182 of file NLATable.h.

References nodeMap.

◆ commonNLAs()

void circt::firrtl::NLATable::commonNLAs ( StringAttr  mod1,
StringAttr  mod2,
DenseSet< hw::HierPathOp > &  common 
)
inline

Compute the NLAs that are common between the two modules, mod1 and mod2 and insert them into the set common.

The set of NLAs that an instance op participates in is the set of common NLAs between the parent module and the instance target. This can be used to get the set of NLAs that an InstanceOp participates in, instead of recording them on the op in the IR.

Definition at line 60 of file NLATable.h.

References lookup().

Referenced by getInstanceNLAs().

◆ erase()

void NLATable::erase ( hw::HierPathOp  nlaOp,
SymbolTable *  symbolTable = nullptr 
)

Remove the NLA from the analysis.

This updates two internal records,

  1. Remove the NLA name to the operation map entry.
  2. For each module in the namepath of the NLA, remove the entry from the list of NLAs that the module participates in. Note that this invalidates any reference to the NLA list returned by 'lookup'.

Definition at line 68 of file NLATable.cpp.

References nodeMap, and symToOp.

◆ eraseModule()

void circt::firrtl::NLATable::eraseModule ( StringAttr  name)
inline

Stop tracking a module.

Remove the module from two internal records,

  1. Module name to Module op map.
  2. Module name to list of NLAs that the module participates in.

Definition at line 130 of file NLATable.h.

References nodeMap, and symToOp.

◆ getInstanceNLAs()

void circt::firrtl::NLATable::getInstanceNLAs ( InstanceOp  inst,
DenseSet< hw::HierPathOp > &  nlas 
)
inline

Get the NLAs that the InstanceOp participates in, insert it to the DenseSet nlas.

Definition at line 71 of file NLATable.h.

References commonNLAs(), and circt::firrtl::getInnerSymName().

◆ getModule()

FModuleLike NLATable::getModule ( StringAttr  name)

Resolve a symbol to a Module.

Definition at line 53 of file NLATable.cpp.

References symToOp.

Referenced by ResolveTracesPass::updateModuleTarget(), and ResolveTracesPass::updateTargetImpl().

◆ getNLA()

hw::HierPathOp NLATable::getNLA ( StringAttr  name)

Resolve a symbol to an NLA.

Definition at line 48 of file NLATable.cpp.

References symToOp.

Referenced by updateModuleInNLA(), ResolveTracesPass::updateModuleTarget(), and ResolveTracesPass::updateTargetImpl().

◆ getNLAsInModule()

void circt::firrtl::NLATable::getNLAsInModule ( StringAttr  modName,
DenseSet< hw::HierPathOp > &  nlas 
)
inline

Get the NLAs that the module modName particiaptes in, and insert them into the DenseSet nlas.

Definition at line 94 of file NLATable.h.

References lookup().

◆ lookup() [1/2]

ArrayRef< hw::HierPathOp > NLATable::lookup ( Operation *  op)

Lookup all NLAs an operation participates in.

This returns a reference to the internal record, so make a copy before making any update to the NLATable.

Definition at line 41 of file NLATable.cpp.

Referenced by commonNLAs(), getNLAsInModule(), and renameModuleAndInnerRef().

◆ lookup() [2/2]

ArrayRef< hw::HierPathOp > NLATable::lookup ( StringAttr  name)

Lookup all NLAs an operation participates in.

This returns a reference to the internal record, so make a copy before making any update to the NLATable.

Definition at line 34 of file NLATable.cpp.

References nodeMap.

◆ removeNLAfromModule()

void circt::firrtl::NLATable::removeNLAfromModule ( hw::HierPathOp  nla,
StringAttr  mod 
)
inline

Remove the NLA from the Module.

This updates the module name to NLA tracking.

Definition at line 167 of file NLATable.h.

References nodeMap.

◆ removeNLAsfromModule()

void circt::firrtl::NLATable::removeNLAsfromModule ( const DenseSet< hw::HierPathOp > &  nlas,
StringAttr  mod 
)
inline

Remove all the nlas in the set nlas from the module.

This updates the module name to NLA tracking.

Definition at line 173 of file NLATable.h.

References nodeMap.

◆ renameModule()

void NLATable::renameModule ( StringAttr  oldModName,
StringAttr  newModName 
)

Rename a module, this updates the name to module tracking and the name to NLA tracking.

This moves all the NLAs that oldModName is participating in to the newModName. The oldModName must exist in the name to module record. This also removes all the entries for oldModName.

Definition at line 100 of file NLATable.cpp.

References nodeMap, and symToOp.

◆ renameModuleAndInnerRef()

void NLATable::renameModuleAndInnerRef ( StringAttr  newModName,
StringAttr  oldModName,
const DenseMap< StringAttr, StringAttr > &  innerSymRenameMap 
)

Replace the module oldModName with newModName in the namepath of any NLA.

Since the module is being updated, the symbols inside the module should also be renamed. Use the rename map innerSymRenameMap to update the inner_sym names in the namepath.

Definition at line 115 of file NLATable.cpp.

References lookup(), and nodeMap.

◆ updateModuleInNLA() [1/2]

void NLATable::updateModuleInNLA ( hw::HierPathOp  nlaOp,
StringAttr  oldModule,
StringAttr  newModule 
)

Replace the module oldModule with newModule in the namepath of the nla nlaOp.

This moves the nla from the list of oldModule to newModule. Move nlaOp from the list of NLAs that oldModule participates in to newModule. This can delete and invalidate any reference returned by lookup.

Definition at line 79 of file NLATable.cpp.

References nodeMap.

◆ updateModuleInNLA() [2/2]

void NLATable::updateModuleInNLA ( StringAttr  nlaName,
StringAttr  oldModule,
StringAttr  newModule 
)

Replace the module oldModule with newModule in the namepath of the nla nlaName.

This moves the nla from the list of oldModule to newModule. Move nlaName from the list of NLAs that oldModule participates in to newModule. This can delete and invalidate any reference returned by lookup.

Definition at line 92 of file NLATable.cpp.

References getNLA().

Member Data Documentation

◆ nodeMap

llvm::DenseMap<StringAttr, SmallVector<hw::HierPathOp, 4> > circt::firrtl::NLATable::nodeMap
private

Map modules to the NLA's that target them.

Definition at line 190 of file NLATable.h.

Referenced by addNLA(), addNLAtoModule(), erase(), eraseModule(), lookup(), removeNLAfromModule(), removeNLAsfromModule(), renameModule(), renameModuleAndInnerRef(), and updateModuleInNLA().

◆ symToOp

llvm::DenseMap<StringAttr, Operation *> circt::firrtl::NLATable::symToOp
private

Map symbol names to module and NLA operations.

Definition at line 193 of file NLATable.h.

Referenced by addModule(), addNLA(), erase(), eraseModule(), getModule(), getNLA(), NLATable(), and renameModule().


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