Fixed bug in AssignElimination. (#4609)

* Fixed bug in AssignElimination.

* Removed out edges check from assign elimination.

* Moved Assert to AssignElimination transformation.

* Renamed transformation, added comment.
This commit is contained in:
Anastasia Popova 2021-03-09 14:58:25 +03:00 committed by GitHub
parent e40a44202e
commit 5f12213a33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,68 +16,20 @@
import logging as log import logging as log
import networkx as nx from mo.front.common.replacement import FrontReplacementPattern
from mo.front.common.replacement import FrontReplacementOp
from mo.graph.graph import Graph from mo.graph.graph import Graph
from mo.utils.error import Error
class AssignElimination(FrontReplacementOp): class AssignAndAssertElimination(FrontReplacementPattern):
op = "Assign" # The solution with removal of Assign and Assert operations is temporary.
# The proper solution is to keep these operations until the partial inference
# phase when control flow edges are properly handled and later unnecessary ones are eliminated.
# In order to achieve this we need to implement control flow inference function
# for these operations similar to "Merge" and "Switch" operations.
enabled = True enabled = True
def replace_sub_graph(self, graph: Graph, match: dict): def find_and_replace_pattern(self, graph: Graph):
node = match['op'] for node in graph.get_op_nodes():
# here we request all data flow output edges (control flow edges will not be listed) if node.soft_get('op') in ["Assign", "AssignSub", "AssignAdd", "Assert"]:
out_edges = node.out_edges() log.debug('"{}" op with id="{}" was removed'.format(node.op, node.id))
if len(out_edges) == 0:
graph.remove_node(node.id) graph.remove_node(node.id)
log.debug('Assign op was removed {}'.format(node.id))
else:
raise Error('Data flow edge coming out of Assign node {}'.format(node.id))
class AssignSubElimination(FrontReplacementOp):
op = "AssignSub"
enabled = True
def replace_sub_graph(self, graph: Graph, match: dict):
node = match['op']
# here we request all data flow output edges (control flow edges will not be listed)
out_edges = node.out_edges()
if len(out_edges) == 0:
graph.remove_node(node.id)
log.debug('AssignSub op was removed {}'.format(node.id))
else:
raise Error('Data flow edge coming out of AssignSub node {}'.format(node.id))
class AssignAddElimination(FrontReplacementOp):
op = "AssignAdd"
enabled = True
def replace_sub_graph(self, graph: Graph, match: dict):
node = match['op']
# here we request all data flow output edges (control flow edges will not be listed)
out_edges = node.out_edges()
if len(out_edges) == 0:
graph.remove_node(node.id)
log.debug('AssignAdd op was removed {}'.format(node.id))
else:
raise Error('Data flow edge coming out of AssignAdd node {}'.format(node.id))
class AssertElimination(FrontReplacementOp):
op = "Assert"
enabled = True
def replace_sub_graph(self, graph: nx.MultiDiGraph, match: dict):
node = match['op']
# here we request all data flow output edges (control flow edges will not be listed)
out_edges = node.out_edges()
if len(out_edges) == 0:
graph.remove_node(node.id)
log.debug('Assert op was removed {}'.format(node.id))
else:
raise Error('Data flow edge coming out of Assert node {}'.format(node.id))