@@ -74,39 +74,41 @@ InstanceInfo::InstanceInfo(Operation *op, mlir::AnalysisManager &am) {
74
74
// Visit modules in reverse post-order (visit parents before children) because
75
75
// information flows in this direction---the attributes of modules are
76
76
// determinend by their instantiations.
77
- llvm::ReversePostOrderTraversal<InstanceGraph *> rpo (&iGraph);
78
- for (auto *modIt : rpo) {
79
- auto moduleOp = modIt->getModule ();
80
- ModuleAttributes &attributes = moduleAttributes[moduleOp];
81
-
82
- // Set DUT-related attributes.
83
- auto isDut = AnnotationSet (moduleOp).hasAnnotation (dutAnnoClass);
84
- if (isDut) {
85
- circuitAttributes.dutNode = modIt;
86
- circuitAttributes.effectiveDutNode = modIt;
87
- }
88
-
89
- // If the module is not instantiated, then set attributes and early exit.
90
- if (modIt->noUses ()) {
91
- attributes.underDut .markConstant (false );
92
- attributes.underLayer .markConstant (false );
93
- continue ;
94
- }
95
-
96
- // Merge in attributes from modules that instantiate this module.
97
- for (auto *useIt : modIt->uses ()) {
98
- auto parentOp = useIt->getParent ()->getModule ();
99
- auto parentAttrs = moduleAttributes.find (parentOp)->getSecond ();
100
- // Merge underDut.
101
- if (this ->isDut (parentOp) || isDut)
102
- attributes.underDut .mergeIn (true );
103
- else
104
- attributes.underDut .mergeIn (parentAttrs.underDut );
105
- // Merge underLayer.
106
- if (useIt->getInstance ()->getParentOfType <LayerBlockOp>())
107
- attributes.underLayer .mergeIn (true );
108
- else
109
- attributes.underLayer .mergeIn (parentAttrs.underLayer );
77
+ DenseSet<InstanceGraphNode *> visited;
78
+ for (auto *root : iGraph) {
79
+ for (auto *modIt : llvm::inverse_post_order_ext (root, visited)) {
80
+ auto moduleOp = modIt->getModule ();
81
+ ModuleAttributes &attributes = moduleAttributes[moduleOp];
82
+
83
+ // Set DUT-related attributes.
84
+ auto isDut = AnnotationSet (moduleOp).hasAnnotation (dutAnnoClass);
85
+ if (isDut) {
86
+ circuitAttributes.dutNode = modIt;
87
+ circuitAttributes.effectiveDutNode = modIt;
88
+ }
89
+
90
+ // If the module is not instantiated, then set attributes and early exit.
91
+ if (modIt->noUses ()) {
92
+ attributes.underDut .markConstant (false );
93
+ attributes.underLayer .markConstant (false );
94
+ continue ;
95
+ }
96
+
97
+ // Merge in attributes from modules that instantiate this module.
98
+ for (auto *useIt : modIt->uses ()) {
99
+ auto parentOp = useIt->getParent ()->getModule ();
100
+ auto parentAttrs = moduleAttributes.find (parentOp)->getSecond ();
101
+ // Merge underDut.
102
+ if (this ->isDut (parentOp) || isDut)
103
+ attributes.underDut .mergeIn (true );
104
+ else
105
+ attributes.underDut .mergeIn (parentAttrs.underDut );
106
+ // Merge underLayer.
107
+ if (useIt->getInstance ()->getParentOfType <LayerBlockOp>())
108
+ attributes.underLayer .mergeIn (true );
109
+ else
110
+ attributes.underLayer .mergeIn (parentAttrs.underLayer );
111
+ }
110
112
}
111
113
}
112
114
0 commit comments