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

arigo at codespeak.net arigo at codespeak.net
Thu Jul 23 19:11:09 CEST 2009


Author: arigo
Date: Thu Jul 23 19:11:08 2009
New Revision: 66550

Modified:
   pypy/branch/pyjitpl5-optimize4/pypy/jit/backend/llgraph/runner.py
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/codewriter.py
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/heaptracker.py
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/resume.py
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizefindnode.py
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_resume.py
Log:
In-progress.  Main change: NEW_WITH_VTABLE no longer takes a 'descr',
because it can more easily fish it from a global table when needed.
It avoids adding a 'descr' everywhere starting from the SpecNodes.


Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/backend/llgraph/runner.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/backend/llgraph/runner.py	Thu Jul 23 19:11:08 2009
@@ -268,19 +268,23 @@
         return history.BoxInt(llimpl.do_arraylen_gc(arraydescr, array))
 
     def do_strlen(self, args, descr=None):
+        assert descr is None
         string = args[0].getptr_base()
         return history.BoxInt(llimpl.do_strlen(0, string))
 
     def do_strgetitem(self, args, descr=None):
+        assert descr is None
         string = args[0].getptr_base()
         index = args[1].getint()
         return history.BoxInt(llimpl.do_strgetitem(0, string, index))
 
     def do_unicodelen(self, args, descr=None):
+        assert descr is None
         string = args[0].getptr_base()
         return history.BoxInt(llimpl.do_unicodelen(0, string))
 
     def do_unicodegetitem(self, args, descr=None):
+        assert descr is None
         string = args[0].getptr_base()
         index = args[1].getint()
         return history.BoxInt(llimpl.do_unicodegetitem(0, string, index))
@@ -319,8 +323,10 @@
     def do_new(self, args, size):
         return history.BoxPtr(llimpl.do_new(size.ofs))
 
-    def do_new_with_vtable(self, args, size):
+    def do_new_with_vtable(self, args, descr=None):
+        assert descr is None
         vtable = args[0].getint()
+        size = self.class_sizes[vtable]    # attribute set by codewriter.py
         result = llimpl.do_new(size.ofs)
         llimpl.do_setfield_gc_int(result, self.fielddescrof_vtable.ofs,
                                   vtable, self.memo_cast)
@@ -365,20 +371,24 @@
                                        self.memo_cast)
 
     def do_newstr(self, args, descr=None):
+        assert descr is None
         length = args[0].getint()
         return history.BoxPtr(llimpl.do_newstr(0, length))
 
     def do_newunicode(self, args, descr=None):
+        assert descr is None
         length = args[0].getint()
         return history.BoxPtr(llimpl.do_newunicode(0, length))
 
     def do_strsetitem(self, args, descr=None):
+        assert descr is None
         string = args[0].getptr_base()
         index = args[1].getint()
         newvalue = args[2].getint()
         llimpl.do_strsetitem(0, string, index, newvalue)
 
     def do_unicodesetitem(self, args, descr=None):
+        assert descr is None
         string = args[0].getptr_base()
         index = args[1].getint()
         newvalue = args[2].getint()
@@ -401,11 +411,13 @@
             llimpl.do_call_void(func, self.memo_cast)
 
     def do_cast_int_to_ptr(self, args, descr=None):
+        assert descr is None
         return history.BoxPtr(llimpl.cast_from_int(llmemory.GCREF,
                                                    args[0].getint(),
                                                    self.memo_cast))
 
     def do_cast_ptr_to_int(self, args, descr=None):
+        assert descr is None
         return history.BoxInt(llimpl.cast_to_int(args[0].getptr_base(),
                                                         self.memo_cast))
 
@@ -511,7 +523,7 @@
         # XXX: return None if RESULT is Void
         return x
 
-    def do_oosend(self, args, descr=None):
+    def do_oosend(self, args, descr):
         assert isinstance(descr, MethDescr)
         selfbox = args[0]
         argboxes = args[1:]

Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/codewriter.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/codewriter.py	Thu Jul 23 19:11:08 2009
@@ -134,7 +134,7 @@
         if self.portal_graph is None or graph is self.portal_graph:
             return ()
         fnptr = self.rtyper.getcallable(graph)
-        if self.metainterp_sd.cpu.is_oo:
+        if self.cpu.is_oo:
             if oosend_methdescr:
                 return (None, oosend_methdescr)
             else:
@@ -742,8 +742,8 @@
             # store the vtable as an address -- that's fine, because the
             # GC doesn't need to follow them
             self.emit('new_with_vtable',
-                      self.get_position(self.cpu.sizeof(STRUCT)),
                       self.const_position(vtable))
+            self.codewriter.register_known_gctype(vtable, STRUCT)
         else:
             self.emit('new', self.get_position(self.cpu.sizeof(STRUCT)))
         self.register_var(op.result)

Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/heaptracker.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/heaptracker.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/heaptracker.py	Thu Jul 23 19:11:08 2009
@@ -86,35 +86,4 @@
         vtable.name[i] = namez[i]
     testing_gcstruct2vtable[GCSTRUCT] = vtable
 
-def populate_type_cache(graphs, cpu):
-    if not cpu.translate_support_code:
-        cache = {}
-    else:
-        cache = []
-    for graph in graphs:
-        for block in graph.iterblocks():
-            for op in block.operations:
-                if not cpu.is_oo and op.opname == 'malloc':
-                    STRUCT = op.args[0].value
-                    if isinstance(STRUCT, lltype.GcStruct):
-                        vtable = get_vtable_for_gcstruct(cpu, STRUCT)
-                        if vtable:
-                            if not cpu.translate_support_code:
-                                vt = cpu.cast_adr_to_int(
-                                    llmemory.cast_ptr_to_adr(vtable))
-                                cache[vt] = cpu.sizeof(STRUCT)
-                            else:
-                                vt = llmemory.cast_ptr_to_adr(vtable)
-                                cache.append((vt, cpu.sizeof(STRUCT)))
-                elif cpu.is_oo and op.opname == 'new':
-                    TYPE = op.args[0].value
-                    if isinstance(TYPE, ootype.OOType):
-                        cls = ootype.cast_to_object(ootype.runtimeClass(TYPE))
-                        typedescr = cpu.typedescrof(TYPE)
-                        if not cpu.translate_support_code:
-                            cache[cls] = typedescr
-                        else:
-                            cache.append((cls, typedescr))
-    return cache
-
 testing_gcstruct2vtable = {}

Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py	Thu Jul 23 19:11:08 2009
@@ -37,9 +37,11 @@
     def force_box(self):
         return self.box
 
-    def get_args_for_fail(self, srcbox, modifier):
-        if self.is_constant():
-            modifier.make_constant(srcbox, self.box)
+    def get_key_box(self):
+        return self.box
+
+    def get_args_for_fail(self, modifier):
+        pass
 
     def is_constant(self):
         return self.level == LEVEL_CONSTANT
@@ -91,8 +93,10 @@
     box = None
     level = LEVEL_KNOWNCLASS
 
-    def __init__(self, optimizer, source_op=None):
+    def __init__(self, optimizer, known_class, keybox, source_op=None):
         self.optimizer = optimizer
+        self.known_class = known_class
+        self.keybox = keybox   # only used as a key in dictionaries
         self.source_op = source_op  # the NEW_WITH_VTABLE operation building it
         self._fields = av_newdict()
 
@@ -119,20 +123,21 @@
                 newoperations.append(op)
         return self.box
 
-    def get_args_for_fail(self, srcbox, modifier):
-        if self.box is not None:
-            InstanceValue.get_args_for_fail(self, srcbox, modifier)
-        else:
-            xxxxx
-            if self.source_op is not None: #otherwise, no loop detection needed
-                keybox = self.source_op.result
-                if keybox in memo:
-                    return
-                memo[keybox] = None
+    def get_key_box(self):
+        if self.box is None:
+            return self.keybox
+        return self.box
+
+    def get_args_for_fail(self, modifier):
+        if self.box is None and not modifier.is_virtual(self.keybox):
             lst = self._fields.keys()
             sort_descrs(lst)
+            fieldboxes = [self._fields[ofs].get_key_box() for ofs in lst]
+            modifier.make_virtual(self.keybox, self.known_class,
+                                  lst, fieldboxes)
             for ofs in lst:
-                self._fields[ofs].get_args_for_fail(list, memo)
+                fieldvalue = self._fields[ofs]
+                fieldvalue.get_args_for_fail(modifier)
 
 
 class __extend__(SpecNode):
@@ -143,7 +148,7 @@
 
 class __extend__(VirtualInstanceSpecNode):
     def setup_virtual_node(self, optimizer, box, newinputargs):
-        vvalue = optimizer.make_virtual(box)
+        vvalue = optimizer.make_virtual(self.known_class, box)
         for ofs, subspecnode in self.fields:
             subbox = optimizer.new_box(ofs)
             vvalue.setfield(ofs, optimizer.getvalue(subbox))
@@ -187,8 +192,8 @@
     def known_nonnull(self, box):
         return self.getvalue(box).is_nonnull()
 
-    def make_virtual(self, box, source_op=None):
-        vvalue = VirtualValue(self, source_op)
+    def make_virtual(self, known_class, box, source_op=None):
+        vvalue = VirtualValue(self, known_class, box, source_op)
         self.make_equal_to(box, vvalue)
         return vvalue
 
@@ -259,21 +264,28 @@
         assert op_fail.opnum == rop.FAIL
         #
         if not we_are_translated() and op_fail.descr is None:  # for tests
-            op_fail.descr = Storage()
-            resume.ResumeDataBuilder()
-            resume.generate_boxes(op_fail.args)
-            resume.finish(op_fail.descr)
-        modifier = resume.ResumeDataVirtualAdder(op_fail.descr, op_fail.args)
+            descr = Storage()
+            builder = resume.ResumeDataBuilder()
+            builder.generate_boxes(op_fail.args)
+            builder.finish(descr)
+        else:
+            descr = op_fail.descr
+        oldboxes = []
+        for box in op_fail.args:
+            if box in self.values:
+                box = self.values[box].get_key_box()   # may be a Const, too
+            oldboxes.append(box)
+        modifier = resume.ResumeDataVirtualAdder(descr, oldboxes)
         for box in op_fail.args:
             if box in self.values:
                 value = self.values[box]
-                value.get_args_for_fail(box, modifier)
+                value.get_args_for_fail(modifier)
         newboxes = modifier.finish()
-        # NB. we mutate op_fail in-place below, as well as op_fail.descr
+        # XXX we mutate op_fail in-place below, as well as op_fail.descr
         # via the ResumeDataVirtualAdder.  That's bad.  Hopefully
         # it does not really matter because no-one is going to look again
-        # at its unoptimized version.  We cannot really clone it because of
-        # how the rest works (e.g. it is returned by cpu.execute_operations()).
+        # at its unoptimized version.  We should really clone it (and
+        # the descr too).
         op_fail.args = newboxes
         op2.suboperations = op1.suboperations
         op1.optimized = op2
@@ -402,7 +414,7 @@
             self.optimize_default(op)
 
     def optimize_NEW_WITH_VTABLE(self, op):
-        self.make_virtual(op.result, op)
+        self.make_virtual(op.args[0], op.result, op)
 
 
 optimize_ops = _findall(Optimizer, 'optimize_')

Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/pyjitpl.py	Thu Jul 23 19:11:08 2009
@@ -7,7 +7,6 @@
 from pypy.jit.metainterp import history, compile, resume
 from pypy.jit.metainterp.history import Const, ConstInt, Box
 from pypy.jit.metainterp.resoperation import rop
-from pypy.jit.metainterp.heaptracker import populate_type_cache
 from pypy.jit.metainterp import codewriter, executor
 from pypy.jit.metainterp import typesystem
 from pypy.rlib.rarithmetic import intmask
@@ -310,9 +309,9 @@
     def opimpl_new(self, size):
         self.execute(rop.NEW, [], descr=size)
 
-    @arguments("descr", "constbox")
-    def opimpl_new_with_vtable(self, size, vtablebox):
-        self.execute(rop.NEW_WITH_VTABLE, [vtablebox], descr=size)
+    @arguments("constbox")
+    def opimpl_new_with_vtable(self, vtablebox):
+        self.execute(rop.NEW_WITH_VTABLE, [vtablebox])
 
     @arguments("box")
     def opimpl_runtimenew(self, classbox):
@@ -932,11 +931,6 @@
         self.opcode_implementations = []
         self.opcode_names = []
         self.opname_to_index = {}
-        self._class_sizes = populate_type_cache(graphs, self.cpu)
-        if not cpu.translate_support_code:
-            self.cpu.class_sizes = self._class_sizes
-        else:
-            self.cpu.class_sizes = None
         if optimizer is None:
             from pypy.jit.metainterp import optimize4 as optimizer
         self.optimize_loop = optimizer.optimize_loop
@@ -979,11 +973,7 @@
     def _setup_once(self):
         """Runtime setup needed by the various components of the JIT."""
         if not self.globaldata.initialized:
-            if self.cpu.class_sizes is None:
-                cs = {}
-                for key, value in self._class_sizes:
-                    cs[key] = value
-                self.cpu.class_sizes = cs
+            xxxxxxxx
             self.cpu.setup_once()
             log(self.jit_starting_line)
             if not self.profiler.initialized:

Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/resume.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/resume.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/resume.py	Thu Jul 23 19:11:08 2009
@@ -59,24 +59,26 @@
         assert storage.rd_virtuals is None
         self.original_liveboxes = liveboxes
         self.liveboxes = {}
-        for box in liveboxes:
-            self.liveboxes[box] = 0
-        self.liveboxes_order = liveboxes[:]
+        self.liveboxes_order = []
+        self._register_boxes(liveboxes)
         self.virtuals = []
         self.vfieldboxes = []
 
     def make_constant(self, box, const):
-        assert self.liveboxes[box] == 0
-        self.liveboxes[box] = self._getconstindex(const)
+        # this part of the interface is not used so far by optimizeopt.py
+        if self.liveboxes[box] == 0:
+            self.liveboxes[box] = self._getconstindex(const)
 
-    def make_virtual(self, virtualbox, known_class, sizedescr,
-                     fielddescrs, fieldboxes):
+    def make_virtual(self, virtualbox, known_class, fielddescrs, fieldboxes):
         assert self.liveboxes[virtualbox] == 0
         self.liveboxes[virtualbox] = len(self.virtuals) | VIRTUAL_FLAG
-        vinfo = VirtualInfo(known_class, sizedescr, fielddescrs)
+        vinfo = VirtualInfo(known_class, fielddescrs)
         self.virtuals.append(vinfo)
         self.vfieldboxes.append(fieldboxes)
-        for box in fieldboxes:
+        self._register_boxes(fieldboxes)
+
+    def _register_boxes(self, boxes):
+        for box in boxes:
             if isinstance(box, Box):
                 self.liveboxes.setdefault(box, 0)
                 self.liveboxes_order.append(box)
@@ -95,7 +97,7 @@
             num = storage.rd_nums[i]
             if num >= 0:
                 box = self.original_liveboxes[num]
-                storage.rd_nums[i] = self.liveboxes[box]
+                storage.rd_nums[i] = self._getboxindex(box)
         storage.rd_virtuals = self.virtuals[:]
         for i in range(len(storage.rd_virtuals)):
             vinfo = storage.rd_virtuals[i]
@@ -117,16 +119,14 @@
 
 
 class VirtualInfo(object):
-    def __init__(self, known_class, sizedescr, fielddescrs):
+    def __init__(self, known_class, fielddescrs):
         self.known_class = known_class
-        self.sizedescr = sizedescr
         self.fielddescrs = fielddescrs
         #self.fieldnums = ...
 
     def allocate(self, metainterp):
         return metainterp.execute_and_record(rop.NEW_WITH_VTABLE,
-                                             [self.known_class],
-                                             descr=self.sizedescr)
+                                             [self.known_class])
 
     def setfields(self, metainterp, box, fn_decode_box):
         for i in range(len(self.fielddescrs)):

Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizefindnode.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizefindnode.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizefindnode.py	Thu Jul 23 19:11:08 2009
@@ -191,7 +191,7 @@
     def test_find_nodes_new_1(self):
         ops = """
         [p1]
-        p2 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p2 = new_with_vtable(ConstClass(node_vtable))
         jump(p2)
         """
         boxes, getnode = self.find_nodes(ops, 'Virtual(node_vtable)')
@@ -215,8 +215,8 @@
     def test_find_nodes_new_2(self):
         ops = """
         [i1, p1]
-        p2 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
-        p3 = new_with_vtable(ConstClass(node_vtable2), descr=nodesize2)
+        p2 = new_with_vtable(ConstClass(node_vtable))
+        p3 = new_with_vtable(ConstClass(node_vtable2))
         setfield_gc(p2, p3, descr=nextdescr)
         setfield_gc(p3, i1, descr=valuedescr)
         jump(i1, p2)
@@ -235,9 +235,9 @@
         i1 = getfield_gc(p1, descr=valuedescr)
         i2 = int_sub(i1, 1)
         sum2 = int_add(sum, i1)
-        p2 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p2 = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(p2, i2, descr=valuedescr)
-        p3 = new_with_vtable(ConstClass(node_vtable2), descr=nodesize2)
+        p3 = new_with_vtable(ConstClass(node_vtable2))
         setfield_gc(p2, p3, descr=nextdescr)
         jump(sum2, p2)
         """
@@ -273,7 +273,7 @@
     def test_find_nodes_new_aliasing_0(self):
         ops = """
         [p1, p2]
-        p3 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p3 = new_with_vtable(ConstClass(node_vtable))
         jump(p3, p3)
         """
         # both p1 and p2 must be NotSpecNodes; it's not possible to pass
@@ -291,7 +291,7 @@
         i1 = getfield_gc(p1, descr=valuedescr)
         i2 = int_sub(i1, 1)
         sum2 = int_add(sum, i1)
-        p2 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p2 = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(p2, i2, descr=valuedescr)
         setfield_gc(p2, p2, descr=nextdescr)
         jump(sum2, p2)
@@ -305,7 +305,7 @@
         ops = """
         [p1, p2]
         escape(p2)
-        p3 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p3 = new_with_vtable(ConstClass(node_vtable))
         jump(p3, p3)
         """
         # both p1 and p2 must be NotSpecNodes; it's not possible to pass
@@ -318,7 +318,7 @@
         [p1]
         guard_class(p1, ConstClass(node_vtable))
             fail()
-        p2 = new_with_vtable(ConstClass(node_vtable2), descr=nodesize2)
+        p2 = new_with_vtable(ConstClass(node_vtable2))
         jump(p2)
         """
         self.find_nodes(ops, 'Not')
@@ -330,7 +330,7 @@
             fail()
         guard_class(p1, ConstClass(node_vtable2))
             fail()
-        p2 = new_with_vtable(ConstClass(node_vtable2), descr=nodesize2)
+        p2 = new_with_vtable(ConstClass(node_vtable2))
         jump(p2, p2)
         """
         self.find_nodes(ops, 'Not, Not')
@@ -339,7 +339,7 @@
         ops = """
         [p0]
         escape(p0)
-        p1 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p1 = new_with_vtable(ConstClass(node_vtable))
         jump(p1)
         """
         self.find_nodes(ops, 'Not')
@@ -347,9 +347,9 @@
     def test_find_nodes_new_unused(self):
         ops = """
         [p0]
-        p1 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
-        p2 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
-        p3 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p1 = new_with_vtable(ConstClass(node_vtable))
+        p2 = new_with_vtable(ConstClass(node_vtable))
+        p3 = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(p1, p2, descr=nextdescr)
         setfield_gc(p2, p3, descr=nextdescr)
         jump(p1)
@@ -362,8 +362,8 @@
     def test_find_nodes_oois(self):
         ops = """
         [p3, p4, p2]
-        p0 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
-        p1 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p0 = new_with_vtable(ConstClass(node_vtable))
+        p1 = new_with_vtable(ConstClass(node_vtable))
         i1 = oononnull(p0)
         guard_true(i1)
           fail()
@@ -409,7 +409,7 @@
     def test_find_nodes_call(self):
         ops = """
         [i0, p2]
-        p0 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p0 = new_with_vtable(ConstClass(node_vtable))
         i1 = call_pure(i0, p0)     # forces p0 to not be virtual
         jump(i1, p0)
         """
@@ -421,7 +421,7 @@
         i0 = getfield_gc(p0, descr=valuedescr)
         guard_value(i0, 0)
           fail()
-        p1 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p1 = new_with_vtable(ConstClass(node_vtable))
         # the field 'value' has its default value of 0
         jump(p1)
         """
@@ -468,7 +468,7 @@
     def test_bridge_simple_virtual_1(self):
         ops = """
         [i0]
-        p0 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p0 = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(p0, i0, descr=valuedescr)
         jump(p0)
         """
@@ -517,7 +517,7 @@
     def test_bridge_virtual_mismatch_1(self):
         ops = """
         [i0]
-        p0 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p0 = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(p0, i0, descr=valuedescr)
         jump(p0, p0)
         """
@@ -551,9 +551,9 @@
     def test_bridge_unused(self):
         ops = """
         []
-        p1 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
-        p2 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
-        p3 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p1 = new_with_vtable(ConstClass(node_vtable))
+        p2 = new_with_vtable(ConstClass(node_vtable))
+        p3 = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(p1, p2, descr=nextdescr)
         setfield_gc(p2, p3, descr=nextdescr)
         jump(p1)
@@ -588,7 +588,7 @@
     def test_bridge_virtual_to_fail(self):
         ops = """
         [i1]
-        p1 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p1 = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(p1, i1, descr=valuedescr)
         fail(p1)
         """

Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py	Thu Jul 23 19:11:08 2009
@@ -4,7 +4,7 @@
                                                             OOtypeMixin,
                                                             BaseTest)
 from pypy.jit.metainterp.optimizeopt import optimize
-from pypy.jit.metainterp.history import AbstractDescr
+from pypy.jit.metainterp.history import AbstractDescr, ConstInt
 from pypy.jit.metainterp import resume
 from pypy.jit.metainterp.resoperation import rop, opname
 from pypy.jit.metainterp.test.oparser import parse
@@ -354,7 +354,7 @@
         [i, p0]
         i0 = getfield_gc(p0, descr=valuedescr)
         i1 = int_add(i0, i)
-        p1 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p1 = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(p1, i1, descr=valuedescr)
         jump(i, p1)
         """
@@ -470,7 +470,7 @@
         i0 = getfield_gc(p0, descr=valuedescr)
         guard_value(i0, 0)
           fail()
-        p1 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p1 = new_with_vtable(ConstClass(node_vtable))
         # the field 'value' has its default value of 0
         jump(p1)
         """
@@ -488,7 +488,7 @@
     def test_virtual_3(self):
         ops = """
         [i]
-        p1 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p1 = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(p1, i, descr=valuedescr)
         i0 = getfield_gc(p1, descr=valuedescr)
         i1 = int_add(i0, 1)
@@ -504,7 +504,7 @@
     def test_nonvirtual_1(self):
         ops = """
         [i]
-        p1 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p1 = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(p1, i, descr=valuedescr)
         i0 = getfield_gc(p1, descr=valuedescr)
         i1 = int_add(i0, 1)
@@ -515,7 +515,7 @@
         expected = """
         [i]
         i1 = int_add(i, 1)
-        p1 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p1 = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(p1, i, descr=valuedescr)
         escape(p1)
         escape(p1)
@@ -529,7 +529,7 @@
         i0 = getfield_gc(p0, descr=valuedescr)
         escape(p0)
         i1 = int_add(i0, i)
-        p1 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p1 = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(p1, i1, descr=valuedescr)
         jump(i, p1)
         """
@@ -539,7 +539,7 @@
     def test_getfield_gc_pure_1(self):
         ops = """
         [i]
-        p1 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p1 = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(p1, i, descr=valuedescr)
         i1 = getfield_gc_pure(p1, descr=valuedescr)
         jump(i1)
@@ -575,16 +575,14 @@
 
     # ----------
 
-    def make_fail_descr(self, boxestext):
+    def make_fail_descr(self):
         class FailDescr(AbstractDescr):
             args_seen = []
             def _oparser_uses_descr(self, oparse, args):
                 # typically called twice, before and after optimization
                 if len(self.args_seen) == 0:
-                    boxes = [oparse.box_for_var(boxtext.strip())
-                             for boxtext in boxestext.split(',')]
                     builder = resume.ResumeDataBuilder()
-                    builder.generate_boxes(boxes)
+                    builder.generate_boxes(args)
                     liveboxes = builder.finish(fdescr)
                     assert liveboxes == args
                 self.args_seen.append((args, oparse))
@@ -593,23 +591,36 @@
         self.fdescr = fdescr
         self.namespace['fdescr'] = fdescr
 
+    def unpack_expected_fail_args(self, oparse, text):
+        import re
+        r = re.compile(r"\bwhere\s+(\w+)\s+is a\s+(\w+)")
+        parts = list(r.finditer(text))
+        if parts:
+            text = text[:parts[0].start()]
+            xxx
+        return [oparse.getvar(s.strip()) for s in text.split(',')]
+
     def check_expanded_fail_descr(self, expectedtext):
         fdescr = self.fdescr
         args, oparse = fdescr.args_seen[-1]
         reader = resume.ResumeDataReader(fdescr, args, MyMetaInterp())
         boxes = reader.consume_boxes()
-        expected = [oparse.getvar(boxtext.strip())
-                    for boxtext in expectedtext.split(',')]
+        expected = self.unpack_expected_fail_args(oparse, expectedtext)
         assert boxes == expected
 
     def test_expand_fail_1(self):
-        self.make_fail_descr('i2, i3')
+        self.make_fail_descr()
         ops = """
         [i1, i3]
+        # first rename i3 into i4
+        p1 = new_with_vtable(ConstClass(node_vtable))
+        setfield_gc(p1, i3, descr=valuedescr)
+        i4 = getfield_gc(p1, descr=valuedescr)
+        #
         i2 = int_add(10, 5)
         guard_true(i1)
-            fail(i2, i3, descr=fdescr)
-        jump(i1, i3)
+            fail(i2, i4, descr=fdescr)
+        jump(i1, i4)
         """
         expected = """
         [i1, i3]
@@ -622,32 +633,33 @@
 
     def test_expand_fail_2(self):
         py.test.skip("in-progress")
+        self.make_fail_descr()
         ops = """
         [i1, i2]
-        p1 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p1 = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(p1, i2, descr=valuedescr)
         setfield_gc(p1, p1, descr=nextdescr)
         guard_true(i1)
-            fail(p1)
+            fail(p1, descr=fdescr)
         jump(i1, i2)
         """
         expected = """
         [i1, i2]
         guard_true(i1)
-            p1 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
-            setfield_gc(p1, i2, descr=valuedescr)
-            setfield_gc(p1, p1, descr=nextdescr)
-            fail(p1)
+            fail(i2, descr=fdescr)
         jump(1, i2)
         """
         self.optimize_loop(ops, 'Not, Not', expected, i1=1)
