Author: Armin Rigo <[email protected]>
Branch: partial-virtualizable
Changeset: r44323:4397483f3694
Date: 2011-05-20 11:38 +0200
http://bitbucket.org/pypy/pypy/changeset/4397483f3694/

Log:    Giant hack. See comments in optimizeopt/virtualize.py

diff --git a/pypy/jit/backend/llgraph/llimpl.py 
b/pypy/jit/backend/llgraph/llimpl.py
--- a/pypy/jit/backend/llgraph/llimpl.py
+++ b/pypy/jit/backend/llgraph/llimpl.py
@@ -1564,6 +1564,9 @@
     assert list(argsiter_f) == []
     return args
 
+def do_partial_virtualizable(virtualizable):
+    pass
+
 
 # for ootype meth and staticmeth
 def call_maybe_on_top_of_llinterp(meth, args):
diff --git a/pypy/jit/metainterp/executor.py b/pypy/jit/metainterp/executor.py
--- a/pypy/jit/metainterp/executor.py
+++ b/pypy/jit/metainterp/executor.py
@@ -323,6 +323,7 @@
                          rop.JIT_DEBUG,
                          rop.SETARRAYITEM_RAW,
                          rop.QUASIIMMUT_FIELD,
+                         rop.PARTIAL_VIRTUALIZABLE,
                          ):      # list of opcodes never executed by pyjitpl
                 continue
             raise AssertionError("missing %r" % (key,))
diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py
--- a/pypy/jit/metainterp/history.py
+++ b/pypy/jit/metainterp/history.py
@@ -211,6 +211,10 @@
     def get_jitcode_for_class(self, oocls):
         return self.jitcodes[oocls]
 
+class JitDriverDescr(AbstractDescr):
+    def __init__(self, jitdriver_sd):
+        self.jitdriver_sd = jitdriver_sd
+
 
 class Const(AbstractValue):
     __slots__ = ()
diff --git a/pypy/jit/metainterp/optimizeopt/simplify.py 
b/pypy/jit/metainterp/optimizeopt/simplify.py
--- a/pypy/jit/metainterp/optimizeopt/simplify.py
+++ b/pypy/jit/metainterp/optimizeopt/simplify.py
@@ -25,6 +25,9 @@
         #     but it's a bit hard to implement robustly if heap.py is also run
         pass
 
+    def optimize_PARTIAL_VIRTUALIZABLE(self, op):
+        pass
+
     def propagate_forward(self, op):
         opnum = op.getopnum()
         for value, func in optimize_ops:
diff --git a/pypy/jit/metainterp/optimizeopt/virtualize.py 
b/pypy/jit/metainterp/optimizeopt/virtualize.py
--- a/pypy/jit/metainterp/optimizeopt/virtualize.py
+++ b/pypy/jit/metainterp/optimizeopt/virtualize.py
@@ -1,3 +1,4 @@
+from pypy.jit.metainterp import history
 from pypy.jit.metainterp.history import Const, ConstInt, BoxInt
 from pypy.jit.metainterp.resoperation import rop, ResOperation
 from pypy.jit.metainterp.optimizeutil import _findall, sort_descrs
@@ -435,6 +436,32 @@
         ###self.heap_op_optimizer.optimize_SETARRAYITEM_GC(op, value, 
fieldvalue)
         self.emit_operation(op)
 
+    def optimize_PARTIAL_VIRTUALIZABLE(self, op):
+        value = self.getvalue(op.getarg(0))
+        if value.is_virtual():
+            jddescr = op.getdescr()
+            assert isinstance(jddescr, history.JitDriverDescr)
+            vinfo = jddescr.jitdriver_sd.virtualizable_info
+            # XXX giant hack.  The idea is that this virtual will be passed
+            # as the virtualizable to the CALL_ASSEMBLER operation that
+            # follows, so it will be forced.  But we will also pass the
+            # virtualizable fields explicitly as arguments to CALL_ASSEMBLER,
+            # which have already been read out of the virtual just before.
+            # The following hackery resets the fields to their NULL/0 value,
+            # which has (only) the effect that forcing the virtual will not
+            # write anything in these fields.
+            assert isinstance(value, AbstractVirtualStructValue)
+            for descr in vinfo.static_field_descrs:
+                try:
+                    del value._fields[descr]
+                except KeyError:
+                    pass
+            for descr in vinfo.array_field_descrs:
+                avalue = value.getfield(descr, None)
+                if isinstance(avalue, VArrayValue):
+                    for i in range(len(avalue._items)):
+                        avalue._items[i] = avalue.constvalue
+
     def propagate_forward(self, op):
         opnum = op.getopnum()
         for value, func in optimize_ops:
diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py
--- a/pypy/jit/metainterp/pyjitpl.py
+++ b/pypy/jit/metainterp/pyjitpl.py
@@ -2340,6 +2340,9 @@
             vbox = args[index]
             args = args + self.gen_load_from_other_virtualizable(vinfo, vbox)
             # ^^^ and not "+=", which makes 'args' a resizable list
+            jddescr = history.JitDriverDescr(targetjitdriver_sd)
+            self.history.record(rop.PARTIAL_VIRTUALIZABLE, [vbox], None,
+                                descr=jddescr)
         warmrunnerstate = targetjitdriver_sd.warmstate
         token = warmrunnerstate.get_assembler_token(greenargs, args)
         op = op.copy_and_change(rop.CALL_ASSEMBLER, args=args, descr=token)
diff --git a/pypy/jit/metainterp/resoperation.py 
b/pypy/jit/metainterp/resoperation.py
--- a/pypy/jit/metainterp/resoperation.py
+++ b/pypy/jit/metainterp/resoperation.py
@@ -478,6 +478,7 @@
     'COPYSTRCONTENT/5',       # src, dst, srcstart, dststart, length
     'COPYUNICODECONTENT/5',
     'QUASIIMMUT_FIELD/1d',    # [objptr], descr=SlowMutateDescr
+    'PARTIAL_VIRTUALIZABLE/1d',  # removed before it's passed to the backend
 
     '_CANRAISE_FIRST', # ----- start of can_raise operations -----
     '_CALL_FIRST',
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to