12 #ifndef CIRCT_DIALECT_FIRRTL_NLATABLE_H
13 #define CIRCT_DIALECT_FIRRTL_NLATABLE_H
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/ADT/SetOperations.h"
20 #include "llvm/ADT/iterator.h"
36 explicit NLATable(Operation *operation);
41 ArrayRef<hw::HierPathOp>
lookup(Operation *op);
46 ArrayRef<hw::HierPathOp>
lookup(StringAttr name);
49 hw::HierPathOp
getNLA(StringAttr name);
61 DenseSet<hw::HierPathOp> &common) {
62 auto mod1NLAs =
lookup(mod1);
63 auto mod2NLAs =
lookup(mod2);
64 common.insert(mod1NLAs.begin(), mod1NLAs.end());
65 DenseSet<hw::HierPathOp> set2(mod2NLAs.begin(), mod2NLAs.end());
66 llvm::set_intersect(common, set2);
77 auto mod = inst->getParentOfType<FModuleOp>().getNameAttr();
81 commonNLAs(inst->getParentOfType<FModuleOp>().getNameAttr(),
82 inst.getModuleNameAttr().getAttr(), nlas);
86 for (
auto nla : llvm::make_early_inc_range(nlas)) {
87 if (!nla.hasInnerSym(mod, instSym))
95 for (
auto nla :
lookup(modName))
113 void addNLA(hw::HierPathOp nla);
121 void erase(hw::HierPathOp nlaOp, SymbolTable *symbolTable =
nullptr);
141 StringAttr newModule);
149 StringAttr newModule);
155 void renameModule(StringAttr oldModName, StringAttr newModName);
162 StringAttr newModName, StringAttr oldModName,
163 const DenseMap<StringAttr, StringAttr> &innerSymRenameMap);
168 llvm::erase(
nodeMap[mod], nla);
176 [&nlas](
const auto &nla) {
return nlas.count(nla); });
190 llvm::DenseMap<StringAttr, SmallVector<hw::HierPathOp, 4>>
nodeMap;
193 llvm::DenseMap<StringAttr, Operation *>
symToOp;
This table tracks nlas and what modules participate in them.
ArrayRef< hw::HierPathOp > lookup(Operation *op)
Lookup all NLAs an operation participates in.
NLATable(const NLATable &)=delete
void updateModuleInNLA(StringAttr nlaName, StringAttr oldModule, StringAttr newModule)
Replace the module oldModule with newModule in the namepath of the nla nlaName.
void removeNLAsfromModule(const DenseSet< hw::HierPathOp > &nlas, StringAttr mod)
Remove all the nlas in the set nlas from the module.
llvm::DenseMap< StringAttr, SmallVector< hw::HierPathOp, 4 > > nodeMap
Map modules to the NLA's that target them.
void renameModule(StringAttr oldModName, StringAttr newModName)
Rename a module, this updates the name to module tracking and the name to NLA tracking.
void addNLA(hw::HierPathOp nla)
Insert a new NLA.
void removeNLAfromModule(hw::HierPathOp nla, StringAttr mod)
Remove the NLA from the Module.
void addNLAtoModule(hw::HierPathOp nla, StringAttr mod)
Add the nla to the module.
void eraseModule(StringAttr name)
Stop tracking a module.
void renameModuleAndInnerRef(StringAttr newModName, StringAttr oldModName, const DenseMap< StringAttr, StringAttr > &innerSymRenameMap)
Replace the module oldModName with newModName in the namepath of any NLA.
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 ...
void erase(hw::HierPathOp nlaOp, SymbolTable *symbolTable=nullptr)
Remove the NLA from the analysis.
void getNLAsInModule(StringAttr modName, DenseSet< hw::HierPathOp > &nlas)
Get the NLAs that the module modName particiaptes in, and insert them into the DenseSet nlas.
void addModule(FModuleLike mod)
Record a new FModuleLike operation.
NLATable(Operation *operation)
Create a new NLA table of a circuit.
void getInstanceNLAs(InstanceOp inst, DenseSet< hw::HierPathOp > &nlas)
Get the NLAs that the InstanceOp participates in, insert it to the DenseSet nlas.
hw::HierPathOp getNLA(StringAttr name)
Resolve a symbol to an NLA.
llvm::DenseMap< StringAttr, Operation * > symToOp
Map symbol names to module and NLA operations.
FModuleLike getModule(StringAttr name)
Resolve a symbol to a Module.
StringAttr getInnerSymName(Operation *op)
Return the StringAttr for the inner_sym name, if it exists.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.