Author: Ronan Lamy <ronan.l...@gmail.com> Branch: ssa-flow Changeset: r74514:273f7c704efb Date: 2014-11-13 23:49 +0000 http://bitbucket.org/pypy/pypy/changeset/273f7c704efb/
Log: create remove_trivial_links(): the SSA version of join_blocks() diff --git a/rpython/translator/simplify.py b/rpython/translator/simplify.py --- a/rpython/translator/simplify.py +++ b/rpython/translator/simplify.py @@ -246,6 +246,44 @@ seen.append(case) block.recloseblock(*exits) +def remove_trivial_links(graph): + """Remove trivial links by merging their source and target blocks + + A link is trivial if it only renames variables, is the single exit of its + source and the single parent of its target. + """ + entrymap = mkentrymap(graph) + block = graph.startblock + seen = set([block]) + stack = list(block.exits) + renaming = {} + while stack: + link = stack.pop() + if link.target in seen: + continue + source = link.prevblock + target = link.target + if (source.exitswitch is None and len(entrymap[target]) == 1 and + target.exits): # stop at the returnblock + assert len(source.exits) == 1 + for vprev, vtarg in zip(link.args, target.inputargs): + while vprev in renaming: + vprev = renaming[vprev] + renaming[vtarg] = vprev + target.renamevariables(renaming) + source.operations.extend(target.operations) + source.exitswitch = newexitswitch = target.exitswitch + exits = target.exits + source.recloseblock(*exits) + if isinstance(newexitswitch, Constant) and newexitswitch != c_last_exception: + exits = replace_exitswitch_by_constant(source, newexitswitch) + stack.extend(exits) + else: + target.renamevariables(renaming) + seen.add(target) + stack.extend(target.exits) + + def join_blocks(graph): """Links can be deleted if they are the single exit of a block and the single entry point of the next block. When this happens, we can @@ -962,9 +1000,9 @@ all_passes = [ eliminate_empty_blocks, + remove_assertion_errors, + remove_trivial_links, SSA_to_SSI, - remove_assertion_errors, - join_blocks, coalesce_bool, transform_dead_op_vars, remove_identical_vars, _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit