[pypy-svn] r62147 - in pypy/branch/pyjitpl5/pypy: jit/metainterp jit/tl module/pypyjit
arigo at codespeak.net
arigo at codespeak.net
Wed Feb 25 16:19:58 CET 2009
Author: arigo
Date: Wed Feb 25 16:19:57 2009
New Revision: 62147
Added:
pypy/branch/pyjitpl5/pypy/jit/tl/pypyjit.py
pypy/branch/pyjitpl5/pypy/jit/tl/pypyjit_child.py
pypy/branch/pyjitpl5/pypy/jit/tl/pypyjit_demo.py
Modified:
pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py
pypy/branch/pyjitpl5/pypy/module/pypyjit/interp_jit.py
Log:
Build a minimal jit/tl/pypyjit.py starting a PyPy translation
with the jit enabled. Temporary.
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py Wed Feb 25 16:19:57 2009
@@ -23,6 +23,9 @@
interp, graph = get_interpreter(function, args, backendopt=backendopt,
inline_threshold=0)
clear_tcache()
+ return jittify_and_run(interp, graph)
+
+def jittify_and_run(interp, graph):
translator = interp.typer.annotator.translator
warmrunnerdesc = WarmRunnerDesc(translator, **kwds)
warmrunnerdesc.state.set_param_threshold(3) # for tests
Added: pypy/branch/pyjitpl5/pypy/jit/tl/pypyjit.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/pypyjit.py Wed Feb 25 16:19:57 2009
@@ -0,0 +1,72 @@
+"""
+A temporary file that invokes translation of PyPy with the JIT enabled.
+"""
+
+import py, os
+
+from pypy.objspace.std import Space
+from pypy.config.translationoption import set_opt_level
+from pypy.config.pypyoption import get_pypy_config, set_pypy_opt_level
+
+config = get_pypy_config(translating=True)
+set_opt_level(config, level='1')
+config.objspace.compiler = 'ast'
+config.objspace.nofaking = True
+config.objspace.allworkingmodules = False
+config.objspace.usemodules.pypyjit = True
+set_pypy_opt_level(config, level='0')
+print config
+
+space = Space(config)
+w_dict = space.newdict()
+
+
+def readfile(filename):
+ fd = os.open(filename, os.O_RDONLY, 0)
+ blocks = []
+ while True:
+ data = os.read(fd, 4096)
+ if not data:
+ break
+ blocks.append(data)
+ os.close(fd)
+ return ''.join(blocks)
+
+def entry_point():
+ source = readfile('pypyjit_demo.py')
+ ec = space.getexecutioncontext()
+ code = ec.compiler.compile(source, '?', 'exec', 0)
+ code.exec_code(space, w_dict, w_dict)
+
+
+def test_run_translation():
+ from pypy.translator.goal.ann_override import PyPyAnnotatorPolicy
+ from pypy.rpython.test.test_llinterp import get_interpreter
+
+ # first annotate, rtype, and backendoptimize PyPy
+ interp, graph = get_interpreter(entry_point, [], backendopt=True,
+ config=config,
+ policy=PyPyAnnotatorPolicy(space))
+
+ # parent process loop: spawn a child, wait for the child to finish,
+ # print a message, and restart
+ while True:
+ child_pid = os.fork()
+ if child_pid == 0:
+ break
+ os.waitpid(child_pid, 0)
+ print '-' * 79
+ print 'Child process finished, press Enter to restart...'
+ raw_input()
+
+ from pypy.jit.tl.pypyjit_child import run_child
+ run_child(globals(), locals())
+
+
+if __name__ == '__main__':
+ import sys
+ if len(sys.argv) > 1:
+ # debugging: run the code directly
+ entry_point()
+ else:
+ test_run_translation()
Added: pypy/branch/pyjitpl5/pypy/jit/tl/pypyjit_child.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/pypyjit_child.py Wed Feb 25 16:19:57 2009
@@ -0,0 +1,4 @@
+
+
+def run_child(glob, loc):
+ xxx
Added: pypy/branch/pyjitpl5/pypy/jit/tl/pypyjit_demo.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/pypyjit_demo.py Wed Feb 25 16:19:57 2009
@@ -0,0 +1,2 @@
+
+print 6 * 7
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 Wed Feb 25 16:19:57 2009
@@ -19,7 +19,7 @@
from pypy.interpreter.pyopcode import Return, Yield
-Frame._virtualizable_ = True
+#Frame._virtualizable2_ = True
PyCode.jit_enable = False # new default attribute
super_dispatch = PyFrame.dispatch
@@ -29,14 +29,14 @@
if pycode.jit_enable:
return self.dispatch_jit(pycode, next_instr, ec)
else:
- self = hint(self, access_directly=True)
+ #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)
+ #hint(None, global_merge_point=True)
+ #pycode = hint(pycode, deepfreeze=True)
- entry_fastlocals_w = self.jit_enter_frame(pycode, next_instr)
+ #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)
@@ -58,89 +58,89 @@
finally:
self.jit_leave_frame(pycode, entry_fastlocals_w)
- def jit_enter_frame(self, pycode, next_instr):
- # *loads* of nonsense for now
+## def jit_enter_frame(self, pycode, next_instr):
+## # *loads* of nonsense for now
- fastlocals_w = [None] * pycode.co_nlocals
+## 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
+## 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
+
+## 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
+
+## self.pycode = pycode
+## self.valuestackdepth = depth
+
+## entry_fastlocals_w = self.fastlocals_w
+## self.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
+
+## 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]
- 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
-
- 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
-
- self.pycode = pycode
- self.valuestackdepth = depth
-
- entry_fastlocals_w = self.fastlocals_w
- self.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
-
- 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
+## self.fastlocals_w = entry_fastlocals_w
PORTAL = PyFrame.dispatch_jit
-class __extend__(Function):
- __metaclass__ = extendabletype
+##class __extend__(Function):
+## __metaclass__ = extendabletype
- def getcode(self):
- # if the self is a compile time constant and if its code
- # is a BuiltinCode => grab and return its code as a constant
- if _is_early_constant(self):
- from pypy.interpreter.gateway import BuiltinCode
- code = hint(self, deepfreeze=True).code
- if not isinstance(code, BuiltinCode): code = self.code
- else:
- code = self.code
- return code
+## def getcode(self):
+## # if the self is a compile time constant and if its code
+## # is a BuiltinCode => grab and return its code as a constant
+## if _is_early_constant(self):
+## from pypy.interpreter.gateway import BuiltinCode
+## code = hint(self, deepfreeze=True).code
+## if not isinstance(code, BuiltinCode): code = self.code
+## else:
+## code = self.code
+## return code
# ____________________________________________________________
@@ -152,7 +152,7 @@
# code backend can fish for it - XXX the following import will look
# less obscure once codebuf.py is moved to a general
# processor-independent place
- from pypy.jit.codegen.hlinfo import highleveljitinfo
+ from pypy.jit.backend.hlinfo import highleveljitinfo
if highleveljitinfo.sys_executable is None:
highleveljitinfo.sys_executable = space.str_w(
space.sys.get('executable'))
More information about the Pypy-commit
mailing list