[pypy-svn] r64062 - in pypy/branch/pyjitpl5-simplify/pypy/jit: backend/minimal backend/test metainterp

arigo at codespeak.net arigo at codespeak.net
Tue Apr 14 14:42:19 CEST 2009


Author: arigo
Date: Tue Apr 14 14:42:19 2009
New Revision: 64062

Modified:
   pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/runner.py
   pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py
   pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py
Log:
Implement caching of the returned descrs
in the minimal backend.


Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/runner.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/minimal/runner.py	Tue Apr 14 14:42:19 2009
@@ -130,12 +130,28 @@
 
     # ----------
 
+    def cached_method(cachename):
+        def decorate(func):
+            def cached_func(self, *args):
+                try:
+                    return getattr(self, cachename)[args]
+                except (KeyError, AttributeError):
+                    descr = func(self, *args)
+                    if not hasattr(self, cachename):
+                        setattr(self, cachename, {})
+                    getattr(self, cachename)[args] = descr
+                    return descr
+            return cached_func
+        return decorate
+
+    @cached_method('_sizecache')
     def sizeof(self, TYPE):
         def alloc():
             p = lltype.malloc(TYPE)
             return lltype.cast_opaque_ptr(llmemory.GCREF, p)
         return SizeDescr(alloc)
 
+    @cached_method('_fieldcache')
     def fielddescrof(self, STRUCT, name):
         dict2 = base_dict.copy()
         dict2['PTR'] = lltype.Ptr(STRUCT)
@@ -156,6 +172,7 @@
         sort_key = _count_sort_key(STRUCT, name)
         return FieldDescr(dict2['getfield'], dict2['setfield'], sort_key)
 
+    @cached_method('_arraycache')
     def arraydescrof(self, ARRAY):
         dict2 = base_dict.copy()
         dict2['malloc'] = lltype.malloc
@@ -184,6 +201,7 @@
                           dict2['getarrayitem'],
                           dict2['setarrayitem'])
 
+    @cached_method('_callcache')
     def calldescrof(self, ARGS, RESULT):
         dict2 = base_dict.copy()
         args = []

Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py	Tue Apr 14 14:42:19 2009
@@ -64,7 +64,7 @@
             return chr(ord(c) + 1)
         FPTR = lltype.Ptr(lltype.FuncType([lltype.Char], lltype.Char))
         func_ptr = llhelper(FPTR, func)
-        calldescr = cpu.calldescrof([lltype.Char], lltype.Char)
+        calldescr = cpu.calldescrof((lltype.Char,), lltype.Char)
         x = cpu.do_call(
             [BoxInt(cpu.cast_adr_to_int(llmemory.cast_ptr_to_adr(func_ptr))),
              BoxInt(ord('A'))],

Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py	Tue Apr 14 14:42:19 2009
@@ -134,7 +134,7 @@
             return ()
         # </hack>
         NON_VOID_ARGS = [ARG for ARG in FUNC.ARGS if ARG is not lltype.Void]
-        calldescr = self.cpu.calldescrof(NON_VOID_ARGS, FUNC.RESULT)
+        calldescr = self.cpu.calldescrof(tuple(NON_VOID_ARGS), FUNC.RESULT)
         return (cfnptr, calldescr)
 
     def get_indirectcallset(self, graphs):
@@ -156,7 +156,7 @@
         assert NON_VOID_ARGS == [T for T in ARGS if T is not lltype.Void]
         assert RESULT == FUNC.RESULT
         # ok
-        calldescr = self.cpu.calldescrof(NON_VOID_ARGS, RESULT)
+        calldescr = self.cpu.calldescrof(tuple(NON_VOID_ARGS), RESULT)
         return calldescr, non_void_args
 
 



More information about the Pypy-commit mailing list