Fixed bug in assign elimination transformation. (#4644)

This commit is contained in:
Anastasia Popova 2021-03-09 14:58:12 +03:00 committed by GitHub
parent 02d2dbd0fa
commit a53524a554
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
"""
Copyright (C) 2018-2020 Intel Corporation
Copyright (C) 2018-2021 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -16,68 +16,20 @@
import logging as log
import networkx as nx
from mo.front.common.replacement import FrontReplacementOp
from mo.front.common.replacement import FrontReplacementPattern
from mo.graph.graph import Graph
from mo.utils.error import Error
class AssignElimination(FrontReplacementOp):
op = "Assign"
class AssignAndAssertElimination(FrontReplacementPattern):
# 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
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('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))
def find_and_replace_pattern(self, graph: Graph):
for node in graph.get_op_nodes():
if node.soft_get('op') in ["Assign", "AssignSub", "AssignAdd", "Assert"]:
log.debug('"{}" op with id="{}" was removed'.format(node.op, node.id))
graph.remove_node(node.id)