[pypy-svn] r61869 - in pypy/branch/pyjitpl5/pypy/jit: backend/llgraph metainterp metainterp/test

fijal at codespeak.net fijal at codespeak.net
Sat Feb 14 11:52:56 CET 2009


Author: fijal
Date: Sat Feb 14 11:52:53 2009
New Revision: 61869

Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vlist.py
Log:
Enough support to pass the first virtual list test
(no virtual list specnode yet)


Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py	Sat Feb 14 11:52:53 2009
@@ -78,10 +78,14 @@
     'guard_no_exception'      : ((), None),
     'guard_exception'         : (('ptr',), 'ptr'),
     'guard_nonvirtualized__4' : (('ptr', 'int'), None),
+    'guard_builtin'   : (('ptr',), None),
     'newstr'          : (('int',), 'ptr'),
     'strlen'          : (('ptr',), 'int'),
     'strgetitem'      : (('ptr', 'int'), 'int'),
     'strsetitem'      : (('ptr', 'int', 'int'), None),
+    'getitem'         : (('ptr', 'ptr', 'int'), 'int'),
+    'setitem'         : (('ptr', 'ptr', 'int', 'int'), None),
+    'newlist'         : (('ptr', 'int'), 'ptr'),
 }
 
 # ____________________________________________________________
@@ -549,6 +553,9 @@
     def op_guard_pause(self):
         raise GuardFailed
 
+    def op_guard_builtin(self, b):
+        pass
+
     def op_guard_true(self, value, *livevars):
         if not value:
             raise GuardFailed
@@ -749,6 +756,15 @@
     op_call_ptr = do_call
     op_call_void = do_call
 
+    def op_getitem(self, ll_getitem, lst, item):
+        return self.do_call(ll_getitem, lst, item)
+
+    def op_setitem(self, ll_setitem, lst, item, val):
+        self.do_call(ll_setitem, lst, item, val)
+
+    def op_newlist(self, ll_newlist, lgt):
+        return self.do_call(ll_newlist, lgt)
+
     def op_cast_int_to_ptr(self, i):
         if i == 0:
             return dummy_null

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py	Sat Feb 14 11:52:53 2009
@@ -18,10 +18,11 @@
     pass
 
 class ListDescr(BuiltinDescr):
-    def __init__(self, getfunc, setfunc, tp):
-        self.setfunc = setfunc
-        self.getfunc = getfunc
-        self.tp = tp
+    def __init__(self, getfunc, setfunc, malloc_func, tp):
+        self.setfunc     = setfunc
+        self.getfunc     = getfunc
+        self.malloc_func = malloc_func
+        self.tp          = tp
     
     def equals(self, other):
         if isinstance(other, ListDescr):
@@ -150,12 +151,15 @@
                                                        args, lltype.Void)
             getfunc, _ = support.builtin_func_for_spec(rtyper, 'list.getitem',
                                                        args[:-1], TP.TO.OF)
+            malloc_func, _ = support.builtin_func_for_spec(rtyper, 'newlist',
+                                                           [lltype.Signed], TP)
             if isinstance(TP.TO.OF, lltype.Number):
                 tp = "int"
             else:
                 tp = "ptr"
             ld = ListDescr(history.ConstAddr(getfunc.value, self.cpu),
                            history.ConstAddr(setfunc.value, self.cpu),
+                           history.ConstAddr(malloc_func.value, self.cpu),
                            tp)
             self.list_cache[TP.TO] = ld
             return ld
@@ -605,25 +609,27 @@
         c_func, TP = support.builtin_func_for_spec(self.codewriter.rtyper,
                                                    oopspec_name, ll_args,
                                                    op.result.concretetype)
+        if oopspec_name.startswith('list') or oopspec_name == 'newlist':
+            if oopspec_name.startswith('list.getitem'):
+                opname = oopspec_name[len('list.'):]
+            elif oopspec_name.startswith('list.setitem'):
+                opname = oopspec_name[len('list.'):]
+            elif oopspec_name == 'newlist':
+                opname = 'newlist'
+            else:
+                raise NotImplementedError("not supported %s" % oopspec_name)
+            self.emit(opname)
+            ld = self.codewriter.list_descr_for_tp(TP)
+            self.emit(self.get_position(ld))
+            self.emit_varargs(args)
+            self.register_var(op.result)
+            if opname == 'newlist':
+                self._eventualy_builtin(op.result)
+            return
         if oopspec_name.endswith('_foldable'):
             opname = 'green_call_%s'
         else:
             opname = 'residual_call_%s'
