diff --git a/include/circt/Support/InstanceGraph.h b/include/circt/Support/InstanceGraph.h index 4b6dcf210d..40a8196e8f 100644 --- a/include/circt/Support/InstanceGraph.h +++ b/include/circt/Support/InstanceGraph.h @@ -210,7 +210,10 @@ public: InstanceGraphNode *operator[](ModuleOpInterface op) { return lookup(op); } /// Check if child is instantiated by a parent. - bool isAncestor(ModuleOpInterface child, ModuleOpInterface parent); + bool isAncestor( + ModuleOpInterface child, ModuleOpInterface parent, + llvm::function_ref skipInstance = + [](InstanceRecord *_) { return false; }); /// Get the node corresponding to the top-level module of a circuit. virtual InstanceGraphNode *getTopLevelNode() { return nullptr; } diff --git a/lib/Support/InstanceGraph.cpp b/lib/Support/InstanceGraph.cpp index e05c81b11d..cac7dc5786 100644 --- a/lib/Support/InstanceGraph.cpp +++ b/lib/Support/InstanceGraph.cpp @@ -136,8 +136,9 @@ void InstanceGraph::replaceInstance(InstanceOpInterface inst, } } -bool InstanceGraph::isAncestor(ModuleOpInterface child, - ModuleOpInterface parent) { +bool InstanceGraph::isAncestor( + ModuleOpInterface child, ModuleOpInterface parent, + llvm::function_ref skipInstance) { DenseSet seen; SmallVector worklist; auto *cn = lookup(child); @@ -149,6 +150,8 @@ bool InstanceGraph::isAncestor(ModuleOpInterface child, if (node->getModule() == parent) return true; for (auto *use : node->uses()) { + if (skipInstance(use)) + continue; auto *mod = use->getParent(); if (!seen.count(mod)) { seen.insert(mod);