[pypy-svn] r22810 - pypy/dist/pypy/jit

arigo at codespeak.net arigo at codespeak.net
Sat Jan 28 20:30:51 CET 2006


Author: arigo
Date: Sat Jan 28 20:30:48 2006
New Revision: 22810

Modified:
   pypy/dist/pypy/jit/hintannotator.py
   pypy/dist/pypy/jit/hintbookkeeper.py
   pypy/dist/pypy/jit/hintcontainer.py
Log:
(pedronis, arre around, arigo)

More random progress, more thinking needed.



Modified: pypy/dist/pypy/jit/hintannotator.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator.py	(original)
+++ pypy/dist/pypy/jit/hintannotator.py	Sat Jan 28 20:30:48 2006
@@ -11,10 +11,13 @@
 
     def consider_op_malloc(self, hs_TYPE):
         TYPE = hs_TYPE.const
-        vstructdef = self.bookkeeper.getvirtualstructdef(TYPE)
+        vstructdef = self.bookkeeper.getvirtualcontainerdef(TYPE)
         return hintmodel.SomeLLAbstractContainer(vstructdef)
-        
-        
+
+    def consider_op_malloc_varsize(self, hs_TYPE, hs_length):
+        TYPE = hs_TYPE.const
+        vcontainerdef = self.bookkeeper.getvirtualcontainerdef(TYPE)
+        return hintmodel.SomeLLAbstractContainer(vcontainerdef)
 
 
 _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 20:30:48 2006
@@ -39,14 +39,13 @@
         res.const = const.value
         return res
 
-    def getvirtualstructdef(self, TYPE):
-        from pypy.jit.hintcontainer import VirtualStructDef
+    def getvirtualcontainerdef(self, TYPE):
         try:
             res = self.virtual_containers[self.position_key]
-            assert isinstance(res, VirtualStructDef)
             assert res.T == TYPE
         except KeyError:
-            res = VirtualStructDef(self, TYPE)
+            from pypy.jit.hintcontainer import virtualcontainerdef
+            res = virtualcontainerdef(self, TYPE)
             self.virtual_containers[self.position_key] = res
         return res
         

Modified: pypy/dist/pypy/jit/hintcontainer.py
==============================================================================
--- pypy/dist/pypy/jit/hintcontainer.py	(original)
+++ pypy/dist/pypy/jit/hintcontainer.py	Sat Jan 28 20:30:48 2006
@@ -2,6 +2,27 @@
 from pypy.jit import hintmodel
 from pypy.rpython.lltypesystem import lltype
 
+def virtualcontainerdef(bookkeeper, T):
+    """Build and return a VirtualXxxDef() corresponding to a
+    freshly allocated virtual container.
+    """
+    if isinstance(T, lltype.Struct):
+        cls = VirtualStructDef
+    elif isinstance(T, lltype.Array):
+        cls = VirtualArrayDef
+    else:
+        raise TypeError("unsupported container type %r" % (T,))
+    return cls(bookkeeper, T)
+
+def make_item_annotation(bookkeeper, TYPE):
+    if isinstance(TYPE, lltype.ContainerType):
+        vdef = virtualcontainerdef(bookkeeper, TYPE)
+        return hintmodel.SomeLLAbstractContainer(vdef)
+    else:
+        return hintmodel.SomeLLAbstractConstant(TYPE, {})
+
+# ____________________________________________________________
+
 class FieldValue(ListItem):
 
     def __init__(self, bookkeeper, name, hs_value):
@@ -22,12 +43,7 @@
         self.names = TYPE._names
         for name in self.names:
             FIELD_TYPE = self.fieldtype(name)
-            if isinstance(FIELD_TYPE, lltype.ContainerType):
-                assert isinstance(FIELD_TYPE, lltype.Struct)   # for now
-                vstructdef = VirtualStructDef(bookkeeper, FIELD_TYPE)
-                hs = hintmodel.SomeLLAbstractContainer(vstructdef)
-            else:
-                hs = hintmodel.SomeLLAbstractConstant(FIELD_TYPE, {})
+            hs = make_item_annotation(bookkeeper, FIELD_TYPE)
             fv = self.fields[name] = FieldValue(bookkeeper, name, hs)
             fv.itemof[self] = True
 
@@ -53,3 +69,40 @@
 
     def __repr__(self):
         return "<VirtualStructDef '%s'>" % (self.T._name,)
+
+# ____________________________________________________________
+
+
+class ArrayItem(ListItem):
+
+    def patch(self):
+        for varraydef in self.itemof:
+            varraydef.arrayitem = self
+
+
+class VirtualArrayDef:
+
+    def __init__(self, bookkeeper, TYPE):
+        self.T = TYPE
+        self.bookkeeper = bookkeeper
+        hs = make_item_annotation(bookkeeper, TYPE.OF)
+        self.arrayitem = ArrayItem(bookkeeper, hs)
+        self.arrayitem.itemof[self] = True
+
+    def read_item(self):
+        self.arrayitem.read_locations[self.bookkeeper.position_key] = True
+        return self.arrayitem.s_value
+
+    def same_as(self, other):
+        return self.arrayitem is other.arrayitem
+
+    def union(self, other):
+        assert self.T == other.T
+        self.arrayitem.merge(other.arrayitem)
+        return self
+
+    def generalize_item(self, hs_value):
+        self.arrayitem.generalize(hs_value)
+
+    def __repr__(self):
+        return "<VirtualArrayDef of %r>" % (self.T.OF,)



More information about the Pypy-commit mailing list