-            if oopspec_name.startswith('list') or oopspec_name == 'newlist':
-                if oopspec_name == 'list.getitem':
-                    opname = 'getitem'
-                elif oopspec_name == 'list.setitem':
-                    opname = 'setitem'
-                elif oopspec_name == 'newlist':
-                    opname = 'newlist'
-                else:
-                    raise NotImplementedError("not supported %s" % oopspec_name)
-                self.emit(opname)
-                ld = self.codewriter.list_descr_for_tp(TP)
-                self.emit(self.get_position(ld))
-                self.emit_varargs(args)
-                self.register_var(op.result)
-                return
         self.emit(opname % getkind_num(self.cpu, op.result.concretetype))
         self.emit_varargs([c_func] + args)
         self.register_var(op.result)

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py	Sat Feb 14 11:52:53 2009
@@ -250,6 +250,14 @@
                 self.nodes[box] = instnode
                 self.first_escaping_op = False
                 continue
+            elif opname == 'newlist':
+                box = op.results[0]
+                instnode = InstanceNode(box, escaped=False)
+                self.nodes[box] = instnode
+                self.first_escaping_op = False
+                # XXX following guard_builtin will set the
+                #     correct class, otherwise it's a mess
+                continue
             elif opname == 'guard_builtin':
                 instnode = self.nodes[op.args[0]]
                 # all builtins have equal classes
@@ -512,6 +520,12 @@
                     key = instnode.cls.source.getint()
                     type_cache.class_size[key] = size
                     continue
+            elif opname == 'newlist':
+                instnode = self.nodes[op.results[0]]
+                if not instnode.escaped:
+                    instnode.virtual = True
+                    assert isinstance(instnode.cls.source, ListDescr)
+                    continue
             elif opname == 'setfield_gc':
                 instnode = self.nodes[op.args[0]]
                 valuenode = self.nodes[op.args[2]]

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	Sat Feb 14 11:52:53 2009
@@ -375,6 +375,7 @@
     def opimpl_residual_call_void(self, varargs):
         return self.execute_with_exc('call_void', varargs, 'void')
 
+
     @arguments("builtin", "varargs")
     def opimpl_getitem(self, descr, varargs):
         args = [descr.getfunc] + varargs
@@ -386,8 +387,19 @@
         return self.execute_with_exc('setitem', args, 'void')
 
     @arguments("builtin", "varargs")
+    def opimpl_getitem_foldable(self, descr, varargs):
+        args = [descr.getfunc] + varargs
+        return self.execute_with_exc('getitem', args, descr.tp, True)
+
+    @arguments("builtin", "varargs")
+    def opimpl_setitem_foldable(self, descr, varargs):
+        args = [descr.setfunc] + varargs
+        return self.execute_with_exc('setitem', args, 'void', True)
+
+    @arguments("builtin", "varargs")
     def opimpl_newlist(self, descr, varargs):
-        return self.execute_with_exc('newlist', varargs, 'ptr')        
+        args = [descr.malloc_func] + varargs
+        op = self.execute_with_exc('newlist', args, 'ptr')
 
     @arguments("indirectcallset", "box", "varargs")
     def opimpl_indirect_call(self, indirectcallset, box, varargs):

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vlist.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vlist.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vlist.py	Sat Feb 14 11:52:53 2009
@@ -8,8 +8,8 @@
 class ListTests:
 
     def check_all_virtualized(self):
-        self.check_loops(new=0, new_with_vtable=0,
-                                call__4=0, call__8=0, call_ptr=0)
+        self.check_loops(new=0, newlist=0,
+                         getitem=0, setitem=0)
 
     def test_simple_array(self):
         jitdriver = JitDriver(greens = [], reds = ['n'])
@@ -22,7 +22,7 @@
             return n
         res = self.meta_interp(f, [10])
         assert res == 0
-        get_stats().check_loops(int_sub=1)
+        self.check_loops(int_sub=1)
         self.check_all_virtualized()
 
     def test_append_pop(self):



More information about the Pypy-commit mailing list