[pypy-svn] r65979 - in pypy/branch/pyjitpl5/pypy/module/pypyjit: . test
fijal at codespeak.net
fijal at codespeak.net
Fri Jun 26 00:30:14 CEST 2009
Author: fijal
Date: Fri Jun 26 00:30:14 2009
New Revision: 65979
Added:
pypy/branch/pyjitpl5/pypy/module/pypyjit/test/test_can_inline.py (contents, props changed)
Modified:
pypy/branch/pyjitpl5/pypy/module/pypyjit/interp_jit.py
Log:
Implement inlining heuristics for pypy (without caching). Not that it is
disabled completely, it has no effect unless you enable it by hand in warmspot
Modified: pypy/branch/pyjitpl5/pypy/module/pypyjit/interp_jit.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/module/pypyjit/interp_jit.py (original)
+++ pypy/branch/pyjitpl5/pypy/module/pypyjit/interp_jit.py Fri Jun 26 00:30:14 2009
@@ -15,12 +15,45 @@
from pypy.interpreter.pyframe import PyFrame
from pypy.interpreter.function import Function
from pypy.interpreter.pyopcode import ExitFrame
+from pypy.rpython.annlowlevel import cast_base_ptr_to_instance
+from pypy.tool.stdlib_opcode import opcodedesc, HAVE_ARGUMENT
+from opcode import opmap
+from pypy.rlib.objectmodel import we_are_translated
PyFrame._virtualizable2_ = ['last_instr',
'valuestackdepth', 'valuestack_w[*]',
'fastlocals_w[*]',
]
+JUMP_ABSOLUTE = opmap['JUMP_ABSOLUTE']
+
+def can_inline(next_instr, bytecode):
+ if we_are_translated():
+ bytecode = cast_base_ptr_to_instance(Pycode, bytecode)
+ co_code = bytecode.co_code
+ next_instr = 0
+ while next_instr < len(co_code):
+ opcode = ord(co_code[next_instr])
+ next_instr += 1
+ if opcode >= HAVE_ARGUMENT:
+ lo = ord(co_code[next_instr])
+ hi = ord(co_code[next_instr+1])
+ next_instr += 2
+ oparg = (hi << 8) | lo
+ else:
+ oparg = 0
+ while opcode == opcodedesc.EXTENDED_ARG.index:
+ opcode = ord(co_code[next_instr])
+ if opcode < HAVE_ARGUMENT:
+ raise BytecodeCorruption
+ lo = ord(co_code[next_instr+1])
+ hi = ord(co_code[next_instr+2])
+ next_instr += 3
+ oparg = (oparg << 16) | (hi << 8) | lo
+ if opcode == JUMP_ABSOLUTE:
+ return False
+ return True
+
class PyPyJitDriver(JitDriver):
reds = ['frame', 'ec']
greens = ['next_instr', 'pycode']
@@ -34,7 +67,7 @@
## blockstack = frame.blockstack
## return (valuestackdepth, blockstack)
-pypyjitdriver = PyPyJitDriver()
+pypyjitdriver = PyPyJitDriver(can_inline = can_inline)
class __extend__(PyFrame):
Added: pypy/branch/pyjitpl5/pypy/module/pypyjit/test/test_can_inline.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/module/pypyjit/test/test_can_inline.py Fri Jun 26 00:30:14 2009
@@ -0,0 +1,14 @@
+
+from pypy.module.pypyjit.interp_jit import can_inline
+
+def test_one():
+ def f():
+ pass
+ assert can_inline(0, f.func_code)
+ def f():
+ while i < 0:
+ pass
+ assert not can_inline(0, f.func_code)
+ def f(a, b):
+ return a + b
+ assert can_inline(0, f.func_code)
More information about the Pypy-commit
mailing list