[pypy-svn] r68671 - in pypy/branch/warmspot-jitinfo/pypy: jit/metainterp jit/metainterp/test module/pypyjit rlib

arigo at codespeak.net arigo at codespeak.net
Tue Oct 20 21:36:35 CEST 2009


Author: arigo
Date: Tue Oct 20 21:36:33 2009
New Revision: 68671

Modified:
   pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/test/test_warmstate.py
   pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/test/test_ztranslation.py
   pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/virtualizable.py
   pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/warmspot.py
   pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/warmstate.py
   pypy/branch/warmspot-jitinfo/pypy/module/pypyjit/interp_jit.py
   pypy/branch/warmspot-jitinfo/pypy/rlib/jit.py
Log:
Fix test_ztranslation.


Modified: pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/test/test_warmstate.py
==============================================================================
--- pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/test/test_warmstate.py	(original)
+++ pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/test/test_warmstate.py	Tue Oct 20 21:36:33 2009
@@ -87,7 +87,7 @@
         _TYPE = llmemory.GCREF
     celldict = {}
     def getter(x, y):
-        return celldict[x, y]
+        return celldict.get((x, y))
     def setter(newcell, x, y):
         newcell.x = x
         newcell.y = y

Modified: pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/test/test_ztranslation.py
==============================================================================
--- pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/test/test_ztranslation.py	(original)
+++ pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/test/test_ztranslation.py	Tue Oct 20 21:36:33 2009
@@ -4,6 +4,8 @@
 from pypy.rlib.jit import JitDriver, OPTIMIZER_FULL, unroll_parameters
 from pypy.rlib.jit import PARAMETERS, dont_look_inside
 from pypy.jit.metainterp.jitprof import Profiler
+from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.ootypesystem import ootype
 
 class TranslationTest:
 
@@ -18,6 +20,7 @@
         # - set_param interface
         # - profiler
         # - full optimizer
+        # - jitdriver hooks
 
         class Frame(object):
             _virtualizable2_ = ['i']
@@ -25,8 +28,24 @@
             def __init__(self, i):
                 self.i = i
 
+        class JitCellCache:
+            entry = None
+        jitcellcache = JitCellCache()
+        def set_jitcell_at(entry):
+            jitcellcache.entry = entry
+        def get_jitcell_at():
+            return jitcellcache.entry
+        def get_printable_location():
+            return '(hello world)'
+        def can_inline():
+            return False
+
         jitdriver = JitDriver(greens = [], reds = ['frame', 'total'],
-                              virtualizables = ['frame'])
+                              virtualizables = ['frame'],
+                              get_jitcell_at=get_jitcell_at,
+                              set_jitcell_at=set_jitcell_at,
+                              get_printable_location=get_printable_location,
+                              can_inline=can_inline)
         def f(i):
             for param in unroll_parameters:
                 defl = PARAMETERS[param]

Modified: pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/virtualizable.py
==============================================================================
--- pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/virtualizable.py	(original)
+++ pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/virtualizable.py	Tue Oct 20 21:36:33 2009
@@ -6,7 +6,7 @@
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.jit.metainterp.typesystem import deref, fieldType, arrayItem
 from pypy.jit.metainterp import history
-from pypy.jit.metainterp.warmspot import wrap, unwrap
+from pypy.jit.metainterp.warmstate import wrap, unwrap
 
 
 class VirtualizableInfo:

Modified: pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/warmspot.py	(original)
+++ pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/warmspot.py	Tue Oct 20 21:36:33 2009
@@ -309,33 +309,37 @@
             annhelper.finish()
         
     def make_driverhook_graphs(self):
+        from pypy.rlib.jit import BaseJitCell
+        bk = self.rtyper.annotator.bookkeeper
+        classdef = bk.getuniqueclassdef(BaseJitCell)
+        s_BaseJitCell_or_None = annmodel.SomeInstance(classdef,
+                                                      can_be_None=True)
+        s_BaseJitCell_not_None = annmodel.SomeInstance(classdef)
+        s_Str = annmodel.SomeString()
+        #
         annhelper = MixLevelHelperAnnotator(self.translator.rtyper)
-        blackboxtype = self.cpu.ts.BASETYPE
         self.set_jitcell_at_ptr = self._make_hook_graph(
-            annhelper, self.jitdriver.set_jitcell_at, None, blackboxtype)
+            annhelper, self.jitdriver.set_jitcell_at, annmodel.s_None,
+            s_BaseJitCell_not_None)
         self.get_jitcell_at_ptr = self._make_hook_graph(
-            annhelper, self.jitdriver.get_jitcell_at, blackboxtype)
+            annhelper, self.jitdriver.get_jitcell_at, s_BaseJitCell_or_None)
         self.can_inline_ptr = self._make_hook_graph(
-            annhelper, self.jitdriver.can_inline, bool)
+            annhelper, self.jitdriver.can_inline, annmodel.s_Bool)
         self.get_printable_location_ptr = self._make_hook_graph(
-            annhelper, self.jitdriver.get_printable_location, str)
+            annhelper, self.jitdriver.get_printable_location, s_Str)
         annhelper.finish()
 
