[pypy-svn] r35357 - in pypy/branch/jit-real-world/pypy: jit/goal module/pypyjit
arigo at codespeak.net
arigo at codespeak.net
Wed Dec 6 03:08:17 CET 2006
Author: arigo
Date: Wed Dec 6 03:08:02 2006
New Revision: 35357
Added:
pypy/branch/jit-real-world/pypy/module/pypyjit/ (props changed)
pypy/branch/jit-real-world/pypy/module/pypyjit/__init__.py (contents, props changed)
pypy/branch/jit-real-world/pypy/module/pypyjit/interp_jit.py (contents, props changed)
Modified:
pypy/branch/jit-real-world/pypy/jit/goal/jitstep.py
pypy/branch/jit-real-world/pypy/jit/goal/targetjit.py
Log:
A module 'pypyjit', enabled by the targetjit.
See the docstring of interp_jit for the purpose.
Modified: pypy/branch/jit-real-world/pypy/jit/goal/jitstep.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/jit/goal/jitstep.py (original)
+++ pypy/branch/jit-real-world/pypy/jit/goal/jitstep.py Wed Dec 6 03:08:02 2006
@@ -1,12 +1,11 @@
-from pypy.interpreter.pyframe import PyFrame
+from pypy.module.pypyjit.interp_jit import PORTAL
from pypy.objspace.flow.model import checkgraph
from pypy.translator.translator import graphof
from pypy.jit.hintannotator.annotator import HintAnnotator, HintAnnotatorPolicy
from pypy.jit.hintannotator.model import OriginFlags, SomeLLAbstractConstant
-PORTAL = PyFrame.dispatch_bytecode.im_func
-#from pypy.jit.goal.x import evaluate as PORTAL
+PORTAL = getattr(PORTAL, 'im_func', PORTAL)
class PyPyHintAnnotatorPolicy(HintAnnotatorPolicy):
Modified: pypy/branch/jit-real-world/pypy/jit/goal/targetjit.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/jit/goal/targetjit.py (original)
+++ pypy/branch/jit-real-world/pypy/jit/goal/targetjit.py Wed Dec 6 03:08:02 2006
@@ -34,6 +34,7 @@
# return main, None
def handle_config(self, config):
+ config.objspace.usemodules.pypyjit = True
config.translation.backendopt.inline_threshold = 0
config.translation.backendopt.merge_if_blocks = False
config.translation.fork_before = 'hintannotate'
Added: pypy/branch/jit-real-world/pypy/module/pypyjit/__init__.py
==============================================================================
--- (empty file)
+++ pypy/branch/jit-real-world/pypy/module/pypyjit/__init__.py Wed Dec 6 03:08:02 2006
@@ -0,0 +1,13 @@
+from pypy.interpreter.mixedmodule import MixedModule
+
+class Module(MixedModule):
+ appleveldefs = {
+ }
+
+ interpleveldefs = {
+ 'enable': 'interp_jit.enable',
+ }
+
+ def setup_after_space_initialization(self):
+ # force the setup() to run early
+ import pypy.module.pypyjit.interp_jit
Added: pypy/branch/jit-real-world/pypy/module/pypyjit/interp_jit.py
==============================================================================
--- (empty file)
+++ pypy/branch/jit-real-world/pypy/module/pypyjit/interp_jit.py Wed Dec 6 03:08:02 2006
@@ -0,0 +1,79 @@
+"""This is not the JIT :-)
+
+The pypyjit module helpers set the 'jit_enable' flag on code objects.
+The code below makes two identical copies of the interpreter's main
+loop, and the flag controls which of them is used. One of them
+(dispatch_jit) is transformed to become a JIT by code elsewhere:
+pypy/jit/*
+"""
+import py
+from pypy.interpreter.pycode import PyCode
+from pypy.interpreter.pyframe import PyFrame
+from pypy.tool.sourcetools import func_with_new_name
+
+
+PyCode.jit_enable = False # new default attribute
+super_dispatch = PyFrame.dispatch
+super_dispatch_bytecode = PyFrame.dispatch_bytecode
+
+
+def setup():
+ # create dispatch_jit() as a copy of dispatch() in which
+ # dispatch_bytecode() has been manually inlined.
+ # Do this with py.code.Source manipulations for now.
+ src = py.code.Source(super_dispatch)
+ CALL_SITE = 'return self.dispatch_bytecode(co_code, next_instr, ec)'
+ for i, line in enumerate(src):
+ if line.strip() == CALL_SITE:
+ break
+ else:
+ raise Exception("fix me! call to dispatch_bytecode() not found")
+
+ indent = line[:line.index(CALL_SITE)]
+
+ src2 = py.code.Source(PyFrame.dispatch_bytecode)
+ hdr = src2[0].strip()
+ assert hdr == 'def dispatch_bytecode(self, co_code, next_instr, ec):'
+ src2 = src2[1:].deindent().indent(indent)
+
+ src3 = py.code.Source('%s\n%s\n%s\n' % (src[:i], src2, src[i+1:]))
+ #print src3
+ d = {}
+ exec src3.compile() in super_dispatch.func_globals, d
+ PyFrame.dispatch_jit = func_with_new_name(d['dispatch'], 'dispatch_jit')
+
+ class __extend__(PyFrame):
+
+ def dispatch(self, co_code, next_instr, ec):
+ if self.pycode.jit_enable:
+ return self.dispatch_jit(co_code, next_instr, ec)
+ else:
+ return super_dispatch(self, co_code, next_instr, ec)
+
+ return PyFrame.dispatch_jit
+
+def setup2():
+ # TEMPORARY: only patches dispatch_bytecode.
+ PyFrame.dispatch_jit = func_with_new_name(
+ PyFrame.dispatch_bytecode.im_func, 'dispatch_jit')
+
+ class __extend__(PyFrame):
+
+ def dispatch_bytecode(self, co_code, next_instr, ec):
+ if self.pycode.jit_enable:
+ print "jitting:", self.pycode.co_name
+ return self.dispatch_jit(co_code, next_instr, ec)
+ else:
+ return super_dispatch_bytecode(self, co_code, next_instr, ec)
+
+ return PyFrame.dispatch_bytecode
+
+PORTAL = setup2()
+
+# ____________________________________________________________
+#
+# Public interface
+
+def enable(space, w_code, w_enabled=True):
+ code = space.interp_w(PyCode, w_code)
+ code.jit_enable = space.is_true(w_enabled)
More information about the Pypy-commit
mailing list