[pypy-svn] r73973 - in pypy/branch/blackhole-improvement/pypy/jit/codewriter: . test

arigo at codespeak.net arigo at codespeak.net
Thu Apr 22 14:39:06 CEST 2010


Author: arigo
Date: Thu Apr 22 14:39:04 2010
New Revision: 73973

Modified:
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/flatten.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/format.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jitter.py
Log:
Support for lists of variables in the assembler source code.


Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/flatten.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/flatten.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/flatten.py	Thu Apr 22 14:39:04 2010
@@ -39,7 +39,7 @@
     flattener = GraphFlattener(graph, regallocs)
     flattener.enforce_input_args()
     flattener.generate_ssa_form()
-    return flattener.assembler
+    return flattener.ssarepr
 
 
 class GraphFlattener(object):
@@ -48,6 +48,11 @@
         self.graph = graph
         self.regallocs = regallocs
         self.registers = {}
+        if graph:
+            name = graph.name
+        else:
+            name = '?'
+        self.ssarepr = SSARepr(name)
 
     def enforce_input_args(self):
         inputargs = self.graph.startblock.inputargs
@@ -64,7 +69,6 @@
                 self.regallocs[kind].swapcolors(realcol, curcol)
 
     def generate_ssa_form(self):
-        self.assembler = SSARepr(self.graph.name)
         self.seen_blocks = {}
         self.make_bytecode_block(self.graph.startblock)
 
@@ -160,13 +164,20 @@
                     self.emitline('%s_rename' % kind, frm, to)
 
     def emitline(self, *line):
-        self.assembler.insns.append(line)
+        self.ssarepr.insns.append(line)
 
-    def flatten_list(self, list):
+    def flatten_list(self, arglist):
         args = []
-        for v in list:
+        for v in arglist:
             if isinstance(v, Variable):
                 v = self.getcolor(v)
+            elif isinstance(v, list):
+                lst = v
+                v = []
+                for x in lst:
+                    if isinstance(x, Variable):
+                        x = self.getcolor(x)
+                    v.append(x)
             args.append(v)
         return args
 

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/format.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/format.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/format.py	Thu Apr 22 14:39:04 2010
@@ -18,7 +18,7 @@
         elif isinstance(x, list):
             return '[%s]' % ', '.join(map(repr, x))
         else:
-            return `x`   # ?
+            return '<unknown object: %r>' % (x,)
     #
     seenlabels = {}
     for asm in ssarepr.insns:

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py	Thu Apr 22 14:39:04 2010
@@ -1,8 +1,12 @@
 import py
 from pypy.jit.codewriter import support
 from pypy.jit.codewriter.flatten import flatten_graph, reorder_renaming_list
+from pypy.jit.codewriter.flatten import GraphFlattener
 from pypy.jit.codewriter.format import format_assembler
 from pypy.jit.codewriter.jitter import transform_graph
+from pypy.rpython.lltypesystem import lltype, rclass, rstr
+from pypy.objspace.flow.model import SpaceOperation, Variable, Constant
+from pypy.translator.unsimplify import varoftype
 
 
 class FakeRegAlloc:
@@ -16,6 +20,11 @@
             self.num_colors += 1
         return self.seen[v]
 
+def fake_regallocs():
+    return {'int': FakeRegAlloc(),
+            'ref': FakeRegAlloc(),
+            'float': FakeRegAlloc()}
+
 def test_reorder_renaming_list():
     result = reorder_renaming_list([], [])
     assert result == []
@@ -35,13 +44,14 @@
         self.rtyper = support.annotate(func, values, type_system=type_system)
         return self.rtyper.annotator.translator.graphs
 
-    def encoding_test(self, func, args, expected, optimize=False):
+    def encoding_test(self, func, args, expected, transform=False):
         graphs = self.make_graphs(func, args)
-        if optimize:
+        if transform:
             transform_graph(graphs[0])
-        ssarepr = flatten_graph(graphs[0], {'int': FakeRegAlloc(),
-                                            'ref': FakeRegAlloc(),
-                                            'float': FakeRegAlloc()})
+        ssarepr = flatten_graph(graphs[0], fake_regallocs())
+        self.assert_format(ssarepr, expected)
+
+    def assert_format(self, ssarepr, expected):
         asm = format_assembler(ssarepr)
         expected = str(py.code.Source(expected)).strip() + '\n'
         assert asm == expected
@@ -97,7 +107,7 @@
             goto L1
             L2:
             int_return %i3
-        """, optimize=True)
+        """, transform=True)
 
     def test_float(self):
         def f(i, f):
@@ -109,3 +119,20 @@
             float_add %f2, %f1, %f3
             float_return %f3
         """)
+
+    def test_arg_sublist_1(self):
+        v1 = varoftype(lltype.Signed)
+        v2 = varoftype(lltype.Char)
+        v3 = varoftype(rclass.OBJECTPTR)
+        v4 = varoftype(lltype.Ptr(rstr.STR))
+        v5 = varoftype(lltype.Float)
+        op = SpaceOperation('residual_call_ir_f',
+                            [Constant(12345, lltype.Signed),  # function ptr
+                             [v1, v2],              # int args
+                             [v3, v4]],             # ref args
+                            v5)                    # result
+        flattener = GraphFlattener(None, fake_regallocs())
+        flattener.serialize_op(op)
+        self.assert_format(flattener.ssarepr, """
+            residual_call_ir_f $12345, [%i0, %i1], [%r0, %r1], %f0
+        """)

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jitter.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jitter.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jitter.py	Thu Apr 22 14:39:04 2010
@@ -67,19 +67,23 @@
                     else: expectedkind = 'r'          # only references
                     yield residual_call_test, ARGS, RESTYPE, expectedkind
 
-def residual_call_test(argtypes, restype, expectedkind):
+def get_direct_call_op(argtypes, restype):
     FUNC = lltype.FuncType(argtypes, restype)
     fnptr = lltype.functionptr(FUNC, "g")    # no graph
     c_fnptr = Constant(fnptr, concretetype=lltype.typeOf(fnptr))
     vars = [varoftype(TYPE) for TYPE in argtypes]
     v_result = varoftype(restype)
     op = SpaceOperation('direct_call', [c_fnptr] + vars, v_result)
+    return op
+
+def residual_call_test(argtypes, restype, expectedkind):
+    op = get_direct_call_op(argtypes, restype)
     op1 = jitter.rewrite_operation(op)
     reskind = getkind(restype)[0]
     assert op1.opname == 'residual_call_%s_%s' % (expectedkind, reskind)
-    assert op1.result == v_result
-    assert op1.args[0] == c_fnptr
+    assert op1.result == op.result
+    assert op1.args[0] == op.args[0]
     assert len(op1.args) == 1 + len(expectedkind)
     for sublist, kind in zip(op1.args[1:], expectedkind):
-        assert sublist == [v for v in vars
+        assert sublist == [v for v in op.args[1:]
                              if getkind(v.concretetype).startswith(kind)]



More information about the Pypy-commit mailing list