-    def _make_hook_graph(self, annhelper, func, rettype, first_arg_type=None):
-        from pypy.annotation.signature import annotationoftype
+    def _make_hook_graph(self, annhelper, func, s_result, s_first_arg=None):
         if func is None:
             return None
-        if rettype is not None:
-            s_result = annotationoftype(rettype)
-            RETTYPE = annhelper.rtyper.getrepr(s_result).lowleveltype
-        else:
-            RETTYPE = lltype.Void
-        FUNC, PTR = self.cpu.ts.get_FuncType(self.green_args_spec, RETTYPE)
+        #
+        extra_args_s = []
+        if s_first_arg is not None:
+            extra_args_s.append(s_first_arg)
+        #
         args_s = self.portal_args_s[:len(self.green_args_spec)]
-        if first_arg_type is not None:
-            args_s.insert(0, annotationoftype(first_arg_type))
-        graph = annhelper.getgraph(func, args_s, s_result)
-        funcptr = annhelper.graph2delayed(graph, FUNC)
+        graph = annhelper.getgraph(func, extra_args_s + args_s, s_result)
+        funcptr = annhelper.graph2delayed(graph)
         return funcptr
 
     def make_args_specification(self):

Modified: pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/warmstate.py
==============================================================================
--- pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/warmstate.py	(original)
+++ pypy/branch/warmspot-jitinfo/pypy/jit/metainterp/warmstate.py	Tue Oct 20 21:36:33 2009
@@ -1,13 +1,15 @@
 import sys
 from pypy.rpython.lltypesystem import lltype, llmemory, rstr
 from pypy.rpython.ootypesystem import ootype
-from pypy.rpython.annlowlevel import hlstr
+from pypy.rpython.annlowlevel import hlstr, cast_base_ptr_to_instance
+from pypy.rpython.annlowlevel import cast_object_to_ptr
 from pypy.rlib.objectmodel import specialize, we_are_translated, r_dict
 from pypy.rlib.rarithmetic import intmask
 from pypy.rlib.nonconst import NonConstant
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rlib.jit import PARAMETERS, OPTIMIZER_SIMPLE, OPTIMIZER_FULL
 from pypy.rlib.jit import DEBUG_PROFILE
+from pypy.rlib.jit import BaseJitCell
 from pypy.jit.metainterp import support, history
 
 # ____________________________________________________________
@@ -266,7 +268,7 @@
         if hasattr(self, 'jit_getter'):
             return self.jit_getter
         #
-        class JitCell(object):
+        class JitCell(BaseJitCell):
             counter = 0
             compiled_merge_points = None
         #
@@ -324,22 +326,41 @@
         rtyper = self.warmrunnerdesc.rtyper
         get_jitcell_at_ptr = self.warmrunnerdesc.get_jitcell_at_ptr
         set_jitcell_at_ptr = self.warmrunnerdesc.set_jitcell_at_ptr
-        cpu = self.warmrunnerdesc.cpu
+        lltohlhack = {}
         #
         def get_jitcell(*greenargs):
             fn = support.maybe_on_top_of_llinterp(rtyper, get_jitcell_at_ptr)
-            try:
-                cellref = fn(*greenargs)
-                if we_are_translated():
-                    cell = cast_base_ptr_to_instance(JitCell, cellref)
+            cellref = fn(*greenargs)
+            # <hacks>
+            if we_are_translated():
+                BASEJITCELL = lltype.typeOf(cellref)
+                cell = cast_base_ptr_to_instance(JitCell, cellref)
+            elif isinstance(cellref, (BaseJitCell, type(None))):
+                BASEJITCELL = None
+                cell = cellref
+            else:
+                BASEJITCELL = lltype.typeOf(cellref)
+                if cellref:
+                    cell = lltohlhack[rtyper.type_system.deref(cellref)]
                 else:
-                    cell = cellref
-            except KeyError:
+                    cell = None
+            # </hacks>
+            if cell is None:
                 cell = JitCell()
+                # <hacks>
                 if we_are_translated():
-                    cellref = cpu.ts.cast_instance_to_base_ref(cell)
-                else:
+                    cellref = cast_object_to_ptr(BASEJITCELL, cell)
+                elif BASEJITCELL is None:
                     cellref = cell
