[pypy-svn] r24646 - in pypy/dist/pypy/jit: . test
arigo at codespeak.net
arigo at codespeak.net
Mon Mar 20 22:09:23 CET 2006
Author: arigo
Date: Mon Mar 20 22:09:22 2006
New Revision: 24646
Modified:
pypy/dist/pypy/jit/hintrtyper.py
pypy/dist/pypy/jit/test/test_hint_timeshift.py
Log:
Intermediate check-in with skipped tests: detect degenerated
virtual containers.
Modified: pypy/dist/pypy/jit/hintrtyper.py
==============================================================================
--- pypy/dist/pypy/jit/hintrtyper.py (original)
+++ pypy/dist/pypy/jit/hintrtyper.py Mon Mar 20 22:09:22 2006
@@ -103,6 +103,7 @@
if isinstance(hop.args_r[0], BlueRepr):
return hop.args_r[0].timeshift_getfield(hop)
# non virtual case
+ # XXX green getfields on an immutable structure could be more efficient
ts = self.timeshifter
PTRTYPE = originalconcretetype(hop.args_s[0])
RESTYPE = originalconcretetype(hop.s_result)
@@ -123,6 +124,7 @@
ts.s_RedBox)
def translate_op_getarrayitem(self, hop):
+ # XXX green getarrayitems on an immutable array could be more efficient
ts = self.timeshifter
PTRTYPE = originalconcretetype(hop.args_s[0])
RESTYPE = originalconcretetype(hop.s_result)
@@ -147,10 +149,7 @@
raise NotImplementedError
def translate_op_getsubstruct(self, hop):
- if isinstance(hop.args_r[0], BlueRepr):
- return hop.args_r[0].timeshift_getsubstruct(hop)
- # non virtual case ...
- raise NotImplementedError
+ return hop.args_r[0].timeshift_getsubstruct(hop)
def translate_op_malloc(self, hop):
r_result = hop.r_result
@@ -211,13 +210,20 @@
class __extend__(pairtype(HintTypeSystem, hintmodel.SomeLLAbstractContainer)):
def rtyper_makerepr((ts, hs_container), hrtyper):
- assert isinstance(hs_container.contentdef, hintcontainer.VirtualStructDef)
- return BlueStructRepr(hs_container.concretetype, hs_container.contentdef,
+ vstructdef = hs_container.contentdef
+ assert isinstance(vstructdef, hintcontainer.VirtualStructDef)
+ if vstructdef.degenerated:
+ # fall back to a red repr
+ return hrtyper.getredrepr(hs_container.concretetype)
+ return BlueStructRepr(hs_container.concretetype, vstructdef,
hrtyper.timeshifter)
def rtyper_makekey((ts, hs_container), hrtyper):
- assert isinstance(hs_container.contentdef, hintcontainer.VirtualStructDef)
vstructdef = hs_container.contentdef
+ assert isinstance(vstructdef, hintcontainer.VirtualStructDef)
+ if vstructdef.degenerated:
+ # fall back to a red repr
+ return hs_container.__class__, "red", hs_container.concretetype
# compute reconstruction information up to our top-most parent
chain = [vstructdef.T]
@@ -270,6 +276,10 @@
def residual_values(self, ll_value):
return [ll_value]
+ def create(self, hop):
+ XXX #...
+
+
class BlueRepr(Repr):
pass
@@ -430,6 +440,9 @@
def residual_values(self, ll_value):
return []
+ #def timeshift_getsubstruct(self, hop):
+ # ...
+
green_signed_repr = GreenRepr(lltype.Signed)
green_void_repr = GreenRepr(lltype.Void)
Modified: pypy/dist/pypy/jit/test/test_hint_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/test/test_hint_timeshift.py (original)
+++ pypy/dist/pypy/jit/test/test_hint_timeshift.py Mon Mar 20 22:09:22 2006
@@ -8,14 +8,15 @@
from pypy.jit.test.test_llabstractinterp import annotation, summary
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rpython.objectmodel import hint
-from pypy.rpython import rgenop
+from pypy.rpython import rgenop, rstr
from pypy.annotation import model as annmodel
from pypy.rpython.llinterp import LLInterpreter
from pypy.objspace.flow.model import checkgraph
+from pypy.translator.backendopt.inline import auto_inlining
from pypy import conftest
-def hannotate(func, values, policy=None):
+def hannotate(func, values, policy=None, inline=None):
# build the normal ll graphs for ll_function
t = TranslationContext()
a = t.buildannotator()
@@ -23,6 +24,8 @@
a.build_types(func, argtypes)
rtyper = t.buildrtyper()
rtyper.specialize()
+ if inline:
+ auto_inlining(t, inline)
graph1 = graphof(t, func)
# build hint annotator types
hannotator = HintAnnotator(policy=policy)
@@ -34,8 +37,8 @@
hannotator.translator.view()
return hs, hannotator, rtyper
-def timeshift(ll_function, values, opt_consts=[]):
- hs, ha, rtyper = hannotate(ll_function, values)
+def timeshift(ll_function, values, opt_consts=[], inline=None):
+ hs, ha, rtyper = hannotate(ll_function, values, inline=inline)
htshift = HintTimeshift(ha, rtyper)
htshift.timeshift()
t = rtyper.annotator.translator
@@ -316,3 +319,40 @@
insns, res = timeshift(ll_function, [7], [0])
assert res == 7
assert insns == {}
+
+def test_merge_substructure():
+ py.test.skip("in-progress")
+ S = lltype.GcStruct('S', ('n', lltype.Signed))
+ T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
+
+ def ll_function(flag):
+ t = lltype.malloc(T)
+ t.s.n = 3
+ s = lltype.malloc(S)
+ s.n = 4
+ if flag:
+ s = t.s
+ return s
+ insns, res = timeshift(ll_function, [0], [])
+ assert res.n == 4
+ assert insns == {'malloc': 1, 'setfield': 1, 'getfield': 1}
+
+def test_plus_minus_all_inlined():
+ py.test.skip("in-progress")
+ def ll_plus_minus(s, x, y):
+ acc = x
+ n = len(s)
+ pc = 0
+ while pc < n:
+ op = s[pc]
+ op = hint(op, concrete=True)
+ if op == '+':
+ acc += y
+ elif op == '-':
+ acc -= y
+ pc += 1
+ return acc
+ s = rstr.string_repr.convert_const("+-+")
+ insns, res = timeshift(ll_plus_minus, [s, 0, 2], [0], inline=999)
+ assert res == ll_plus_minus(s, 0, 2)
+ assert insns == {'int_add': 2, 'int_sub': 1}
More information about the Pypy-commit
mailing list