[pypy-svn] r21262 - in pypy/dist/pypy/translator: backendopt test

arigo at codespeak.net arigo at codespeak.net
Sun Dec 18 11:05:39 CET 2005


Author: arigo
Date: Sun Dec 18 11:05:36 2005
New Revision: 21262

Modified:
   pypy/dist/pypy/translator/backendopt/ssa.py
   pypy/dist/pypy/translator/test/test_simplify.py
Log:
Improve translator.simplify.remove_identical_vars() to find and eliminate
duplicate input variables of a block also in the case where a link provides
several times the same *constant* for this input variable.

Seems to be required for hint() to work as expected in the jit.

XXX does this noticeably slow down translate_pypy?


Modified: pypy/dist/pypy/translator/backendopt/ssa.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/ssa.py	(original)
+++ pypy/dist/pypy/translator/backendopt/ssa.py	Sun Dec 18 11:05:36 2005
@@ -15,21 +15,24 @@
         # the nth output variable from each of the incoming links, in a list:
         # [Block, blockvar, linkvar, linkvar, linkvar...]
         opportunities = []
+        opportunities_with_const = []
         for block, links in mkentrymap(graph).items():
             if block is graph.startblock:
                 continue
             assert links
             for n, inputvar in enumerate(block.inputargs):
                 vars = [block, inputvar]
+                put_in = opportunities
                 for link in links:
                     var = link.args[n]
                     if not isinstance(var, Variable):
-                        break
+                        put_in = opportunities_with_const
                     vars.append(var)
-                else:
-                    # if no Constant found in the incoming links
-                    opportunities.append(vars)
+                # if any link provides a Constant, record this in
+                # the opportunities_with_const list instead
+                put_in.append(vars)
         self.opportunities = opportunities
+        self.opportunities_with_const = opportunities_with_const
         self.variable_families = UnionFind()
 
     def complete(self):
@@ -66,9 +69,9 @@
         while progress:
             progress = False
             block_phi_nodes = {}   # in the SSA sense
-            for vars in self.opportunities:
+            for vars in self.opportunities + self.opportunities_with_const:
                 block, blockvar = vars[:2]
-                linksvars = vars[2:]   # from the incoming links
+                linksvars = vars[2:]   # from the incoming links (vars+consts)
                 linksvars = [variable_families.find_rep(v) for v in linksvars]
                 phi_node = (block,) + tuple(linksvars) # ignoring n and blockvar
                 if phi_node in block_phi_nodes:

Modified: pypy/dist/pypy/translator/test/test_simplify.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_simplify.py	(original)
+++ pypy/dist/pypy/translator/test/test_simplify.py	Sun Dec 18 11:05:36 2005
@@ -82,4 +82,15 @@
             assert op.opname != 'getfield'
             if op.opname == 'keepalive':
                 assert op.args[0] in graph.getargs()
-   
+
+
+def test_remove_identical_variables():
+    def g(code):
+        pc = 0
+        while pc < len(code):
+            pc += 1
+        return pc
+
+    graph = TranslationContext().buildflowgraph(g)
+    for block in graph.iterblocks():
+        assert len(block.inputargs) <= 2   # at most 'pc' and 'code'



More information about the Pypy-commit mailing list