+                else:
+                    if isinstance(BASEJITCELL, lltype.Ptr):
+                        cellref = lltype.malloc(BASEJITCELL.TO)
+                    elif isinstance(BASEJITCELL, ootype.Instance):
+                        cellref = ootype.new(BASEJITCELL)
+                    else:
+                        assert False, "no clue"
+                    lltohlhack[rtyper.type_system.deref(cellref)] = cell
+                # </hacks>
                 fn = support.maybe_on_top_of_llinterp(rtyper,
                                                       set_jitcell_at_ptr)
                 fn(cellref, *greenargs)
@@ -367,6 +388,7 @@
                 set_future_values_from_vinfo(*redargs)
         #
         if vinfo is not None:
+            i0 = len(warmrunnerdesc.red_args_types)
             num_green_args = warmrunnerdesc.num_green_args
             vable_static_fields = unrolling_iterable(
                 zip(vinfo.static_extra_types, vinfo.static_fields))
@@ -376,6 +398,7 @@
             getarrayitem = cpu.ts.getarrayitem
             #
             def set_future_values_from_vinfo(*redargs):
+                i = i0
                 virtualizable = redargs[vinfo.index_of_virtualizable -
                                         num_green_args]
                 virtualizable = vinfo.cast_to_vtype(virtualizable)

Modified: pypy/branch/warmspot-jitinfo/pypy/module/pypyjit/interp_jit.py
==============================================================================
--- pypy/branch/warmspot-jitinfo/pypy/module/pypyjit/interp_jit.py	(original)
+++ pypy/branch/warmspot-jitinfo/pypy/module/pypyjit/interp_jit.py	Tue Oct 20 21:36:33 2009
@@ -50,7 +50,7 @@
 def leave(next_instr, pycode, frame, ec):
     from pypy.interpreter.executioncontext import ExecutionContext
     # can't use a method here, since this function is seen later than the main
-    # annotation
+    # annotation       XXX no longer true, could be fixed
     ExecutionContext._jit_rechain_frame(ec, frame)
 
 class PyPyJitDriver(JitDriver):

Modified: pypy/branch/warmspot-jitinfo/pypy/rlib/jit.py
==============================================================================
--- pypy/branch/warmspot-jitinfo/pypy/rlib/jit.py	(original)
+++ pypy/branch/warmspot-jitinfo/pypy/rlib/jit.py	Tue Oct 20 21:36:33 2009
@@ -94,7 +94,6 @@
 
 PARAMETERS = {'threshold': 1000,
               'trace_eagerness': 200,
-              'hash_bits': 14,
               'trace_limit': 10000,
               'inlining': False,
               'optimizer': OPTIMIZER_FULL,
@@ -114,6 +113,7 @@
     virtualizables = []
     
     def __init__(self, greens=None, reds=None, virtualizables=None,
+                 get_jitcell_at=None, set_jitcell_at=None,
                  can_inline=None, get_printable_location=None,
                  leave=None):
         if greens is not None:
@@ -128,6 +128,8 @@
             assert v in self.reds
         self._alllivevars = dict.fromkeys(self.greens + self.reds)
         self._make_extregistryentries()
+        self.get_jitcell_at = get_jitcell_at
+        self.set_jitcell_at = set_jitcell_at
         self.get_printable_location = get_printable_location
         self.can_inline = can_inline
         self.leave = leave
@@ -194,6 +196,10 @@
 #
 # Annotation and rtyping of some of the JitDriver methods
 
+class BaseJitCell(object):
+    __slots__ = ()
+
+
 class ExtEnterLeaveMarker(ExtRegistryEntry):
     # Replace a call to myjitdriver.jit_merge_point(**livevars)
     # with an operation jit_marker('jit_merge_point', myjitdriver, livevars...)
@@ -218,17 +224,21 @@
 
     def annotate_hooks(self, **kwds_s):
         driver = self.instance.im_self
+        s_jitcell = self.bookkeeper.valueoftype(BaseJitCell)
+        self.annotate_hook(driver.get_jitcell_at, driver.greens, **kwds_s)
+        self.annotate_hook(driver.set_jitcell_at, driver.greens, [s_jitcell],
+                           **kwds_s)
         self.annotate_hook(driver.can_inline, driver.greens, **kwds_s)
         self.annotate_hook(driver.get_printable_location, driver.greens, **kwds_s)
         self.annotate_hook(driver.leave, driver.greens + driver.reds, **kwds_s)
 
-    def annotate_hook(self, func, variables, **kwds_s):
+    def annotate_hook(self, func, variables, args_s=[], **kwds_s):
         if func is None:
             return
         bk = self.bookkeeper
         s_func = bk.immutablevalue(func)
         uniquekey = 'jitdriver.%s' % func.func_name
-        args_s = []
+        args_s = args_s[:]
         for name in variables:
             s_arg = kwds_s['s_' + name]
             args_s.append(s_arg)



More information about the Pypy-commit mailing list