[pypy-svn] r53257 - in pypy/branch/jit-hotpath/pypy/jit: codegen/llgraph rainbow rainbow/test timeshifter
antocuni at codespeak.net
antocuni at codespeak.net
Wed Apr 2 19:03:37 CEST 2008
Author: antocuni
Date: Wed Apr 2 19:03:36 2008
New Revision: 53257
Modified:
pypy/branch/jit-hotpath/pypy/jit/codegen/llgraph/llimpl.py
pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py
pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py
pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py
Log:
move the various test_degenerated_* to TestLLType, and write the
equivalents for ootype.
To make test_degenerated_at_return passing we need to erase the type
of all instances to the most general superclass (ROOT excluded); I'm
not sure this is 100% correct, but tests seem to pass.
Modified: pypy/branch/jit-hotpath/pypy/jit/codegen/llgraph/llimpl.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/codegen/llgraph/llimpl.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/codegen/llgraph/llimpl.py Wed Apr 2 19:03:36 2008
@@ -140,6 +140,12 @@
if TYPE is llmemory.GCREF or v.concretetype is llmemory.GCREF:
lltype.cast_opaque_ptr(TYPE, v.concretetype._defl()) # sanity check
opname = 'cast_opaque_ptr'
+ elif isinstance(TYPE, ootype.Instance):
+ FROMTYPE = v.concretetype
+ if ootype.isSubclass(FROMTYPE, TYPE):
+ opname = 'ooupcast'
+ else:
+ opname = 'oodowncast'
else:
assert v.concretetype == lltype.erasedType(TYPE)
opname = 'cast_pointer'
@@ -159,6 +165,14 @@
op = flowmodel.SpaceOperation("cast_pointer", [v], v2)
block.operations.append(op)
return v2
+ elif isinstance(T, ootype.Instance):
+ while T._superclass is not ootype.ROOT:
+ T = T._superclass
+ v2 = flowmodel.Variable()
+ v2.concretetype = T
+ op = flowmodel.SpaceOperation("ooupcast", [v], v2)
+ block.operations.append(op)
+ return v2
return v
def genop(block, opname, vars_gv, gv_RESULT_TYPE):
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 Wed Apr 2 19:03:36 2008
@@ -1591,6 +1591,12 @@
def serialize_op_oosetfield(self, op):
return self.serialize_op_setfield_impl(op)
+ def serialize_op_ooupcast(self, op):
+ return self.serialize_op_cast_pointer(op)
+
+ def serialize_op_oodowncast(self, op):
+ return self.serialize_op_cast_pointer(op)
+
def serialize_op_new(self, op):
TYPE = op.args[0].value
if TYPE.oopspec_name is not None:
Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py Wed Apr 2 19:03:36 2008
@@ -806,83 +806,6 @@
assert res == 7
self.check_insns({})
- def test_degenerated_before_return(self):
- 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
- s.n += 1
- return s.n * t.s.n
- res = self.interpret(ll_function, [0], [])
- assert res == 5 * 3
- res = self.interpret(ll_function, [1], [])
- assert res == 4 * 4
-
- def test_degenerated_before_return_2(self):
- 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:
- pass
- else:
- s = t.s
- s.n += 1
- return s.n * t.s.n
- res = self.interpret(ll_function, [1], [])
- assert res == 5 * 3
- res = self.interpret(ll_function, [0], [])
- assert res == 4 * 4
-
- def test_degenerated_at_return(self):
- 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.n = 3.25
- t.s.n = 3
- s = lltype.malloc(S)
- s.n = 4
- if flag:
- s = t.s
- return s
-
- res = self.interpret(ll_function, [0], [])
- assert res.n == 4
- res = self.interpret(ll_function, [1], [])
- assert res.n == 3
-
- def test_degenerated_via_substructure(self):
- 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 = 7
- if flag:
- pass
- else:
- s = t.s
- t.s.n += 1
- return s.n * t.s.n
- res = self.interpret(ll_function, [1], [])
- assert res == 7 * 4
- res = self.interpret(ll_function, [0], [])
- assert res == 4 * 4
-
def test_degenerate_with_voids(self):
S = self.GcStruct('S', ('y', lltype.Void),
('x', lltype.Signed))
@@ -2064,6 +1987,84 @@
class TestLLType(SimpleTests):
type_system = "lltype"
+ def test_degenerated_before_return(self):
+ 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
+ s.n += 1
+ return s.n * t.s.n
+ res = self.interpret(ll_function, [0], [])
+ assert res == 5 * 3
+ res = self.interpret(ll_function, [1], [])
+ assert res == 4 * 4
+
+ def test_degenerated_before_return_2(self):
+ 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:
+ pass
+ else:
+ s = t.s
+ s.n += 1
+ return s.n * t.s.n
+ res = self.interpret(ll_function, [1], [])
+ assert res == 5 * 3
+ res = self.interpret(ll_function, [0], [])
+ assert res == 4 * 4
+
+ def test_degenerated_at_return(self):
+ 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.n = 3.25
+ t.s.n = 3
+ s = lltype.malloc(S)
+ s.n = 4
+ if flag:
+ s = t.s
+ return s
+
+ res = self.interpret(ll_function, [0], [])
+ assert res.n == 4
+ res = self.interpret(ll_function, [1], [])
+ assert res.n == 3
+
+ def test_degenerated_via_substructure(self):
+ 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 = 7
+ if flag:
+ pass
+ else:
+ s = t.s
+ t.s.n += 1
+ return s.n * t.s.n
+ res = self.interpret(ll_function, [1], [])
+ assert res == 7 * 4
+ res = self.interpret(ll_function, [0], [])
+ assert res == 4 * 4
+
+
class TestOOType(SimpleTests):
type_system = "ootype"
@@ -2100,13 +2101,68 @@
del insns[a]
return insns
+ def test_degenerated_before_return(self):
+ S = ootype.Instance('S', ootype.ROOT, {'x': ootype.Signed})
+ T = ootype.Instance('T', S, {'y': ootype.Float})
+
+ def ll_function(flag):
+ t = ootype.new(T)
+ t.x = 3
+ s = ootype.new(S)
+ s.x = 4
+ if flag:
+ s = ootype.ooupcast(S, t)
+ s.x += 1
+ return s.x * t.x
+ res = self.interpret(ll_function, [0], [])
+ assert res == 5 * 3
+ res = self.interpret(ll_function, [1], [])
+ assert res == 4 * 4
+
+ def test_degenerated_before_return_2(self):
+ S = ootype.Instance('S', ootype.ROOT, {'x': lltype.Signed})
+ T = ootype.Instance('T', S, {'y': lltype.Float})
+
+ def ll_function(flag):
+ t = ootype.new(T)
+ t.x = 3
+ s = ootype.new(S)
+ s.x = 4
+ if flag:
+ pass
+ else:
+ s = ootype.ooupcast(S, t)
+ s.x += 1
+ return s.x * t.x
+ res = self.interpret(ll_function, [1], [])
+ assert res == 5 * 3
+ res = self.interpret(ll_function, [0], [])
+ assert res == 4 * 4
+
+ def test_degenerated_at_return(self):
+ S = ootype.Instance('S', ootype.ROOT, {'x': lltype.Signed})
+ T = ootype.Instance('T', S, {'y': lltype.Float})
+
+ def ll_function(flag):
+ t = ootype.new(T)
+ t.y = 3.25
+ t.x = 3
+ s = ootype.new(S)
+ s.x = 4
+ if flag:
+ s = ootype.ooupcast(S, t)
+ return s
+
+ res = self.interpret(ll_function, [0], [])
+ assert res.x == 4
+ res = self.interpret(ll_function, [1], [])
+ assert res.x == 3
+
+
def _skip(self):
py.test.skip('in progress')
- test_degenerated_before_return = _skip
- test_degenerated_before_return_2 = _skip
- test_degenerated_at_return = _skip
- test_degenerated_via_substructure = _skip
+ #test_degenerated_via_substructure = _skip
test_plus_minus = _skip
test_red_array = _skip
test_red_struct_array = _skip
Modified: pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py Wed Apr 2 19:03:36 2008
@@ -274,6 +274,15 @@
except AttributeError:
return TYPE._short_name()
+ def _compute_fielddescs(self, RGenOp):
+ AbstractStructTypeDesc._compute_fielddescs(self, RGenOp)
+ TYPE = self.TYPE
+ if isinstance(TYPE, ootype.Instance):
+ SUPERTYPE = TYPE._superclass
+ if SUPERTYPE is not None:
+ desc = InstanceTypeDesc(RGenOp, SUPERTYPE)
+ self.fielddescs = desc.fielddescs + self.fielddescs
+ self.fielddesc_by_name.update(desc.fielddesc_by_name)
def create_varsize(jitstate, contdesc, sizebox):
gv_size = sizebox.getgenvar(jitstate)
More information about the pypy-svn
mailing list