Skip to content

Commit

Permalink
Fix state-order traversal w.r.t. if branches without else
Browse files Browse the repository at this point in the history
  • Loading branch information
tbennun committed Oct 11, 2022
1 parent 12732c5 commit 2f6f06d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions dace/sdfg/analysis/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,10 @@ def _stateorder_topological_sort(sdfg: SDFG,
"""
# Traverse states in custom order
visited = visited or set()
if stop is not None:
visited.add(stop)
stack = [start]
while stack:
node = stack.pop()
if node in visited:
if node in visited or node is stop:
continue
yield node

Expand Down Expand Up @@ -265,6 +263,9 @@ def _stateorder_topological_sort(sdfg: SDFG,
mergestate = stop

for branch in oe:
if branch.dst is mergestate:
# If we hit the merge state (if without else), defer to end of branch traversal
continue
for s in _stateorder_topological_sort(sdfg,
branch.dst,
ptree,
Expand All @@ -273,8 +274,7 @@ def _stateorder_topological_sort(sdfg: SDFG,
visited=visited):
yield s
visited.add(s)
if mergestate != stop:
stack.append(mergestate)
stack.append(mergestate)


def stateorder_topological_sort(sdfg: SDFG) -> Iterator[SDFGState]:
Expand Down

0 comments on commit 2f6f06d

Please sign in to comment.