[pypy-svn] r14097 - in pypy/dist/pypy/translator: . llvm2 test

ericvrp at codespeak.net ericvrp at codespeak.net
Sat Jul 2 16:16:09 CEST 2005


Author: ericvrp
Date: Sat Jul  2 16:16:09 2005
New Revision: 14097

Added:
   pypy/dist/pypy/translator/test/test_backendoptimization.py
Modified:
   pypy/dist/pypy/translator/backendoptimization.py
   pypy/dist/pypy/translator/llvm2/genllvm.py
Log:
(ericvrp, cfbolz)
added remove_void which tries to get rid of unneccessary voids in the flow graph.
works only for void function arguments at the moment.



Modified: pypy/dist/pypy/translator/backendoptimization.py
==============================================================================
--- pypy/dist/pypy/translator/backendoptimization.py	(original)
+++ pypy/dist/pypy/translator/backendoptimization.py	Sat Jul  2 16:16:09 2005
@@ -1,9 +1,10 @@
 import autopath
 from pypy.translator.translator import Translator
 from pypy.objspace.flow.model import Variable, Constant, Block, Link
+from pypy.objspace.flow.model import SpaceOperation
 from pypy.objspace.flow.model import traverse, mkentrymap, checkgraph
 from pypy.tool.unionfind import UnionFind
-
+from pypy.rpython.lltype import Void
 
 def remove_same_as(graph):
     """Remove all 'same_as' operations.
@@ -41,6 +42,21 @@
     traverse(visit, graph)
 
 
+def remove_void(translator):
+    for func, graph in translator.flowgraphs.iteritems():
+        args = [arg for arg in graph.startblock.inputargs
+                    if arg.concretetype is not Void]
+        graph.startblock.inputargs = args
+    def visit(block): 
+        if isinstance(block, Block):
+            for op in block.operations:
+                if op.opname == 'direct_call':
+                    args = [arg for arg in op.args
+                                if arg.concretetype is not Void]
+                    op.args = args
+    for func, graph in translator.flowgraphs.iteritems():
+        traverse(visit, graph)
+ 
 def SSI_to_SSA(graph):
     """Rename the variables in a flow graph as much as possible without
     violating the SSA rule.  'SSI' means that each Variable in a flow graph is

Modified: pypy/dist/pypy/translator/llvm2/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm2/genllvm.py	Sat Jul  2 16:16:09 2005
@@ -8,8 +8,10 @@
 from pypy.rpython import lltype
 from pypy.tool.udir import udir
 from pypy.translator.llvm2.codewriter import CodeWriter
+from pypy.translator.backendoptimization import remove_void
 
 def genllvm(translator):
+    remove_void(translator)
     func = translator.entrypoint
 
     db = Database(translator)

Added: pypy/dist/pypy/translator/test/test_backendoptimization.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/test/test_backendoptimization.py	Sat Jul  2 16:16:09 2005
@@ -0,0 +1,24 @@
+from pypy.translator.backendoptimization import remove_void
+from pypy.translator.translator import Translator
+from pypy.rpython.lltype import Void
+from pypy.rpython.llinterp import LLInterpreter
+from pypy.objspace.flow.model import checkgraph
+
+def annotate_and_remove_void(f, annotate):
+    t = Translator(f)
+    a = t.annotate(annotate)
+    t.specialize()
+    remove_void(t)
+    return t
+
+def test_remove_void_args():
+    def f(i):
+        return [1,2,3,i][i]
+    t = annotate_and_remove_void(f, [int])
+    for func, graph in t.flowgraphs.iteritems():
+        assert checkgraph(graph) is None
+        for arg in graph.startblock.inputargs:
+            assert arg.concretetype is not Void
+    interp = LLInterpreter(t.flowgraphs, t.rtyper)
+    assert interp.eval_function(f, [0]) == 1 
+



More information about the Pypy-commit mailing list