[pypy-commit] pypy ssa-flow: make SSA_to_SSI accept only graphs, fix tests

rlamy noreply at buildbot.pypy.org
Wed Nov 12 19:43:09 CET 2014


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: ssa-flow
Changeset: r74487:77c7e2e136ee
Date: 2013-08-15 16:20 +0100
http://bitbucket.org/pypy/pypy/changeset/77c7e2e136ee/

Log:	make SSA_to_SSI accept only graphs, fix tests

diff --git a/rpython/translator/backendopt/ssa.py b/rpython/translator/backendopt/ssa.py
--- a/rpython/translator/backendopt/ssa.py
+++ b/rpython/translator/backendopt/ssa.py
@@ -16,7 +16,9 @@
         # [Block, blockvar, linkvar, linkvar, linkvar...]
         opportunities = []
         opportunities_with_const = []
-        for block, links in mkinsideentrymap(graph).items():
+        entrymap = mkentrymap(graph)
+        del entrymap[graph.startblock]
+        for block, links in entrymap.items():
             assert links
             for n, inputvar in enumerate(block.inputargs):
                 vars = [block, inputvar]
@@ -123,23 +125,6 @@
 
 # ____________________________________________________________
 
-def mkinsideentrymap(graph_or_blocks):
-    # graph_or_blocks can be a full FunctionGraph, or a mapping
-    # {block: reachable-from-outside-flag}.
-    if isinstance(graph_or_blocks, dict):
-        blocks = graph_or_blocks
-        entrymap = {}
-        for block in blocks:
-            for link in block.exits:
-                if link.target in blocks and not blocks[link.target]:
-                    entrymap.setdefault(link.target, []).append(link)
-        return entrymap
-    else:
-        graph = graph_or_blocks
-        entrymap = mkentrymap(graph)
-        del entrymap[graph.startblock]
-        return entrymap
-
 def variables_created_in(block):
     result = set(block.inputargs)
     for op in block.operations:
@@ -147,17 +132,14 @@
     return result
 
 
-def SSA_to_SSI(graph_or_blocks, annotator=None):
+def SSA_to_SSI(graph, annotator=None):
     """Turn a number of blocks belonging to a flow graph into valid (i.e. SSI)
     form, assuming that they are only in SSA form (i.e. they can use each
     other's variables directly, without having to pass and rename them along
     links).
-
-    'graph_or_blocks' can be a graph, or just a dict that lists some blocks
-    from a graph, as follows: {block: reachable-from-outside-flag}.
     """
     seen = set()
-    for link in graph_or_blocks.iterlinks():
+    for link in graph.iterlinks():
         mapping = {}
         seen.update(link.args)
         for arg in link.target.inputargs:
@@ -165,8 +147,9 @@
                 mapping[arg] = Variable(arg)
         link.target.renamevariables(mapping)
 
-    entrymap = mkinsideentrymap(graph_or_blocks)
-    builder = DataFlowFamilyBuilder(graph_or_blocks)
+    entrymap = mkentrymap(graph)
+    del entrymap[graph.startblock]
+    builder = DataFlowFamilyBuilder(graph)
     variable_families = builder.get_variable_families()
     del builder
 
diff --git a/rpython/translator/backendopt/test/test_ssa.py b/rpython/translator/backendopt/test/test_ssa.py
--- a/rpython/translator/backendopt/test/test_ssa.py
+++ b/rpython/translator/backendopt/test/test_ssa.py
@@ -1,7 +1,7 @@
 from rpython.translator.backendopt.ssa import *
 from rpython.translator.translator import TranslationContext
-from rpython.flowspace.model import Block, Link, Variable, Constant
-from rpython.flowspace.model import SpaceOperation
+from rpython.flowspace.model import (
+    Block, Link, Variable, Constant, SpaceOperation, FunctionGraph)
 
 
 def test_data_flow_families():
@@ -60,16 +60,14 @@
     b2 = Block([x])
     b3 = Block([])
 
+    graph = FunctionGraph('x', b1)
     b2.operations.append(SpaceOperation('add', [x, c], y))
     b2.exitswitch = y
 
     b1.closeblock(Link([Constant(0)], b2))
     b2.closeblock(Link([y], b2), Link([], b3))
-    b3.closeblock(Link([y, c], None))
-
-    SSA_to_SSI({b1: True,     # reachable from outside
-                b2: False,
-                b3: False})
+    b3.closeblock(Link([y, c], graph.exceptblock))
+    SSA_to_SSI(graph)
 
     assert len(b1.inputargs) == 1
     assert len(b2.inputargs) == 2
@@ -100,10 +98,8 @@
 
     b3.operations.append(SpaceOperation('hello', [y], z))
     b1.closeblock(Link([x], b2), Link([], b3))
-
-    SSA_to_SSI({b1: True,     # reachable from outside
-                b2: False,
-                b3: False})
+    graph = FunctionGraph('x', b1)
+    SSA_to_SSI(graph)
 
     assert b1.inputargs == [x]
     assert b2.inputargs == [y]


More information about the pypy-commit mailing list