hdl.xfrm: avoid cycles in union-find graph in LHSGroupAnalyzer.

This commit is contained in:
whitequark 2018-12-22 22:19:14 +00:00
parent 3448953f61
commit 621dddebfd
2 changed files with 16 additions and 0 deletions

View file

@ -298,6 +298,8 @@ class LHSGroupAnalyzer(StatementVisitor):
root_group = self.find(root)
for leaf in leaves:
leaf_group = self.find(leaf)
if root_group == leaf_group:
continue
self.unions[leaf_group] = root_group
def groups(self):

View file

@ -186,6 +186,20 @@ class LHSGroupAnalyzerTestCase(FHDLTestCase):
SignalSet((a, b)),
])
def test_no_loops(self):
a = Signal()
b = Signal()
stmts = [
a.eq(0),
Cat(a, b).eq(0),
Cat(a, b).eq(0),
]
groups = LHSGroupAnalyzer()(stmts)
self.assertEqual(list(groups.values()), [
SignalSet((a, b)),
])
def test_switch(self):
a = Signal()
b = Signal()