Skip to content

Commit

Permalink
Fix conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad committed Sep 7, 2023
1 parent 0b0a3c8 commit b29a3f5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
5 changes: 3 additions & 2 deletions dace/transformation/interstate/scope_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ def apply(self, graph: ControlFlowGraph, sdfg: SDFG) -> Optional[int]:
parent.add_edge(init_state, guard_state, init_edge)

end_state = parent.add_state(self.block.label + '_end')
cond_expr = self.block.scope_condition.code
parent.add_edge(guard_state, end_state,
InterstateEdge(condition=CodeBlock(astutils.negate_expr(self.block.scope_condition.code))))
InterstateEdge(CodeBlock(astutils.negate_expr(cond_expr)).code))
for a_edge in parent.out_edges(self.block):
parent.add_edge(end_state, a_edge.dst, a_edge.data)
parent.remove_edge(a_edge)
Expand All @@ -73,7 +74,7 @@ def apply(self, graph: ControlFlowGraph, sdfg: SDFG) -> Optional[int]:

# Connect the loop states
parent.add_edge(guard_state, internal_start,
InterstateEdge(condition=self.block.scope_condition.as_string))
InterstateEdge(CodeBlock(cond_expr).code))
for node in to_connect:
parent.add_edge(node, last_loop_state, InterstateEdge())

Expand Down
31 changes: 30 additions & 1 deletion dace/transformation/passes/fusion_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from dace import SDFG, properties
from dace.sdfg import nodes
from dace.sdfg.utils import fuse_states, inline_sdfgs
from dace.sdfg.utils import fuse_states, inline_sdfgs, inline_loop_blocks
from dace.transformation import pass_pipeline as ppl


Expand Down Expand Up @@ -85,6 +85,35 @@ def report(self, pass_retval: int) -> str:
return f'Inlined {pass_retval} SDFGs.'


@dataclass(unsafe_hash=True)
@properties.make_properties
class InlineScopes(ppl.Pass):
"""
Inlines all possible sub-scopes of an SDFG to create a state machine.
"""

CATEGORY: str = 'Cleanup'

permissive = properties.Property(dtype=bool, default=False, desc='If True, ignores some checks on inlining.')
progress = properties.Property(dtype=bool,
default=None,
allow_none=True,
desc='Whether to print progress, or None for default (print after 5 seconds).')

def should_reapply(self, modified: ppl.Modifies) -> bool:
return modified & (ppl.Modifies.States | ppl.Modifies.InterstateEdges)

def modifies(self) -> ppl.Modifies:
return ppl.Modifies.States | ppl.Modifies.InterstateEdges

def apply_pass(self, sdfg: SDFG, _: Dict[str, Any]) -> Optional[int]:
inlined = inline_loop_blocks(sdfg, self.permissive, self.progress)
return inlined or None

def report(self, pass_retval: int) -> str:
return f'Inlined {pass_retval} scopes.'


@dataclass(unsafe_hash=True)
@properties.make_properties
class FixNestedSDFGReferences(ppl.Pass):
Expand Down

0 comments on commit b29a3f5

Please sign in to comment.