[pypy-svn] r36765 - in pypy/dist/pypy/jit/timeshifter: . test
ac at codespeak.net
ac at codespeak.net
Sun Jan 14 23:24:44 CET 2007
Author: ac
Date: Sun Jan 14 23:24:44 2007
New Revision: 36765
Modified:
pypy/dist/pypy/jit/timeshifter/rcontainer.py
pypy/dist/pypy/jit/timeshifter/rtimeshift.py
pypy/dist/pypy/jit/timeshifter/rvalue.py
pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py
Log:
(pedronis, arre) Support aliasing of virtual structures inside virtualizable.
Modified: pypy/dist/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rcontainer.py (original)
+++ pypy/dist/pypy/jit/timeshifter/rcontainer.py Sun Jan 14 23:24:44 2007
@@ -423,14 +423,18 @@
def op_getsubstruct(self, jitstate, fielddesc):
return self.ownbox
- def make_vinfo(self, jitstate):
- # xxx aliasing
+ def make_vinfo(self, jitstate, memo):
+ try:
+ return memo.containers[self]
+ except KeyError:
+ pass
typedesc = self.typedesc
assert typedesc is not None
builder = jitstate.curbuilder
gv_vinfo = builder.genop_call(typedesc.make_vinfo_token,
typedesc.gv_make_vinfo_ptr,
[])
+ memo.containers[self] = gv_vinfo
vars_gv = []
for box in self.content_boxes:
if box.genvar:
@@ -444,7 +448,7 @@
assert isinstance(box, rvalue.PtrRedBox)
content = box.content
assert isinstance(content, VirtualStruct) # XXX for now
- gv_vinfo1 = content.make_vinfo(jitstate)
+ gv_vinfo1 = content.make_vinfo(jitstate, memo)
builder.genop_call(typedesc.vinfo_append_vinfo_token,
typedesc.gv_vinfo_append_vinfo_ptr,
[gv_vinfo, gv_vinfo1])
@@ -470,15 +474,21 @@
return self.RGenOp.read_frame_var(T, base,
self.info, index)
assert isinstance(T, lltype.Ptr)
+ return vinfo.get_forced(fielddesc, base)
+ read_field._annspecialcase_ = "specialize:arg(1)"
+
+ def get_forced(self, fielddesc, base):
+ T = fielddesc.RESTYPE
+ assert isinstance(T, lltype.Ptr)
if self.s:
return lltype.cast_opaque_ptr(T, self.s)
S = T.TO
s = lltype.malloc(S)
self.s = lltype.cast_opaque_ptr(llmemory.GCREF, s)
- fielddesc.fill_into(s, base, vinfo)
+ fielddesc.fill_into(s, base, self)
return s
-
- read_field._annspecialcase_ = "specialize:arg(1)"
+ get_forced._annspecialcase_ = "specialize:arg(1)"
+
class VirtualizableStruct(VirtualStruct):
@@ -515,11 +525,13 @@
boxes[i] = fielddesc.generate_get(jitstate, gv_outside)
jitstate.add_virtualizable(self.ownbox)
- def prepare_for_residual_call(self, jitstate, gv_base):
+ def prepare_for_residual_call(self, jitstate, gv_base, memo):
typedesc = self.typedesc
builder = jitstate.curbuilder
gv_outside = self.content_boxes[-1].genvar
if gv_outside is not typedesc.gv_null:
+ if self in memo.containers:
+ return
base_desc = typedesc.base_desc
assert base_desc is not None
base_token = base_desc.fieldtoken
@@ -531,6 +543,8 @@
gv_vinfo = builder.genop_call(typedesc.make_vinfo_token,
typedesc.gv_make_vinfo_ptr,
[])
+ memo.containers[self] = gv_vinfo
+
for i in range(NVABLEFIELDS, n-1):
box = boxes[i]
if box.genvar:
@@ -544,7 +558,7 @@
assert isinstance(box, rvalue.PtrRedBox)
content = box.content
assert isinstance(content, VirtualStruct) # XXX for now
- gv_vinfo1 = content.make_vinfo(jitstate)
+ gv_vinfo1 = content.make_vinfo(jitstate, memo)
builder.genop_call(typedesc.vinfo_append_vinfo_token,
typedesc.gv_vinfo_append_vinfo_ptr,
[gv_vinfo, gv_vinfo1])
Modified: pypy/dist/pypy/jit/timeshifter/rtimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rtimeshift.py (original)
+++ pypy/dist/pypy/jit/timeshifter/rtimeshift.py Sun Jan 14 23:24:44 2007
@@ -893,10 +893,11 @@
if virtualizables:
builder = self.curbuilder
gv_base = builder.get_frame_base()
+ memo = rvalue.make_vinfo_memo()
for virtualizable_box in virtualizables:
content = virtualizable_box.content
assert isinstance(content, rcontainer.VirtualizableStruct)
- content.prepare_for_residual_call(self, gv_base)
+ content.prepare_for_residual_call(self, gv_base, memo)
def after_residual_call(self):
virtualizables = self.virtualizables
Modified: pypy/dist/pypy/jit/timeshifter/rvalue.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rvalue.py (original)
+++ pypy/dist/pypy/jit/timeshifter/rvalue.py Sun Jan 14 23:24:44 2007
@@ -25,6 +25,9 @@
def unfreeze_memo():
return Memo()
+def make_vinfo_memo():
+ return Memo()
+
class DontMerge(Exception):
pass
Modified: pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py (original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py Sun Jan 14 23:24:44 2007
@@ -725,7 +725,6 @@
def test_explicit_force_unaliased_residual_red_call(self):
- py.test.skip('Fails for unknown reason.')
def get_p(pq):
pq_access = pq.vable_access
if pq_access:
@@ -793,3 +792,69 @@
res = self.timeshift_from_portal(main, f, [2, 20, 10],
policy=StopAtGPolicy())
assert res == 1
+
+ def test_explicit_force_aliased_residual_red_call(self):
+ def get_p(pq):
+ pq_access = pq.vable_access
+ if pq_access:
+ p = pq_access.get_p(pq)
+ else:
+ p = pq.p
+ return p
+ def get_q(pq):
+ pq_access = pq.vable_access
+ if pq_access:
+ q = pq_access.get_q(pq)
+ else:
+ q = pq.q
+ return q
+
+ def g(e):
+ pq = e.pq
+ p = get_p(pq)
+ q = get_q(pq)
+ e.w = int(p == q)
+
+ def f(e, a, b):
+ pq = e.pq
+ s = lltype.malloc(S)
+ s.a = a
+ s.b = b
+ pq_access = pq.vable_access
+ if pq_access:
+ pq_access.set_p(pq, s)
+ else:
+ pq.p = s
+ pq_access = pq.vable_access
+ if pq_access:
+ pq_access.set_q(pq, s)
+ else:
+ pq.q = s
+
+ g(e)
+ return pq.p.a
+
+
+ def main(a, b, x):
+ pq = lltype.malloc(PQ)
+ pq.vable_access = lltype.nullptr(PQ_ACCESS)
+ pq.p = lltype.nullptr(S)
+ pq.q = pq.p
+ e = lltype.malloc(E3)
+ e.pq = pq
+ f(e, a, b)
+ return e.w
+
+
+ class StopAtGPolicy(HintAnnotatorPolicy):
+ def __init__(self):
+ HintAnnotatorPolicy.__init__(self, novirtualcontainer=True)
+
+ def look_inside_graph(self, graph):
+ if graph.name == 'g':
+ return False
+ return True
+
+ res = self.timeshift_from_portal(main, f, [2, 20, 10],
+ policy=StopAtGPolicy())
+ assert res == 1
More information about the Pypy-commit
mailing list