[pypy-svn] r40768 - in pypy/dist/pypy/translator: . goal test
ac at codespeak.net
ac at codespeak.net
Mon Mar 19 14:25:51 CET 2007
Author: ac
Date: Mon Mar 19 14:25:49 2007
New Revision: 40768
Added:
pypy/dist/pypy/translator/goal/targetportal.py (contents, props changed)
Modified:
pypy/dist/pypy/translator/driver.py
pypy/dist/pypy/translator/goal/translate.py
pypy/dist/pypy/translator/test/test_driver.py
Log:
(pedronis, arre)
Add JIT-generation tasks to the driver and add a --jit option to translate.py
See target_portal.py for a simple example.
Modified: pypy/dist/pypy/translator/driver.py
==============================================================================
--- pypy/dist/pypy/translator/driver.py (original)
+++ pypy/dist/pypy/translator/driver.py Mon Mar 19 14:25:49 2007
@@ -1,6 +1,6 @@
import sys, os
-from pypy.translator.translator import TranslationContext
+from pypy.translator.translator import TranslationContext, graphof
from pypy.translator.tool.taskengine import SimpleTaskEngine
from pypy.translator.goal import query
from pypy.annotation import model as annmodel
@@ -78,7 +78,8 @@
class TranslationDriver(SimpleTaskEngine):
- def __init__(self, setopts=None, default_goal=None, disable=[],
+ def __init__(self, setopts=None, default_goal=None, extra_goals=[],
+ disable=[],
exe_name=None, extmod_name=None,
config=None, overrides=None):
SimpleTaskEngine.__init__(self)
@@ -108,7 +109,7 @@
default_goal = None
self.default_goal = default_goal
-
+ self.extra_goals = extra_goals
self.exposed = []
# expose tasks
@@ -129,7 +130,9 @@
expose_task(task)
else:
task, postfix = parts
- if task in ('rtype', 'backendopt', 'llinterpret'):
+ if task in ('rtype', 'backendopt', 'llinterpret',
+ 'prehannotatebackendopt', 'hintannotate',
+ 'timeshift'):
if ts:
if ts == postfix:
expose_task(task, explicit_task)
@@ -328,12 +331,75 @@
task_rtype_ootype = taskdef(task_rtype_ootype, ['annotate'], "ootyping")
OOTYPE = 'rtype_ootype'
+ def task_prehannotatebackendopt_lltype(self):
+ from pypy.translator.backendopt.all import backend_optimizations
+ backend_optimizations(self.translator,
+ inline_threshold=0,
+ merge_if_blocks=False,
+ constfold=True,
+ remove_asserts=True)
+ #
+ task_prehannotatebackendopt_lltype = taskdef(
+ task_prehannotatebackendopt_lltype,
+ [RTYPE],
+ "Backendopt before Hint-annotate")
+
+ def task_hintannotate_lltype(self):
+ from pypy.jit.hintannotator.annotator import HintAnnotator
+ from pypy.jit.hintannotator.model import OriginFlags
+ from pypy.jit.hintannotator.model import SomeLLAbstractConstant
+
+ get_portal = self.extra['portal']
+ PORTAL, POLICY = get_portal(self)
+ t = self.translator
+ self.portal_graph = graphof(t, PORTAL)
+
+ hannotator = HintAnnotator(base_translator=t, policy=POLICY)
+ hs = hannotator.build_types(self.portal_graph,
+ [SomeLLAbstractConstant(v.concretetype,
+ {OriginFlags(): True})
+ for v in self.portal_graph.getargs()])
+ count = hannotator.bookkeeper.nonstubgraphcount
+ self.log.info('Hint-annotated %d graphs (plus %d stubs).' % (
+ count, len(hannotator.translator.graphs) - count))
+ n = len(list(hannotator.translator.graphs[0].iterblocks()))
+ self.log.info("portal has %d blocks" % n)
+ self.hannotator = hannotator
+ #
+ task_hintannotate_lltype = taskdef(task_hintannotate_lltype,
+ ['prehannotatebackendopt_lltype'],
+ "Hint-annotate")
+
+ def task_timeshift_lltype(self):
+ from pypy.jit.timeshifter.hrtyper import HintRTyper
+ from pypy.jit.codegen import detect_cpu
+ cpu = detect_cpu.autodetect()
+ if cpu == 'i386':
+ from pypy.jit.codegen.i386.rgenop import RI386GenOp as RGenOp
+ RGenOp.MC_SIZE = 32 * 1024 * 1024
+ elif cpu == 'ppc':
+ from pypy.jit.codegen.ppc.rgenop import RPPCGenOp as RGenOp
+ else:
+ raise Exception('Unsuported cpu %r'%cpu)
+
+ ha = self.hannotator
+ t = self.translator
+ # make the timeshifted graphs
+ hrtyper = HintRTyper(ha, t.rtyper, RGenOp)
+ hrtyper.specialize(origportalgraph=self.portal_graph, view=False)
+ #
+ task_timeshift_lltype = taskdef(task_timeshift_lltype,
+ ["hintannotate_lltype"],
+ "Timeshift")
+
def task_backendopt_lltype(self):
from pypy.translator.backendopt.all import backend_optimizations
backend_optimizations(self.translator)
#
task_backendopt_lltype = taskdef(task_backendopt_lltype,
- [RTYPE], "lltype back-end optimisations")
+ [RTYPE,
+ '??timeshift_lltype'],
+ "lltype back-end optimisations")
BACKENDOPT = 'backendopt_lltype'
def task_backendopt_ootype(self):
@@ -630,18 +696,20 @@
return
elif isinstance(goals, str):
goals = [goals]
+ goals.extend(self.extra_goals)
goals = self.backend_select_goals(goals)
return self._execute(goals, task_skip = self._maybe_skip())
def from_targetspec(targetspec_dic, config=None, args=None,
empty_translator=None,
disable=[],
- default_goal=None):
+ default_goal=None,
+ extra_goals=[]):
if args is None:
args = []
driver = TranslationDriver(config=config, default_goal=default_goal,
- disable=disable)
+ extra_goals=extra_goals, disable=disable)
# patch some attributes of the os module to make sure they
# have the same value on every platform.
backend, ts = driver.get_backend_and_type_system()
Added: pypy/dist/pypy/translator/goal/targetportal.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/goal/targetportal.py Mon Mar 19 14:25:49 2007
@@ -0,0 +1,23 @@
+from pypy.rlib.objectmodel import hint
+
+def compute(x, y):
+ hint(x, concrete=True)
+ r = x + y
+ return r
+
+# __________ Entry point __________
+
+def entry_point(argv):
+ if len(argv) <3:
+ return -2
+ r = compute(int(argv[1]), int(argv[2]))
+ print r
+ return 0
+
+# _____ Define and setup target ___
+
+def target(*args):
+ return entry_point, None
+
+def portal(drv):
+ return compute, None
Modified: pypy/dist/pypy/translator/goal/translate.py
==============================================================================
--- pypy/dist/pypy/translator/goal/translate.py (original)
+++ pypy/dist/pypy/translator/goal/translate.py Mon Mar 19 14:25:49 2007
@@ -17,21 +17,30 @@
GOALS= [
("annotate", "do type inference", "-a --annotate", ""),
("rtype", "do rtyping", "-t --rtype", ""),
+ ("prehannotatebackendopt", "backend optimize before hint-annotating",
+ "--prehannotatebackendopt", ""),
+ ("hintannotate", "hint-annotate", "--hintannotate", ""),
+ ("timeshift", "timeshift (jit generation)", "--timeshift", ""),
("backendopt", "do backend optimizations", "--backendopt", ""),
("source", "create source", "-s --source", ""),
("compile", "compile", "-c --compile", " (default goal)"),
+ ("?jit", "generate JIT", "--jit", ""),
("run", "run the resulting binary", "--run", ""),
("llinterpret", "interpret the rtyped flow graphs", "--llinterpret", ""),
]
-
def goal_options():
result = []
for name, doc, cmdline, extra in GOALS:
+ optional = False
+ if name.startswith('?'):
+ optional = True
+ name = name[1:]
yesdoc = doc[0].upper()+doc[1:]+extra
result.append(BoolOption(name, yesdoc, default=False, cmdline=cmdline,
negation=False))
- result.append(BoolOption("no_%s" % name, "Don't "+doc, default=False,
- cmdline="--no-"+name, negation=False))
+ if not optional:
+ result.append(BoolOption("no_%s" % name, "Don't "+doc, default=False,
+ cmdline="--no-"+name, negation=False))
return result
translate_optiondescr = OptionDescription("translate", "XXX", [
@@ -116,6 +125,8 @@
# set goals and skipped_goals
reset = False
for name, _, _, _ in GOALS:
+ if name.startswith('?'):
+ continue
if getattr(translateconfig.goal_options, name):
if name not in translateconfig.goals:
translateconfig.goals.append(name)
@@ -250,12 +261,15 @@
pdb_plus_show.start(tb, server_setup, graphic=not translateconfig.text)
log_config(translateconfig, "translate.py configuration")
-
+ extra_goals = []
+ if translateconfig.goal_options.jit:
+ extra_goals.append('timeshift')
try:
drv = driver.TranslationDriver.from_targetspec(targetspec_dic, config, args,
empty_translator=t,
disable=translateconfig.skipped_goals,
- default_goal='compile')
+ default_goal='compile',
+ extra_goals=extra_goals)
log_config(config.translation, "translation configuration")
pdb_plus_show.expose({'drv': drv, 'prof': prof})
Modified: pypy/dist/pypy/translator/test/test_driver.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_driver.py (original)
+++ pypy/dist/pypy/translator/test/test_driver.py Mon Mar 19 14:25:49 2007
@@ -12,9 +12,10 @@
def test_ctr():
td = TranslationDriver()
-
- assert cmpl(td.exposed,
- ['annotate', 'backendopt', 'llinterpret', 'rtype', 'source', 'compile', 'run'])
+ expected = ['annotate', 'backendopt', 'llinterpret', 'rtype', 'source',
+ 'compile', 'run', 'prehannotatebackendopt', 'hintannotate',
+ 'timeshift']
+ assert cmpl(td.exposed, expected)
assert td.backend_select_goals(['compile_c']) == ['compile_c']
assert td.backend_select_goals(['compile']) == ['compile_c']
@@ -34,7 +35,7 @@
assert td.backend_select_goals(['backendopt_lltype']) == [
'backendopt_lltype']
- assert cmpl(td.exposed, ['annotate', 'backendopt_lltype',
+ expected = ['annotate', 'backendopt_lltype',
'backendopt_ootype',
'llinterpret_lltype',
'rtype_ootype', 'rtype_lltype', 'source_cl', 'source_js',
@@ -42,7 +43,10 @@
'compile_cl', 'compile_cli', 'compile_c', 'compile_squeak',
'compile_llvm', 'compile_js', 'run_cl', 'run_squeak',
'run_llvm', 'run_c', 'run_js', 'run_cli',
- 'compile_jvm', 'source_jvm', 'run_jvm'])
+ 'compile_jvm', 'source_jvm', 'run_jvm',
+ 'prehannotatebackendopt_lltype', 'hintannotate_lltype',
+ 'timeshift_lltype']
+ assert cmpl(td.exposed, expected)
td = TranslationDriver({'backend': None, 'type_system': 'lltype'})
@@ -55,7 +59,7 @@
'backendopt_lltype']
expected = ['annotate', 'backendopt', 'llinterpret', 'rtype', 'source_c',
- 'source_llvm', 'compile_c', 'compile_llvm', 'run_llvm',
- 'run_c']
+ 'source_llvm', 'compile_c', 'compile_llvm', 'run_llvm',
+ 'run_c', 'prehannotatebackendopt', 'hintannotate', 'timeshift']
assert cmpl(td.exposed, expected)
More information about the Pypy-commit
mailing list