[pypy-svn] r22796 - in pypy/dist/pypy/jit: . test
pedronis at codespeak.net
pedronis at codespeak.net
Sat Jan 28 16:29:57 CET 2006
Author: pedronis
Date: Sat Jan 28 16:29:53 2006
New Revision: 22796
Added:
pypy/dist/pypy/jit/hintcontainer.py (contents, props changed)
Modified:
pypy/dist/pypy/jit/hintannotator.py
pypy/dist/pypy/jit/hintbookkeeper.py
pypy/dist/pypy/jit/hintmodel.py
pypy/dist/pypy/jit/test/test_hint_annotation.py
Log:
(arre, arigo, pedronis)
started support for hint annotating containers. started with structures.
Modified: pypy/dist/pypy/jit/hintannotator.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator.py (original)
+++ pypy/dist/pypy/jit/hintannotator.py Sat Jan 28 16:29:53 2006
@@ -2,11 +2,19 @@
from pypy.jit import hintmodel
from pypy.jit.hintbookkeeper import HintBookkeeper
+
class HintAnnotator(RPythonAnnotator):
def __init__(self):
RPythonAnnotator.__init__(self)
self.bookkeeper = HintBookkeeper() # XXX
+ def consider_op_malloc(self, hs_TYPE):
+ TYPE = hs_TYPE.const
+ vstructdef = self.bookkeeper.getvirtualstructdef(TYPE)
+ return hintmodel.SomeLLAbstractContainer(vstructdef)
+
+
+
_registeroperations(HintAnnotator.__dict__, hintmodel)
Modified: pypy/dist/pypy/jit/hintbookkeeper.py
==============================================================================
--- pypy/dist/pypy/jit/hintbookkeeper.py (original)
+++ pypy/dist/pypy/jit/hintbookkeeper.py Sat Jan 28 16:29:53 2006
@@ -7,6 +7,7 @@
def __init__(self):
self.pending_specializations = []
self.origins = {}
+ self.virtual_containers = {}
def enter(self, position_key):
"""Start of an operation.
@@ -37,6 +38,17 @@
res.const = const.value
return res
+ def getvirtualstructdef(self, TYPE):
+ from pypy.jit.hintcontainer import VirtualStructDef
+ try:
+ res = self.virtual_containers[self.position_key]
+ assert isinstance(res, VirtualStructDef)
+ assert res.T == TYPE
+ except KeyError:
+ res = VirtualStructDef(self, TYPE)
+ self.virtual_containers[self.position_key] = res
+ return res
+
# get current bookkeeper
def getbookkeeper():
Added: pypy/dist/pypy/jit/hintcontainer.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/hintcontainer.py Sat Jan 28 16:29:53 2006
@@ -0,0 +1,48 @@
+from pypy.annotation.listdef import ListItem
+from pypy.jit import hintmodel
+
+class FieldValue(ListItem):
+
+ def __init__(self, bookkeeper, name, hs_value):
+ ListItem.__init__(self, bookkeeper, hs_value)
+ self.name = name
+
+ def patch(self):
+ for vstructdef in self.itemof:
+ vstructdef.fields[self.name] = self
+
+
+class VirtualStructDef:
+
+ def __init__(self, bookkeeper, TYPE):
+ self.T = TYPE
+ self.bookkeeper = bookkeeper
+ self.fields = {}
+ self.names = TYPE._names
+ for name in self.names:
+ hs = hintmodel.SomeLLAbstractConstant(self.fieldtype(name), {})
+ fv = self.fields[name] = FieldValue(bookkeeper, name, hs)
+ fv.itemof[self] = True
+
+ def fieldtype(self, name):
+ return getattr(self.T, name)
+
+ def read_field(self, name):
+ fv = self.fields[name]
+ fv.read_locations[self.bookkeeper.position_key] = True
+ return fv.s_value
+
+ def same_as(self, other):
+ return self.fields == other.fields
+
+ def union(self, other):
+ assert self.T == other.T
+ for name in self.names:
+ self.fields[name].merge(other.fields[name])
+ return self
+
+ def generalize_field(self, name, hs_value):
+ self.fields[name].generalize(hs_value)
+
+ def __repr__(self):
+ return "<VirtualStructDef '%s'>" % (self.T._name,)
Modified: pypy/dist/pypy/jit/hintmodel.py
==============================================================================
--- pypy/dist/pypy/jit/hintmodel.py (original)
+++ pypy/dist/pypy/jit/hintmodel.py Sat Jan 28 16:29:53 2006
@@ -3,7 +3,7 @@
from pypy.jit.hintbookkeeper import getbookkeeper
from pypy.rpython.lltypesystem import lltype
-UNARY_OPERATIONS = "same_as hint getfield".split()
+UNARY_OPERATIONS = "same_as hint getfield setfield".split()
BINARY_OPERATIONS = "int_add int_sub int_mul int_gt int_eq".split()
@@ -46,6 +46,12 @@
class SomeLLAbstractVariable(SomeLLAbstractValue):
pass
+class SomeLLAbstractContainer(SomeLLAbstractValue):
+
+ def __init__(self, contentdef):
+ self.contentdef = contentdef
+ self.concretetype = lltype.Ptr(contentdef.T)
+
# ____________________________________________________________
# operations
@@ -75,6 +81,15 @@
else:
return SomeLLAbstractVariable(FIELD_TYPE)
+class __extend__(SomeLLAbstractContainer):
+
+ def setfield(hs_s1, hs_fieldname, hs_value):
+ hs_s1.contentdef.generalize_field(hs_fieldname.const, hs_value)
+
+ def getfield(hs_s1, hs_fieldname):
+ return hs_s1.contentdef.read_field(hs_fieldname.const)
+
+
class __extend__(pairtype(SomeLLAbstractValue, SomeLLAbstractValue)):
def int_add((hs_v1, hs_v2)):
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 Sat Jan 28 16:29:53 2006
@@ -169,6 +169,22 @@
assert len(hs.origins) == 1
assert len(hs.origins.keys()[0].origins) == 2
+def test_simple_struct_malloc():
+ S = lltype.GcStruct('helloworld', ('hello', lltype.Signed),
+ ('world', lltype.Signed))
+ def ll_function(x):
+ s = lltype.malloc(S)
+ s.hello = x
+ return s.hello + s.world
+
+ 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
+
+
+
More information about the Pypy-commit
mailing list