+        self.check_expanded_fail_descr('''ptr
+            where ptr is a node_vtable, valuedescr=i2
+            ''')
 
     def test_expand_fail_3(self):
         py.test.skip("in-progress")
         ops = """
         [i1, i2, i3, p3]
-        p1 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
-        p2 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        p1 = new_with_vtable(ConstClass(node_vtable))
+        p2 = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(p1, 1, descr=valuedescr)
         setfield_gc(p1, p2, descr=nextdescr)
         setfield_gc(p2, i2, descr=valuedescr)

Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_resume.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_resume.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_resume.py	Thu Jul 23 19:11:08 2009
@@ -97,13 +97,11 @@
     modifier.make_virtual(b2s,
                           ConstAddr(LLtypeMixin.node_vtable_adr,
                                     LLtypeMixin.cpu),
-                          LLtypeMixin.nodesize,
                           [LLtypeMixin.nextdescr, LLtypeMixin.valuedescr],
                           [b4s, c1s])   # new fields
     modifier.make_virtual(b4s,
                           ConstAddr(LLtypeMixin.node_vtable_adr2,
                                     LLtypeMixin.cpu),
-                          LLtypeMixin.nodesize2,
                           [LLtypeMixin.nextdescr, LLtypeMixin.valuedescr,
                                                   LLtypeMixin.otherdescr],
                           [b2s, b3s, b5s])  # new fields
@@ -143,23 +141,31 @@
 
 
 def test_virtual_adder_make_constant():
-    storage = make_demo_storage()
-    b1s, b2s, b3s = [BoxInt(1), BoxPtr(), BoxInt(3)]
-    modifier = ResumeDataVirtualAdder(storage, [b1s, b2s, b3s])
-    modifier.make_constant(b1s, ConstInt(111))           # <-------
-    assert not modifier.is_virtual(b1s)
-    assert not modifier.is_virtual(b2s)
-    assert not modifier.is_virtual(b3s)
-    # done
-    liveboxes = modifier.finish()
-    assert liveboxes == [b2s, b3s]
-    #
-    b2t, b3t = [BoxPtr(demo55o), BoxInt(33)]
-    reader = ResumeDataReader(storage, [b2t, b3t], MyMetaInterp())
-    lst = reader.consume_boxes()
-    c1t = ConstInt(111)
-    assert lst == [c1t, ConstInt(1), c1t, b2t]
-    lst = reader.consume_boxes()
-    assert lst == [ConstInt(2), ConstInt(3)]
-    lst = reader.consume_boxes()
-    assert lst == [c1t, b2t, b3t]
+    for testnumber in [0, 1]:
+        storage = make_demo_storage()
+        b1s, b2s, b3s = [BoxInt(1), BoxPtr(), BoxInt(3)]
+        if testnumber == 0:
+            # I. making a constant with make_constant()
+            modifier = ResumeDataVirtualAdder(storage, [b1s, b2s, b3s])
+            modifier.make_constant(b1s, ConstInt(111))
+            assert not modifier.is_virtual(b1s)
+        else:
+            # II. making a constant by directly specifying a constant in
+            #     the list of liveboxes
+            b1s = ConstInt(111)
+            modifier = ResumeDataVirtualAdder(storage, [b1s, b2s, b3s])
+        assert not modifier.is_virtual(b2s)
+        assert not modifier.is_virtual(b3s)
+        # done
+        liveboxes = modifier.finish()
+        assert liveboxes == [b2s, b3s]
+        #
+        b2t, b3t = [BoxPtr(demo55o), BoxInt(33)]
+        reader = ResumeDataReader(storage, [b2t, b3t], MyMetaInterp())
+        lst = reader.consume_boxes()
+        c1t = ConstInt(111)
+        assert lst == [c1t, ConstInt(1), c1t, b2t]
+        lst = reader.consume_boxes()
+        assert lst == [ConstInt(2), ConstInt(3)]
+        lst = reader.consume_boxes()
+        assert lst == [c1t, b2t, b3t]



More information about the Pypy-commit mailing list