[pypy-svn] r41045 - in pypy/dist/pypy/jit: hintannotator hintannotator/test timeshifter timeshifter/test
arigo at codespeak.net
arigo at codespeak.net
Thu Mar 22 14:26:41 CET 2007
Author: arigo
Date: Thu Mar 22 14:26:40 2007
New Revision: 41045
Modified:
pypy/dist/pypy/jit/hintannotator/annotator.py
pypy/dist/pypy/jit/hintannotator/bookkeeper.py
pypy/dist/pypy/jit/hintannotator/model.py
pypy/dist/pypy/jit/hintannotator/test/test_annotator.py
pypy/dist/pypy/jit/timeshifter/hrtyper.py
pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
Log:
(arigo, arre, pedronis)
Support for pure ts_metacalls, with fixing across them.
If they are green, the original graph just gets called
at compile-time.
Modified: pypy/dist/pypy/jit/hintannotator/annotator.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/annotator.py (original)
+++ pypy/dist/pypy/jit/hintannotator/annotator.py Thu Mar 22 14:26:40 2007
@@ -96,9 +96,11 @@
def consider_op_resume_point(self, hs_v, *args_hs):
pass
- def consider_op_ts_metacall(self, hs_metafunc, *args_hs):
- RESTYPE = self.bookkeeper.current_op_concretetype()
- return hintmodel.variableoftype(RESTYPE)
+ def consider_op_ts_metacall(self, hs_f1, hs_metadesccls, *args_hs):
+ bookkeeper = self.bookkeeper
+ fnobj = hs_f1.const._obj
+ return hintmodel.cannot_follow_call(bookkeeper, fnobj.graph, args_hs,
+ lltype.typeOf(fnobj).RESULT)
def simplify(self):
RPythonAnnotator.simplify(self, extra_passes=[])
Modified: pypy/dist/pypy/jit/hintannotator/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/bookkeeper.py (original)
+++ pypy/dist/pypy/jit/hintannotator/bookkeeper.py Thu Mar 22 14:26:40 2007
@@ -49,12 +49,9 @@
except KeyError:
bk = self.bookkeeper
look = bk.annotator.policy.look_inside_graph(self.origgraph)
- if look:
- if callable(look):
- graph = self.build_metacall_graph(self.origgraph, look)
- else:
- # normal case
- graph = copygraph(self.origgraph, varmap=TIMESHIFTMAP)
+ if look and not callable(look):
+ # normal case
+ graph = copygraph(self.origgraph, varmap=TIMESHIFTMAP)
if not self._cache:
bk.nonstuboriggraphcount += 1
if verbose:
@@ -62,7 +59,7 @@
else:
log.dot()
else:
- graph = self.build_callback_graph(self.origgraph)
+ graph = self.build_callback_graph(self.origgraph, look)
if not self._cache:
bk.stuboriggraphcount += 1
if verbose:
@@ -83,29 +80,24 @@
self.bookkeeper.annotator.translator.graphs.append(graph)
return graph
- def build_callback_graph(self, graph):
+ def build_callback_graph(self, graph, metadesccls=False):
args_v = [copyvar(None, v) for v in graph.getargs()]
v_res = copyvar(None, graph.getreturnvar())
rtyper = self.bookkeeper.annotator.base_translator.rtyper # fish
fnptr = rtyper.getcallable(graph)
v_ptr = Constant(fnptr, lltype.typeOf(fnptr))
newstartblock = Block(args_v)
+ if metadesccls:
+ v_metadesccls = Constant(metadesccls, lltype.Void)
+ args_v = [v_metadesccls] + args_v
+ opname = 'ts_metacall'
+ suffix = 'ts_metacall'
+ else:
+ opname = 'direct_call'
+ suffix = 'ts_stub'
newstartblock.operations.append(
- SpaceOperation('direct_call', [v_ptr] + args_v, v_res))
- newgraph = FunctionGraph('%s_ts_stub' % (graph.name,), newstartblock)
- newgraph.getreturnvar().concretetype = v_res.concretetype
- newstartblock.closeblock(Link([v_res], newgraph.returnblock))
- return newgraph
-
- def build_metacall_graph(self, origgraph, metadesccls):
- args_v = [copyvar(None, v) for v in origgraph.getargs()]
- v_res = copyvar(None, origgraph.getreturnvar())
- v_metadesccls = Constant(metadesccls, lltype.Void)
- newstartblock = Block(args_v)
- newstartblock.operations.append(
- SpaceOperation('ts_metacall', [v_metadesccls] + args_v, v_res))
- newgraph = FunctionGraph('%s_ts_metacall' % (origgraph.name,),
- newstartblock)
+ SpaceOperation(opname, [v_ptr] + args_v, v_res))
+ newgraph = FunctionGraph('%s_%s' % (graph.name, suffix), newstartblock)
newgraph.getreturnvar().concretetype = v_res.concretetype
newstartblock.closeblock(Link([v_res], newgraph.returnblock))
return newgraph
Modified: pypy/dist/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/model.py (original)
+++ pypy/dist/pypy/jit/hintannotator/model.py Thu Mar 22 14:26:40 2007
@@ -83,7 +83,7 @@
def record_dependencies(self, greenorigindependencies,
callreturndependencies):
bk = self.bookkeeper
- if self.spaceop.opname == 'direct_call':
+ if self.spaceop.opname in ('direct_call', 'ts_metacall'):
args = self.spaceop.args[1:]
elif self.spaceop.opname == 'indirect_call':
args = self.spaceop.args[1:-1]
Modified: pypy/dist/pypy/jit/hintannotator/test/test_annotator.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/test/test_annotator.py (original)
+++ pypy/dist/pypy/jit/hintannotator/test/test_annotator.py Thu Mar 22 14:26:40 2007
@@ -881,3 +881,31 @@
return 5
hs = hannotate(g, [int], backendoptimize=True)
assert hs.is_green()
+
+
+def test_substitute_graph():
+ class MetaG:
+ pass # the details are only used by the timeshifter
+
+ def g(m):
+ return m * 17
+
+ def f(n, m):
+ x = g(n)
+ y = g(m)
+ hint(y, concrete=True)
+ return g(m)
+
+ class MyPolicy(HintAnnotatorPolicy):
+ entrypoint_returns_red = False
+ def look_inside_graph(self, graph):
+ if graph.func is g:
+ return MetaG # replaces g with a meta-call to metafunc()
+ else:
+ return True
+
+ hs, hannotator = hannotate(f, [int, int], policy=MyPolicy(),
+ annotator=True)
+ assert hs.is_green()
+ for graph in hannotator.translator.graphs:
+ assert 'int_mul' not in flowmodel.summary(graph)
Modified: pypy/dist/pypy/jit/timeshifter/hrtyper.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/hrtyper.py (original)
+++ pypy/dist/pypy/jit/timeshifter/hrtyper.py Thu Mar 22 14:26:40 2007
@@ -681,22 +681,25 @@
return v
def translate_op_ts_metacall(self, hop):
- nb_args = hop.nb_args - 1
+ # note that if the ts_metacall operation is pure and green, then
+ # we don't even get there because the original graph in which
+ # it is will just be green_call'ed by the caller.
+ nb_args = hop.nb_args - 2
def normalize(hs):
T = originalconcretetype(hs)
if T is lltype.Void:
return lltype.Void
else:
return self.getredrepr(T)
- args_r = [normalize(hs) for hs in hop.args_s[1:]]
- vlist = hop.inputargs(lltype.Void, *args_r)
- metadesccls = vlist[0].value
+ args_r = [normalize(hs) for hs in hop.args_s[2:]]
+ vlist = hop.inputargs(lltype.Void, lltype.Void, *args_r)
+ metadesccls = vlist[1].value
metadesc = metadesccls(self)
metafunc = metadesc.metafunc
v_jitstate = hop.llops.getjitstate()
return hop.llops.genmixlevelhelpercall(metafunc,
[self.s_JITState] + [self.s_RedBox] * nb_args,
- [v_jitstate] + vlist[1:],
+ [v_jitstate] + vlist[2:],
self.s_RedBox)
def translate_op_getfield(self, hop):
@@ -1527,6 +1530,7 @@
args_v = [v_self] + args_v
function = function.im_func
+ assert len(args_s) == len(args_v)
graph = self.hrtyper.annhelper.getgraph(function, args_s, s_result)
self.record_extra_call(graph) # xxx
Modified: pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py (original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py Thu Mar 22 14:26:40 2007
@@ -1667,10 +1667,13 @@
return IntRedBox(mbox.kind, gv_result)
def g(m):
- return m + 17
+ return m * 10
- def f(n):
- return g(n)
+ def f(n, m):
+ x = g(n)
+ y = g(m)
+ hint(y, concrete=True)
+ return x + g(y)
class MyPolicy(HintAnnotatorPolicy):
def look_inside_graph(self, graph):
@@ -1679,6 +1682,6 @@
else:
return True
- res = self.timeshift(f, [3], policy=MyPolicy())
- assert res == -3
- self.check_insns({'int_neg': 1})
+ res = self.timeshift(f, [3, 6], policy=MyPolicy())
+ assert res == -3 + 600
+ self.check_insns({'int_neg': 1, 'int_add': 1})
More information about the Pypy-commit
mailing list