[pypy-svn] r22845 - in pypy/dist/pypy/jit: . test
arigo at codespeak.net
arigo at codespeak.net
Sun Jan 29 15:55:35 CET 2006
Author: arigo
Date: Sun Jan 29 15:55:33 2006
New Revision: 22845
Modified:
pypy/dist/pypy/jit/hintbookkeeper.py
pypy/dist/pypy/jit/hintmodel.py
pypy/dist/pypy/jit/hintvlist.py
pypy/dist/pypy/jit/test/test_hint_annotation.py
Log:
(arre, pedronis, arigo)
Refactoring: removed the OriginTreeNode and replaced it with an empty box
OriginFlags. Now the SomeLLAbstractConstant annotations contain a family of
such boxes, which no longer point to each other directly.
Fixed the tests, added a nice __repr__.
The TL interpreter seems to get correct-looking annotations now :-)
Modified: pypy/dist/pypy/jit/hintbookkeeper.py
==============================================================================
--- pypy/dist/pypy/jit/hintbookkeeper.py (original)
+++ pypy/dist/pypy/jit/hintbookkeeper.py Sun Jan 29 15:55:33 2006
@@ -6,7 +6,7 @@
def __init__(self, hannotator):
self.pending_specializations = []
- self.origins = {}
+ self.originflags = {}
self.virtual_containers = {}
self.annotator = hannotator
@@ -23,11 +23,11 @@
def myorigin(self):
try:
- origin = self.origins[self.position_key]
+ origin = self.originflags[self.position_key]
except KeyError:
from pypy.jit import hintmodel
- origin = hintmodel.OriginTreeNode()
- self.origins[self.position_key] = origin
+ origin = hintmodel.OriginFlags()
+ self.originflags[self.position_key] = origin
return origin
def compute_at_fixpoint(self):
Modified: pypy/dist/pypy/jit/hintmodel.py
==============================================================================
--- pypy/dist/pypy/jit/hintmodel.py (original)
+++ pypy/dist/pypy/jit/hintmodel.py Sun Jan 29 15:55:33 2006
@@ -20,31 +20,17 @@
uint_gt uint_lt uint_le uint_ge uint_eq uint_ne
getarrayitem""".split()
-class OriginTreeNode(object):
+class OriginFlags(object):
fixed = False
- def __init__(self, origins=None):
- if origins is None:
- origins = {}
- self.origins = origins
-
- def merge(self, nodes):
- self.origins.update(nodes)
-
- def visit(self, seen=None):
- if seen is None:
- seen = {}
- yield self
- for o in self.origins:
- if o not in seen:
- seen[o] = True
- for o1 in o.visit(seen):
- yield o1
-
def __repr__(self):
- return "O" + (self.fixed and "f" or "")
-
+ if self.fixed:
+ s = "fixed "
+ else:
+ s = ""
+ return "<%sorigin>" % (s,)
+
class SomeLLAbstractValue(annmodel.SomeObject):
def __init__(self, T):
@@ -57,6 +43,22 @@
SomeLLAbstractValue.__init__(self, T)
self.origins = origins
+ def fmt_origins(self, origins):
+ counts = {}
+ for o in origins:
+ x = repr(o)
+ counts[x] = counts.get(x, 0) + 1
+ items = counts.items()
+ items.sort()
+ lst = []
+ for key, count in items:
+ s = ''
+ if count > 1:
+ s += '%d*' % count
+ s += key
+ lst.append(s)
+ return '<%s>' % (', '.join(lst),)
+
class SomeLLConcreteValue(SomeLLAbstractValue):
pass
@@ -69,14 +71,29 @@
self.contentdef = contentdef
self.concretetype = lltype.Ptr(contentdef.T)
+
+setunion = annmodel.setunion
+
+def setadd(set, newitem):
+ if newitem not in set:
+ set = set.copy()
+ set[newitem] = True
+ return set
+
+def newset(set, *sets):
+ set = set.copy()
+ for s2 in sets:
+ set.update(s2)
+ return set
+
def reorigin(hs_v1, *deps_hs):
if isinstance(hs_v1, SomeLLAbstractConstant):
- origin = getbookkeeper().myorigin()
- origin.merge(hs_v1.origins)
- for hs_dep in deps_hs:
- if isinstance(hs_v1, SomeLLAbstractConstant):
- origin.merge(hs_dep.origins)
- return SomeLLAbstractConstant(hs_v1.concretetype, {origin: True})
+ deps_origins = [hs_dep.origins for hs_dep in deps_hs
+ if isinstance(hs_dep, SomeLLAbstractConstant)]
+ d = newset(hs_v1.origins,
+ {getbookkeeper().myorigin(): True},
+ *deps_origins)
+ return SomeLLAbstractConstant(hs_v1.concretetype, d)
else:
return hs_v1
@@ -95,31 +112,27 @@
return SomeLLAbstractVariable(hs_c1.concretetype)
assert hs_flags.const['concrete']
for o in hs_c1.origins:
- for o1 in o.visit():
- o1.fixed = True
+ o.fixed = True
return SomeLLConcreteValue(hs_c1.concretetype)
def getfield(hs_c1, hs_fieldname):
S = hs_c1.concretetype.TO
FIELD_TYPE = getattr(S, hs_fieldname.const)
if S._hints.get('immutable', False):
- origin = getbookkeeper().myorigin()
- origin.merge(hs_c1.origins)
- return SomeLLAbstractConstant(FIELD_TYPE, {origin: True})
+ d = setadd(hs_c1.origins, getbookkeeper().myorigin())
+ return SomeLLAbstractConstant(FIELD_TYPE, d)
else:
return SomeLLAbstractVariable(FIELD_TYPE)
def getsubstruct(hs_c1, hs_fieldname):
S = hs_c1.concretetype.TO
SUB_TYPE = getattr(S, hs_fieldname.const)
- origin = getbookkeeper().myorigin()
- origin.merge(hs_c1.origins)
- return SomeLLAbstractConstant(lltype.Ptr(SUB_TYPE), {origin: True})
+ d = setadd(hs_c1.origins, getbookkeeper().myorigin())
+ return SomeLLAbstractConstant(lltype.Ptr(SUB_TYPE), d)
def getarraysize(hs_c1):
- origin = getbookkeeper().myorigin()
- origin.merge(hs_c1.origins)
- return SomeLLAbstractConstant(lltype.Signed, {origin: True})
+ d = setadd(hs_c1.origins, getbookkeeper().myorigin())
+ return SomeLLAbstractConstant(lltype.Signed, d)
def direct_call(hs_f1, *args_hs):
bookkeeper = getbookkeeper()
@@ -144,23 +157,20 @@
return reorigin(hs_res)
def unary_char(hs_c1):
- origin = getbookkeeper().myorigin()
- origin.merge(hs_c1.origins)
- return SomeLLAbstractConstant(lltype.Char, {origin: True})
+ d = setadd(hs_c1.origins, getbookkeeper().myorigin())
+ return SomeLLAbstractConstant(lltype.Char, d)
cast_int_to_char = unary_char
def unary_int(hs_c1):
- origin = getbookkeeper().myorigin()
- origin.merge(hs_c1.origins)
- return SomeLLAbstractConstant(lltype.Signed, {origin: True})
+ d = setadd(hs_c1.origins, getbookkeeper().myorigin())
+ return SomeLLAbstractConstant(lltype.Signed, d)
cast_uint_to_int = cast_bool_to_int = cast_char_to_int = int_neg = unary_int
def int_is_true(hs_c1):
- origin = getbookkeeper().myorigin()
- origin.merge(hs_c1.origins)
- return SomeLLAbstractConstant(lltype.Bool, {origin: True})
+ d = setadd(hs_c1.origins, getbookkeeper().myorigin())
+ return SomeLLAbstractConstant(lltype.Bool, d)
uint_is_true = int_is_true
@@ -230,43 +240,39 @@
class __extend__(pairtype(SomeLLAbstractConstant, SomeLLAbstractConstant)):
def int_add((hs_c1, hs_c2)):
- origin = getbookkeeper().myorigin()
- origin.merge(hs_c1.origins)
- origin.merge(hs_c2.origins)
- return SomeLLAbstractConstant(lltype.Signed, {origin: True})
+ d = newset(hs_c1.origins, hs_c2.origins,
+ {getbookkeeper().myorigin(): True})
+ return SomeLLAbstractConstant(lltype.Signed, d)
int_floordiv = int_rshift = int_and = int_mul = int_mod = int_sub = int_add
def uint_add((hs_c1, hs_c2)):
- origin = getbookkeeper().myorigin()
- origin.merge(hs_c1.origins)
- origin.merge(hs_c2.origins)
- return SomeLLAbstractConstant(lltype.Unsigned, {origin: True})
+ d = newset(hs_c1.origins, hs_c2.origins,
+ {getbookkeeper().myorigin(): True})
+ return SomeLLAbstractConstant(lltype.Unsigned, d)
uint_floordiv = uint_rshift = uint_and = uint_mul = uint_mod = uint_sub = uint_add
def int_eq((hs_c1, hs_c2)):
- origin = getbookkeeper().myorigin()
- origin.merge(hs_c1.origins)
- origin.merge(hs_c2.origins)
- return SomeLLAbstractConstant(lltype.Bool, {origin: True})
+ d = newset(hs_c1.origins, hs_c2.origins,
+ {getbookkeeper().myorigin(): True})
+ return SomeLLAbstractConstant(lltype.Bool, d)
int_lt = int_le = int_ge = int_ne = int_gt = int_eq
uint_lt = uint_le = uint_ge = uint_ne = uint_gt = uint_eq = int_eq
def union((hs_c1, hs_c2)):
assert hs_c1.concretetype == hs_c2.concretetype
- origins = annmodel.setunion(hs_c1.origins, hs_c2.origins)
- return SomeLLAbstractConstant(hs_c1.concretetype, origins)
+ d = newset(hs_c1.origins, hs_c2.origins)
+ return SomeLLAbstractConstant(hs_c1.concretetype, d)
def getarrayitem((hs_c1, hs_index)):
A = hs_c1.concretetype.TO
READ_TYPE = A.OF
if A._hints.get('immutable', False):
- origin = getbookkeeper().myorigin()
- origin.merge(hs_c1.origins)
- origin.merge(hs_index.origins)
- return SomeLLAbstractConstant(READ_TYPE, {origin: True})
+ d = newset(hs_c1.origins, hs_index.origins,
+ {getbookkeeper().myorigin(): True})
+ return SomeLLAbstractConstant(READ_TYPE, d)
else:
return SomeLLAbstractVariable(READ_TYPE)
Modified: pypy/dist/pypy/jit/hintvlist.py
==============================================================================
--- pypy/dist/pypy/jit/hintvlist.py (original)
+++ pypy/dist/pypy/jit/hintvlist.py Sun Jan 29 15:55:33 2006
@@ -1,5 +1,6 @@
from pypy.annotation.listdef import ListItem
-from pypy.jit import hintmodel
+from pypy.jit.hintmodel import SomeLLAbstractConstant
+from pypy.jit.hintmodel import SomeLLAbstractContainer, reorigin
from pypy.jit.hintbookkeeper import getbookkeeper
from pypy.jit.hintcontainer import AbstractContainerDef, make_item_annotation
from pypy.rpython.lltypesystem import lltype
@@ -34,15 +35,15 @@
def oop_len(self):
origin = getbookkeeper().myorigin()
- return hintmodel.SomeLLAbstractConstant(lltype.Signed, {origin: True})
+ return SomeLLAbstractConstant(lltype.Signed, {origin: True})
def oop_nonzero(self):
origin = getbookkeeper().myorigin()
- return hintmodel.SomeLLAbstractConstant(lltype.Bool, {origin: True})
+ return SomeLLAbstractConstant(lltype.Bool, {origin: True})
def oop_getitem(self, hs_index):
assert hs_index.concretetype == lltype.Signed
- return self.read_item()
+ return reorigin(self.read_item(), hs_index)
def oop_setitem(self, hs_index, hs_value):
assert hs_index.concretetype == lltype.Signed
@@ -60,7 +61,7 @@
def oop_pop(self, hs_index=None):
assert hs_index is None or hs_index.concretetype == lltype.Signed
- return self.read_item()
+ return reorigin(self.read_item(), hs_index)
def oop_reverse(self):
pass
@@ -69,10 +70,10 @@
bk = self.bookkeeper
vlistdef = bk.getvirtualcontainerdef(self.T, VirtualListDef)
vlistdef.generalize_item(self.read_item())
- return hintmodel.SomeLLAbstractContainer(vlistdef)
+ return SomeLLAbstractContainer(vlistdef)
def oop_concat(self, hs_other):
- assert isinstance(hs_other, hintmodel.SomeLLAbstractContainer) # for now
+ assert isinstance(hs_other, SomeLLAbstractContainer) # for now
assert hs_other.contentdef.T == self.T
return self.oop_copy()
@@ -82,4 +83,4 @@
bk = getbookkeeper()
LIST = bk.current_op_concretetype().TO
vlistdef = bk.getvirtualcontainerdef(LIST, VirtualListDef)
- return hintmodel.SomeLLAbstractContainer(vlistdef)
+ return SomeLLAbstractContainer(vlistdef)
Modified: pypy/dist/pypy/jit/test/test_hint_annotation.py
==============================================================================
--- pypy/dist/pypy/jit/test/test_hint_annotation.py (original)
+++ pypy/dist/pypy/jit/test/test_hint_annotation.py Sun Jan 29 15:55:33 2006
@@ -21,11 +21,11 @@
graph1 = graphof(t, func)
# build hint annotator types
hannotator = HintAnnotator(t, policy=policy)
+ t.annotator = hannotator # XXX?
hs = hannotator.build_graph_types(graph1, [SomeLLAbstractConstant(v.concretetype,
- {OriginTreeNode(): True})
+ {OriginFlags(): True})
for v in graph1.getargs()])
- #hannotator.translator.graphs.append(graph1)
- #hannotator.translator.view()
+ #t.view()
if annotator:
return hs, hannotator
else:
@@ -36,7 +36,7 @@
return x + y
hs = hannotate(ll_function, [int, int])
assert isinstance(hs, SomeLLAbstractConstant)
- assert len(hs.origins) == 1
+ assert len(hs.origins) == 3
assert hs.concretetype == lltype.Signed
def test_join():
@@ -48,7 +48,7 @@
return z
hs = hannotate(ll_function, [bool, int, int])
assert isinstance(hs, SomeLLAbstractConstant)
- assert len(hs.origins) == 2
+ assert len(hs.origins) == 4
assert hs.concretetype == lltype.Signed
@@ -74,13 +74,9 @@
return z # origin of z1
hs = hannotate(ll_function, [bool, int, int])
assert isinstance(hs, SomeLLAbstractConstant)
- assert len(hs.origins) == 2
+ assert len(hs.origins) == 4
for o in hs.origins:
assert o.fixed
- assert len(o.origins) == 2
- for o in o.origins:
- assert o.fixed
- assert not o.origins
assert hs.concretetype == lltype.Signed
def test_simple_variable():
@@ -156,7 +152,7 @@
hs = hannotate(ll_function, [int, int])
assert isinstance(hs, SomeLLAbstractConstant)
assert hs.concretetype == lltype.Signed
- assert len(hs.origins) == 2
+ assert len(hs.origins) == 4
def test_loop1():
def ll_function(x, y):
@@ -169,7 +165,7 @@
hs = hannotate(ll_function, [int, int])
assert isinstance(hs, SomeLLAbstractConstant)
assert hs.concretetype == lltype.Signed
- assert len(hs.origins) == 2
+ assert len(hs.origins) == 4
def test_simple_struct():
S = lltype.GcStruct('helloworld', ('hello', lltype.Signed),
@@ -180,8 +176,7 @@
hs = hannotate(ll_function, [annmodel.SomePtr(lltype.Ptr(S))])
assert isinstance(hs, SomeLLAbstractConstant)
assert hs.concretetype == lltype.Signed
- assert len(hs.origins) == 1
- assert len(hs.origins.keys()[0].origins) == 2
+ assert len(hs.origins) == 4
def test_simple_struct_malloc():
S = lltype.GcStruct('helloworld', ('hello', lltype.Signed),
@@ -194,8 +189,7 @@
hs = hannotate(ll_function, [int])
assert isinstance(hs, SomeLLAbstractConstant)
assert hs.concretetype == lltype.Signed
- assert len(hs.origins) == 1
- assert len(hs.origins.keys()[0].origins) == 1
+ assert len(hs.origins) == 2
def test_container_union():
S = lltype.GcStruct('helloworld', ('hello', lltype.Signed),
@@ -212,8 +206,7 @@
hs = hannotate(ll_function, [bool, int, int])
assert isinstance(hs, SomeLLAbstractConstant)
assert hs.concretetype == lltype.Signed
- assert len(hs.origins) == 1
- assert len(hs.origins.keys()[0].origins) == 2
+ assert len(hs.origins) == 3
def test_simple_call():
def ll2(x, y):
@@ -223,7 +216,7 @@
hs = hannotate(ll1, [int, int, int])
assert isinstance(hs, SomeLLAbstractConstant)
assert hs.concretetype == lltype.Signed
- assert len(hs.origins) == 1
+ assert len(hs.origins) == 7
def test_simple_list_operations():
def ll_function(x, y, index):
@@ -233,7 +226,7 @@
hs = hannotate(ll_function, [int, int, int], policy=P_OOPSPEC)
assert isinstance(hs, SomeLLAbstractConstant)
assert hs.concretetype == lltype.Signed
- assert len(hs.origins) == 2
+ assert len(hs.origins) == 4
def test_some_more_list_operations():
def ll_function(x, y, index):
@@ -244,7 +237,7 @@
hs = hannotate(ll_function, [int, int, int], policy=P_OOPSPEC)
assert isinstance(hs, SomeLLAbstractConstant)
assert hs.concretetype == lltype.Signed
- assert len(hs.origins) == 2
+ assert len(hs.origins) == 4
def test_simple_cast_pointer():
GCS1 = lltype.GcStruct('s1', ('x', lltype.Signed))
@@ -293,5 +286,4 @@
def test_hannotate_tl():
from pypy.jit import tl
-
- hannotate(tl.interp, [str, int])
+ hannotate(tl.interp, [str, int], policy=P_OOPSPEC)
More information about the Pypy-commit
mailing list