2 Copyright (c) 2018-2019 Intel Corporation
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
21 from mo.front.common.replacement import FrontReplacementOp
22 from mo.graph.graph import Node, Graph
23 from mo.utils.error import Error
26 class AssignElimination(FrontReplacementOp):
30 def replace_sub_graph(self, graph: Graph, match: dict):
32 # here we request all data flow output edges (control flow edges will not be listed)
33 out_edges = node.out_edges()
34 if len(out_edges) == 0:
35 graph.remove_node(node.id)
36 log.debug('Assign op was removed {}'.format(node.id))
38 raise Error('Data flow edge coming out of Assign node {}'.format(node.id))
41 class AssignSubElimination(FrontReplacementOp):
45 def replace_sub_graph(self, graph: Graph, match: dict):
47 # here we request all data flow output edges (control flow edges will not be listed)
48 out_edges = node.out_edges()
49 if len(out_edges) == 0:
50 graph.remove_node(node.id)
51 log.debug('AssignSub op was removed {}'.format(node.id))
53 raise Error('Data flow edge coming out of AssignSub node {}'.format(node.id))
56 class AssignAddElimination(FrontReplacementOp):
60 def replace_sub_graph(self, graph: Graph, match: dict):
62 # here we request all data flow output edges (control flow edges will not be listed)
63 out_edges = node.out_edges()
64 if len(out_edges) == 0:
65 graph.remove_node(node.id)
66 log.debug('AssignAdd op was removed {}'.format(node.id))
68 raise Error('Data flow edge coming out of AssignAdd node {}'.format(node.id))
71 class AssertElimination(FrontReplacementOp):
75 def replace_sub_graph(self, graph: nx.MultiDiGraph, match: dict):
77 # here we request all data flow output edges (control flow edges will not be listed)
78 out_edges = node.out_edges()
79 if len(out_edges) == 0:
80 graph.remove_node(node.id)
81 log.debug('Assert op was removed {}'.format(node.id))
83 raise Error('Data flow edge coming out of Assert node {}'.format(node.id))