[pypy-svn] r53221 - in pypy/branch/jit-hotpath/pypy/jit/rainbow: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Apr 1 00:28:30 CEST 2008
Author: cfbolz
Date: Tue Apr 1 00:28:29 2008
New Revision: 53221
Modified:
pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py
pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_hotpath.py
Log:
fix a bug in the fallback interp
Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py Tue Apr 1 00:28:29 2008
@@ -36,6 +36,25 @@
jitstate.residual_ll_exception(ll_exc)
+def make_colororder(graph, hannotator):
+ # if the graph takes both red and green arguments, we need
+ # a way for the fallback interp to rezip the two lists
+ # 'greenargs' and 'redargs' into a single one
+ colororder = ""
+ in_order = True # "in order" means allgreens+allreds
+ for v in graph.getargs():
+ if v.concretetype is lltype.Void:
+ continue
+ if hannotator.binding(v).is_green():
+ if "r" in colororder:
+ in_order = False
+ colororder += "g"
+ else:
+ colororder += "r"
+ if in_order:
+ colororder = None
+ return colororder
+
class CallDesc:
__metaclass__ = cachedtype
@@ -131,6 +150,9 @@
fnptr = codewriter.rtyper.getcallable(graph)
keys.append(llmemory.cast_ptr_to_adr(fnptr))
values.append(codewriter.get_jitcode(tsgraph))
+ # arbitrarily use the last graph to make the colororder -
+ # normalization should ensure that all colors are the same
+ colororder = make_colororder(tsgraph, codewriter.hannotator)
def bytecode_for_address(fnaddress):
# XXX optimize
@@ -143,7 +165,7 @@
self.graphs = [graph for (graph, tsgraph) in graph2tsgraph]
self.jitcodes = values
self.calldesc = CallDesc(codewriter.RGenOp, codewriter.exceptiondesc,
- lltype.typeOf(fnptr))
+ lltype.typeOf(fnptr), colororder)
class BytecodeWriter(object):
@@ -301,22 +323,7 @@
RESULT = graph.getreturnvar().concretetype
FUNCTYPE = lltype.FuncType(ARGS, RESULT)
- # if the graph takes both red and green arguments, we need
- # a way for the fallback interp to rezip the two lists
- # 'greenargs' and 'redargs' into a single one
- colororder = ""
- in_order = True # "in order" means allgreens+allreds
- for v in graph.getargs():
- if v.concretetype is lltype.Void:
- continue
- if self.hannotator.binding(v).is_green():
- if "r" in colororder:
- in_order = False
- colororder += "g"
- else:
- colororder += "r"
- if in_order:
- colororder = None
+ colororder = make_colororder(graph, self.hannotator)
owncalldesc = CallDesc(self.RGenOp, self.exceptiondesc,
lltype.Ptr(FUNCTYPE), colororder)
# detect the special ts_stub or ts_metacall graphs and replace
Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_hotpath.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_hotpath.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_hotpath.py Tue Apr 1 00:28:29 2008
@@ -3,7 +3,8 @@
from pypy.rlib.jit import JitDriver, hint, JitHintError
from pypy.jit.rainbow.test import test_interpreter
from pypy.jit.rainbow.hotpath import HotRunnerDesc
-from pypy.jit.hintannotator.policy import HintAnnotatorPolicy
+from pypy.jit.hintannotator.policy import HintAnnotatorPolicy, \
+ StopAtXPolicy
from pypy.rpython.llinterp import LLInterpreter
from pypy import conftest
@@ -587,3 +588,33 @@
res = self.run(ll_function, [40], threshold=2)
assert "".join(res.chars) == " ".join([str(i) for i in range(1, 80)])
self.check_insns(malloc=1)
+
+ def test_indirect_call_fallback_color_order(self):
+ class A(object):
+ def g(self, green, red):
+ return red + green
+
+ class B(A):
+ def g(self, green, red):
+ return red - green
+
+ myjitdriver = JitDriver(greens = ['x'],
+ reds = ['a', 'i', 'tot'])
+ def g(isnotnone):
+ if isnotnone:
+ return A()
+ return B()
+ def f(isnotnone, x):
+ a = g(isnotnone)
+ i = 1024 * 1024
+ tot = 0
+ while i > 0:
+ i >>= 1
+ tot += a.g(x, i)
+ hint(x, concrete=True)
+ myjitdriver.jit_merge_point(tot=tot, i=i, a=a, x=x)
+ myjitdriver.can_enter_jit(tot=tot, i=i, a=a, x=x)
+ return tot
+ res = self.run(f, [False, 5], threshold=4, policy=StopAtXPolicy(g))
+ assert res == f(False, 5)
+
More information about the Pypy-commit
mailing list