9 #ifndef CIRCT_DIALECT_FIRRTL_OWNINGMODULECACHE_H
10 #define CIRCT_DIALECT_FIRRTL_OWNINGMODULECACHE_H
33 auto [it, inserted] =
cache.try_emplace(op);
43 FModuleOp owner =
nullptr;
49 auto combine = [](FModuleOp current, FModuleOp parent,
bool first) {
52 else if (current != parent)
58 SmallVector<StackElement> stack;
60 stack.emplace_back(node);
62 auto returning =
false;
63 FModuleOp result =
nullptr;
64 while (!stack.empty()) {
66 auto &elt = stack.back();
71 elt.owner = combine(elt.owner, result, elt.first);
83 cache[elt.current] = elt.owner;
88 auto *parentNode = (*it)->getParent();
89 auto parent = parentNode->getModule();
94 if (
auto parentModule = dyn_cast<FModuleOp>(parent.getOperation())) {
95 elt.owner = combine(elt.owner, parentModule, elt.first);
99 auto [pIt, pInserted] =
cache.try_emplace(parent);
101 elt.owner = combine(elt.owner, pIt->second, elt.first);
107 stack.emplace_back(parentNode);
114 assert(returning &&
"must be returning a result");
122 if (
auto module = dyn_cast<FModuleOp>(op))
124 if (
auto classOp = dyn_cast<ClassOp>(op))
126 op = op->getParentOp();
132 DenseMap<Operation *, FModuleOp>
cache;
assert(baseType &&"element must be base type")
This graph tracks modules and where they are instantiated.
This is a Node in the InstanceGraph.
auto getModule()
Get the module that this node is tracking.
UseIterator usesBegin()
Iterate the instance records which instantiate this module.
InstanceGraphNode * lookup(ModuleOpInterface op)
Look up an InstanceGraphNode for a module.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
This implements an analysis to determine which module owns a given path operation.
DenseMap< Operation *, FModuleOp > cache
FModuleOp lookup(ClassOp classOp)
Return this operation's owning module.
OwningModuleCache(InstanceGraph &instanceGraph)
FModuleOp lookup(Operation *op)
Return this operation's owning module.
InstanceGraph & instanceGraph
Iterator for module uses.