[pypy-svn] r35905 - in pypy/dist/pypy: annotation rpython rpython/lltypesystem

mwh at codespeak.net mwh at codespeak.net
Tue Dec 19 21:51:13 CET 2006


Author: mwh
Date: Tue Dec 19 21:51:12 2006
New Revision: 35905

Modified:
   pypy/dist/pypy/annotation/model.py
   pypy/dist/pypy/rpython/lltypesystem/rpbc.py
   pypy/dist/pypy/rpython/rpbc.py
Log:
attempt to avoid non-trivial char->char conversions for SmallFuncSetReprs.
seems to help performance a bit, at least.


Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py	(original)
+++ pypy/dist/pypy/annotation/model.py	Tue Dec 19 21:51:12 2006
@@ -322,11 +322,12 @@
     or a set of such instances."""
     immutable = True
 
-    def __init__(self, descriptions, can_be_None=False):
+    def __init__(self, descriptions, can_be_None=False, subset_of=None):
         # descriptions is a set of Desc instances.
         descriptions = dict.fromkeys(descriptions)
         self.descriptions = descriptions
         self.can_be_None = can_be_None
+        self.subset_of = subset_of
         self.simplify()
         if self.isNone():
             self.knowntype = type(None)

Modified: pypy/dist/pypy/rpython/lltypesystem/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rpbc.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rpbc.py	Tue Dec 19 21:51:12 2006
@@ -131,13 +131,21 @@
         assert len(uniquerows) == 1
         self.lowleveltype = Char
         self.pointer_repr = FunctionsPBCRepr(rtyper, s_pbc)
-        self.descriptions = list(s_pbc.descriptions)
-        if self.s_pbc.can_be_None:
-            self.descriptions.insert(0, None)
         self._conversion_tables = {}
         self._dispatch_cache = {}
 
     def _setup_repr(self):
+        if self.s_pbc.subset_of:
+            assert self.s_pbc.can_be_None == self.s_pbc.subset_of.can_be_None
+            r = self.rtyper.getrepr(self.s_pbc.subset_of)
+            if r is not self:
+                r.setup()
+                self.descriptions = r.descriptions
+                self.c_pointer_table = r.c_pointer_table
+                return
+        self.descriptions = list(self.s_pbc.descriptions)
+        if self.s_pbc.can_be_None:
+            self.descriptions.insert(0, None)
         POINTER_TABLE = Array(self.pointer_repr.lowleveltype)
         pointer_table = malloc(POINTER_TABLE, len(self.descriptions),
                                immortal=True)
@@ -147,7 +155,6 @@
             else:
                 pointer_table[i] = self.pointer_repr.convert_const(None)
         self.c_pointer_table = inputconst(Ptr(POINTER_TABLE), pointer_table)
-        from pypy.objspace.flow import model
 
     def get_s_callable(self):
         return self.s_pbc
@@ -192,7 +199,10 @@
         graph = FunctionGraph("dispatcher", startblock, varoftype(resulttype))
         row_of_graphs = self.callfamily.calltables[shape][index]
         links = []
-        for i, desc in enumerate(self.descriptions):
+        descs = list(self.s_pbc.descriptions)
+        if self.s_pbc.can_be_None:
+            descs.insert(0, None)
+        for desc in descs:
             if desc is None:
                 continue
             args_v = [varoftype(t) for t in argtypes]
@@ -203,6 +213,7 @@
             b.operations.append(
                 SpaceOperation("direct_call", [v_fn] + args_v, v_result))
             b.closeblock(Link([v_result], graph.returnblock))
+            i = self.descriptions.index(desc)
             links.append(Link(inputargs[1:], b, chr(i)))
             links[-1].llexitcase = chr(i)
         startblock.closeblock(*links)
@@ -285,11 +296,22 @@
         r_from._conversion_tables[r_to] = r
         return r
 
+## myf = open('convlog.txt', 'w')
+
 class __extend__(pairtype(SmallFunctionSetPBCRepr, SmallFunctionSetPBCRepr)):
     def convert_from_to((r_from, r_to), v, llops):
         c_table = conversion_table(r_from, r_to)
         if c_table:
             assert v.concretetype is Char
+##             from pypy.rpython.lltypesystem.rstr import string_repr
+##             s = repr(llops.rtyper.annotator.annotated.get(llops.originalblock))
+##             if 'LOAD_GLOBAL' in s:
+##                 import pdb; pdb.set_trace()
+##             print >> myf, 'static small conv', s
+##             print 'static small conv', s
+##             llops.genop('debug_print',
+##                         [Constant(string_repr.convert_const("dynamic small conv" + s),
+##                                   string_repr.lowleveltype)])
             v_int = llops.genop('cast_char_to_int', [v],
                                 resulttype=Signed)
             return llops.genop('getarrayitem', [c_table, v_int],
@@ -317,7 +339,7 @@
         # s_func = r_func.s_pbc -- not precise enough, see
         # test_precise_method_call_1.  Build a more precise one...
         funcdescs = [desc.funcdesc for desc in hop.args_s[0].descriptions]
-        s_func = annmodel.SomePBC(funcdescs)
+        s_func = annmodel.SomePBC(funcdescs, subset_of=r_func.s_pbc)
         v_im_self = hop.inputarg(self, arg=0)
         v_cls = self.r_im_self.getfield(v_im_self, '__class__', hop.llops)
         v_func = r_class.getclsfield(v_cls, self.methodname, hop.llops)

Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py	(original)
+++ pypy/dist/pypy/rpython/rpbc.py	Tue Dec 19 21:51:12 2006
@@ -14,6 +14,15 @@
 
 from pypy.rpython import callparse
 
+def small_cand(rtyper, s_pbc):
+    if 1 < len(s_pbc.descriptions) < rtyper.getconfig().translation.withsmallfuncsets and \
+           hasattr(rtyper.type_system.rpbc, 'SmallFunctionSetPBCRepr'):
+        callfamily = s_pbc.descriptions.iterkeys().next().getcallfamily()
+        concretetable, uniquerows = get_concrete_calltable(rtyper, callfamily)
+        if len(uniquerows) == 1 and (not s_pbc.subset_of or small_cand(rtyper, s_pbc.subset_of)):
+            return True
+    return False
+
 class __extend__(annmodel.SomePBC):
     def rtyper_makerepr(self, rtyper):
         if self.isNone():
@@ -27,12 +36,8 @@
                     getRepr = OverriddenFunctionPBCRepr
                 else:
                     getRepr = rtyper.type_system.rpbc.FunctionsPBCRepr
-                    if 1 < len(self.descriptions) < rtyper.getconfig().translation.withsmallfuncsets and \
-                           hasattr(rtyper.type_system.rpbc, 'SmallFunctionSetPBCRepr'):
-                        callfamily = self.descriptions.iterkeys().next().getcallfamily()
-                        concretetable, uniquerows = get_concrete_calltable(rtyper, callfamily)
-                        if len(uniquerows) == 1:
-                            getRepr = rtyper.type_system.rpbc.SmallFunctionSetPBCRepr
+                    if small_cand(rtyper, self):
+                        getRepr = rtyper.type_system.rpbc.SmallFunctionSetPBCRepr
             else:
                 getRepr = getFrozenPBCRepr
         elif issubclass(kind, description.ClassDesc):
@@ -61,7 +66,11 @@
     def rtyper_makekey(self):
         lst = list(self.descriptions)
         lst.sort()
-        return tuple([self.__class__, self.can_be_None]+lst)
+        if self.subset_of:
+            t = self.subset_of.rtyper_makekey()
+        else:
+            t = ()
+        return tuple([self.__class__, self.can_be_None]+lst)+t
 
 ##builtin_descriptor_type = (
 ##    type(len),                            # type 'builtin_function_or_method'



More information about the Pypy-commit mailing list