[pypy-svn] r52755 - pypy/branch/jit-hotpath/pypy/module/pypyjit
cfbolz at codespeak.net
cfbolz at codespeak.net
Thu Mar 20 00:27:33 CET 2008
Author: cfbolz
Date: Thu Mar 20 00:27:33 2008
New Revision: 52755
Modified:
pypy/branch/jit-hotpath/pypy/module/pypyjit/interp_jit.py
Log:
(arigo, cfbolz): try to adapt the pypy python interpreter to
the hotpath way of hints. This is untested and thus likely broken.
Modified: pypy/branch/jit-hotpath/pypy/module/pypyjit/interp_jit.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/module/pypyjit/interp_jit.py (original)
+++ pypy/branch/jit-hotpath/pypy/module/pypyjit/interp_jit.py Thu Mar 20 00:27:33 2008
@@ -10,7 +10,7 @@
import sys
from pypy.tool.pairtype import extendabletype
from pypy.rlib.rarithmetic import r_uint, intmask
-from pypy.rlib.jit import hint, _is_early_constant
+from pypy.rlib.jit import hint, _is_early_constant, JitDriver
import pypy.interpreter.pyopcode # for side-effects
from pypy.interpreter.eval import Frame
from pypy.interpreter.pycode import PyCode, CO_VARARGS, CO_VARKEYWORDS
@@ -23,108 +23,74 @@
PyCode.jit_enable = False # new default attribute
super_dispatch = PyFrame.dispatch
-class __extend__(PyFrame):
-
- def dispatch(self, pycode, next_instr, ec):
- if pycode.jit_enable:
- return self.dispatch_jit(pycode, next_instr, ec)
- else:
- self = hint(self, access_directly=True)
- return super_dispatch(self, pycode, next_instr, ec)
-
- def dispatch_jit(self, pycode, next_instr, ec):
- hint(None, global_merge_point=True)
- pycode = hint(pycode, deepfreeze=True)
-
- entry_fastlocals_w = self.jit_enter_frame(pycode, next_instr)
-
- # For the sequel, force 'next_instr' to be unsigned for performance
- next_instr = r_uint(next_instr)
- co_code = pycode.co_code
-
- try:
- try:
- while True:
- hint(None, global_merge_point=True)
- next_instr = self.handle_bytecode(co_code, next_instr, ec)
- except Return:
- w_result = self.popvalue()
- self.blockstack = None
- self.valuestack_w = None
- return w_result
- except Yield:
- w_result = self.popvalue()
- return w_result
- finally:
- self.jit_leave_frame(pycode, entry_fastlocals_w)
-
- def jit_enter_frame(self, pycode, next_instr):
+class PyPyJitDriver(JitDriver):
+ reds = ['frame', 'ec']
+ greens = ['next_instr', 'pycode']
+ def on_enter_jit(self):
# *loads* of nonsense for now
+ frame = self.frame
+ pycode = self.pycode
fastlocals_w = [None] * pycode.co_nlocals
- if next_instr == 0:
- # first time we enter this function
- depth = 0
- self.blockstack = []
-
- numargs = pycode.co_argcount
- if pycode.co_flags & CO_VARARGS: numargs += 1
- if pycode.co_flags & CO_VARKEYWORDS: numargs += 1
- while True:
- numargs -= 1
- if numargs < 0:
- break
- hint(numargs, concrete=True)
- w_obj = self.fastlocals_w[numargs]
- assert w_obj is not None
- fastlocals_w[numargs] = w_obj
-
- else:
- stuff = self.valuestackdepth
- if len(self.blockstack):
- stuff |= (-sys.maxint-1)
-
- stuff = hint(stuff, promote=True)
- if stuff >= 0:
- # blockdepth == 0, common case
- self.blockstack = []
- depth = stuff & sys.maxint
+ stuff = frame.valuestackdepth
+ if len(frame.blockstack):
+ stuff |= (-sys.maxint-1)
+
+ stuff = hint(stuff, promote=True)
+ if stuff >= 0:
+ # blockdepth == 0, common case
+ # XXX or it was at some point but not now, not at all
+ # XXX as we expect to *be* in a loop...
+ frame.blockstack = []
+ depth = stuff & sys.maxint
- i = pycode.co_nlocals
- while True:
- i -= 1
- if i < 0:
- break
- hint(i, concrete=True)
- w_obj = self.fastlocals_w[i]
- fastlocals_w[i] = w_obj
+ i = pycode.co_nlocals
+ while True:
+ i -= 1
+ if i < 0:
+ break
+ hint(i, concrete=True)
+ w_obj = frame.fastlocals_w[i]
+ fastlocals_w[i] = w_obj
- self.pycode = pycode
- self.valuestackdepth = depth
+ frame.pycode = pycode
+ frame.valuestackdepth = depth
- entry_fastlocals_w = self.fastlocals_w
- self.fastlocals_w = fastlocals_w
+ frame.fastlocals_w = fastlocals_w
virtualstack_w = [None] * pycode.co_stacksize
while depth > 0:
depth -= 1
hint(depth, concrete=True)
- virtualstack_w[depth] = self.valuestack_w[depth]
- self.valuestack_w = virtualstack_w
- return entry_fastlocals_w
+ virtualstack_w[depth] = frame.valuestack_w[depth]
+ frame.valuestack_w = virtualstack_w
- def jit_leave_frame(self, pycode, entry_fastlocals_w):
- i = pycode.co_nlocals
- while True:
- i -= 1
- if i < 0:
- break
- hint(i, concrete=True)
- entry_fastlocals_w[i] = self.fastlocals_w[i]
-
- self.fastlocals_w = entry_fastlocals_w
+class __extend__(PyFrame):
+ def dispatch(self, pycode, next_instr, ec):
+ pycode = hint(pycode, deepfreeze=True)
+ next_instr = r_uint(next_instr)
+ try:
+ while True:
+ PyPyJitDriver.jit_merge_point(
+ frame=self, ec=ec, next_instr=next_instr, pycode=pycode)
+ co_code = pycode.co_code
+ next_instr = self.handle_bytecode(co_code, next_instr, ec)
+ except Return:
+ w_result = self.popvalue()
+ self.blockstack = None
+ self.valuestack_w = None
+ return w_result
+ except Yield:
+ w_result = self.popvalue()
+ return w_result
+
+ def JUMP_ABSOLUTE(f, jumpto, next_instr, *ignored):
+ ec = f.space.getexecutioncontext()
+ PyPyJitDriver.can_enter_jit(frame=f, ec=ec, next_instr=jumpto,
+ pycode=self.getcode())
+ return jumpto
PORTAL = PyFrame.dispatch_jit
More information about the Pypy-commit
mailing list