[pypy-svn] r32021 - in pypy/dist/pypy/jit: hintannotator hintannotator/test timeshifter timeshifter/test
pedronis at codespeak.net
pedronis at codespeak.net
Tue Sep 5 18:52:08 CEST 2006
Author: pedronis
Date: Tue Sep 5 18:52:06 2006
New Revision: 32021
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/rcontainer.py
pypy/dist/pypy/jit/timeshifter/rtyper.py
pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
pypy/dist/pypy/jit/timeshifter/test/test_vlist.py
Log:
(arre, pedronis)
start of having the hint-annotator exception transform the copied graphs it annotates.
with this in place we need to be careful about what pointer comparisons mean for virtual or
red virtual containers. Not all tests work with exceptiontransform on, to have them pass
we need to avoid pointer equality comparisions to force things to eagerly: next thing to do.
(For completely blue container this is controlled at annotation time, see code
added to annotate ptr_eq/ptr_ne for constant/virtual container pairs).
Modified: pypy/dist/pypy/jit/hintannotator/annotator.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/annotator.py (original)
+++ pypy/dist/pypy/jit/hintannotator/annotator.py Tue Sep 5 18:52:06 2006
@@ -3,14 +3,20 @@
from pypy.jit.hintannotator.bookkeeper import HintBookkeeper
from pypy.rpython.lltypesystem import lltype
+from pypy.translator.c.exceptiontransform import ExceptionTransformer
+
class HintAnnotator(RPythonAnnotator):
- def __init__(self, translator=None, policy=None):
- bookkeeper = HintBookkeeper(self)
+ def __init__(self, translator=None, base_translator=None, policy=None):
+ bookkeeper = HintBookkeeper(self)
RPythonAnnotator.__init__(self, translator, policy=policy,
bookkeeper=bookkeeper)
+ self.base_translator = base_translator
+ if getattr(policy, 'exceptiontransform', True) and base_translator is not None:
+ self.exceptiontransformer = ExceptionTransformer(base_translator)
+
def build_types(self, origgraph, input_args_hs):
desc = self.bookkeeper.getdesc(origgraph)
flowgraph = desc.specialize(input_args_hs)
@@ -38,5 +44,10 @@
def consider_op_keepalive(self, hs_v):
pass
+ def consider_op_debug_log_exc(self, hs_v):
+ pass
+
+ def simplify(self):
+ RPythonAnnotator.simplify(self, extra_passes=[])
HintAnnotator._registeroperations(hintmodel)
Modified: pypy/dist/pypy/jit/hintannotator/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/bookkeeper.py (original)
+++ pypy/dist/pypy/jit/hintannotator/bookkeeper.py Tue Sep 5 18:52:06 2006
@@ -1,6 +1,7 @@
from pypy.tool.tls import tlsobject
from pypy.objspace.flow.model import copygraph
from pypy.annotation import model as annmodel
+from pypy.rpython.lltypesystem import lltype
TLS = tlsobject()
@@ -31,7 +32,15 @@
try:
return self._cache[key]
except KeyError:
+ bk = self.bookkeeper
graph = copygraph(self.origgraph)
+ try:
+ exceptiontransformer = bk.annotator.exceptiontransformer
+ except AttributeError:
+ pass
+ else:
+ # except transform the copied graph before its hint-annotation
+ exceptiontransformer.create_exception_handling(graph)
if alt_name is not None:
graph.name = alt_name
self._cache[key] = graph
@@ -89,6 +98,12 @@
res.const = const.value
return res
+ def immutablevalue(self, value):
+ from pypy.jit.hintannotator import model as hintmodel
+ res = hintmodel.SomeLLAbstractConstant(lltype.typeOf(value), {})
+ res.const = value
+ return res
+
def current_op_concretetype(self):
_, block, i = self.position_key
op = block.operations[i]
Modified: pypy/dist/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/model.py (original)
+++ pypy/dist/pypy/jit/hintannotator/model.py Tue Sep 5 18:52:06 2006
@@ -19,7 +19,8 @@
char_gt char_lt char_le char_ge char_eq char_ne
int_gt int_lt int_le int_ge int_eq int_ne
uint_gt uint_lt uint_le uint_ge uint_eq uint_ne
- getarrayitem""".split()
+ getarrayitem
+ ptr_eq ptr_ne""".split()
class HintError(Exception):
pass
@@ -360,12 +361,27 @@
return pair(hs_cont2, hs_val1).union()
+
+
class __extend__(pairtype(SomeLLAbstractContainer, SomeLLAbstractConstant)):
def getarrayitem((hs_a1, hs_index)):
hs_res = hs_a1.contentdef.read_item()
return reorigin(hs_res, hs_res, hs_index)
+ def ptr_eq((hs_cont1, hs_ptr2)):
+ return getbookkeeper().immutablevalue(False)
+
+ def ptr_ne((hs_cont1, hs_ptr2)):
+ return getbookkeeper().immutablevalue(True)
+
+class __extend__(pairtype(SomeLLAbstractConstant, SomeLLAbstractContainer)):
+
+ def ptr_eq((hs_ptr1, hs_cont2)):
+ return getbookkeeper().immutablevalue(False)
+
+ def ptr_ne((hs_ptr1, hs_cont2)):
+ return getbookkeeper().immutablevalue(True)
# ____________________________________________________________
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 Tue Sep 5 18:52:06 2006
@@ -28,11 +28,11 @@
auto_inlining(t, inline)
graph1 = graphof(t, func)
# build hint annotator types
- hannotator = HintAnnotator(policy=policy)
- hannotator.base_translator = t
+ hannotator = HintAnnotator(base_translator=t, policy=policy)
hs = hannotator.build_types(graph1, [SomeLLAbstractConstant(v.concretetype,
{OriginFlags(): True})
for v in graph1.getargs()])
+ hannotator.simplify()
t = hannotator.translator
if conftest.option.view:
t.view()
@@ -258,6 +258,12 @@
assert hs.concretetype == lltype.Signed
assert len(hs.origins) == 4
+def test_make_a_list():
+ def ll_function(x, y):
+ return [x, y]
+ hs = hannotate(ll_function, [int, int], policy=P_OOPSPEC)
+ assert isinstance(hs, SomeLLAbstractContainer)
+
def test_simple_cast_pointer():
GCS1 = lltype.GcStruct('s1', ('x', lltype.Signed))
GCS2 = lltype.GcStruct('s2', ('sub', GCS1), ('y', lltype.Signed))
@@ -473,7 +479,6 @@
def test_raise_exc():
- py.test.skip("work in-progress")
class E(Exception):
pass
def f1():
@@ -488,7 +493,6 @@
def test_raise_and_catch_exc():
- py.test.skip("work in-progress")
class E(Exception):
pass
def f(flag):
@@ -502,7 +506,11 @@
return -1
return 0
- hannotate(g, [bool], policy=P_OOPSPEC_NOVIRTUAL)
+ hs = hannotate(g, [bool], policy=P_OOPSPEC_NOVIRTUAL)
+ # xxx this has a green return but the function has side effects
+ # we need to proper notice that for correct timeshifting
+ assert isinstance(hs, SomeLLAbstractConstant)
+ assert hs.concretetype == lltype.Signed
def f(flag):
if flag:
@@ -510,5 +518,8 @@
e.a = 3
raise e
- hannotate(g, [bool], policy=P_OOPSPEC_NOVIRTUAL)
-
+ hs = hannotate(g, [bool], policy=P_OOPSPEC_NOVIRTUAL)
+ # xxx this has a green return but the function has side effects
+ # we need to proper notice that for correct timeshifting
+ assert isinstance(hs, SomeLLAbstractConstant)
+ assert hs.concretetype == lltype.Signed
Modified: pypy/dist/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rcontainer.py (original)
+++ pypy/dist/pypy/jit/timeshifter/rcontainer.py Tue Sep 5 18:52:06 2006
@@ -3,7 +3,16 @@
from pypy.jit.timeshifter import rvalue
class AbstractContainer(object):
- pass
+
+ def op_getfield(self, jitstate, fielddesc):
+ raise NotImplementedError
+
+ def op_setfield(self, jitstate, fielddesc, valuebox):
+ raise NotImplementedError
+
+ def op_getsubstruct(self, jitstate, fielddesc):
+ raise NotImplementedError
+
# ____________________________________________________________
Modified: pypy/dist/pypy/jit/timeshifter/rtyper.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rtyper.py (original)
+++ pypy/dist/pypy/jit/timeshifter/rtyper.py Tue Sep 5 18:52:06 2006
@@ -107,6 +107,9 @@
# don't try to generate hint operations, just discard them
return hop.inputarg(hop.r_result, arg=0)
+ def translate_op_debug_log_exc(self, hop): # don't timeshift debug_log_exc
+ pass
+
def translate_op_keepalive(self,hop):
pass
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 Tue Sep 5 18:52:06 2006
@@ -21,6 +21,8 @@
P_NOVIRTUAL = AnnotatorPolicy()
P_NOVIRTUAL.novirtualcontainer = True
+P_NOVIRTUAL.exceptiontransform = False # XXX for now, needs to make ptr_ne/eq
+ # not force things
def getargtypes(annotator, values):
return [annotation(annotator, x) for x in values]
@@ -45,11 +47,11 @@
auto_inlining(t, inline)
graph1 = graphof(t, func)
# build hint annotator types
- hannotator = HintAnnotator(policy=policy)
- hannotator.base_translator = t
+ hannotator = HintAnnotator(base_translator=t, policy=policy)
hs = hannotator.build_types(graph1, [SomeLLAbstractConstant(v.concretetype,
{OriginFlags(): True})
for v in graph1.getargs()])
+ hannotator.simplify()
if conftest.option.view:
hannotator.translator.view()
return hs, hannotator, rtyper
Modified: pypy/dist/pypy/jit/timeshifter/test/test_vlist.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_vlist.py (original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_vlist.py Tue Sep 5 18:52:06 2006
@@ -4,6 +4,8 @@
P_OOPSPEC = AnnotatorPolicy()
P_OOPSPEC.novirtualcontainer = True
P_OOPSPEC.oopspec = True
+P_OOPSPEC.exceptiontransform = False # XXX for now, needs to make ptr_ne/eq
+ # not force things
class TestVList(TimeshiftingTests):
More information about the Pypy-commit
mailing list