def while_block_struct(graph, node_map): change = False for node in graph.rpo[:]: if node.startloop: change = True new_node = LoopBlock(node.name, node) node_map[node] = new_node new_node.copy_from(node) entry = node is graph.entry lpreds = graph.preds(node) lsuccs = graph.sucs(node) for pred in lpreds: graph.add_edge(node_map.get(pred, pred), new_node) for suc in lsuccs: graph.add_edge(new_node, node_map.get(suc, suc)) if entry: graph.entry = new_node if node.type.is_cond: new_node.true = node.true new_node.false = node.false graph.add_node(new_node) graph.remove_node(node) if change: graph.reset_rpo()
def while_block_struct(graph, node_map): change = False for node in graph.get_rpo()[:]: if node.is_start_loop(): change = True new_node = LoopBlock(node.name, node) node_map[node] = new_node new_node.copy_from(node) entry = node is graph.get_entry() lpreds = graph.preds(node) lsuccs = graph.sucs(node) for pred in lpreds: graph.add_edge(node_map.get(pred, pred), new_node) for suc in lsuccs: graph.add_edge(new_node, node_map.get(suc, suc)) if entry: graph.set_entry(new_node) if node.is_cond(): new_node.set_true(node.true) new_node.set_false(node.false) graph.add_node(new_node) graph.remove_node(node) if change: graph.reset_rpo()
def while_block_struct(graph, node_map): change = False for node in graph.rpo[:]: if node.startloop: change = True new_node = LoopBlock(node.name, node) node_map[node] = new_node new_node.copy_from(node) entry = node is graph.entry lpreds = graph.preds(node) lsuccs = graph.sucs(node) for pred in lpreds: graph.add_edge(node_map.get(pred, pred), new_node) for suc in lsuccs: graph.add_edge(new_node, node_map.get(suc, suc)) if entry: graph.entry = new_node if node.type.is_cond: new_node.true = node.true new_node.false = node.false graph.add_node(new_node) graph.remove_node(node) if change: graph.compute_rpo()