Author: Armin Rigo <[email protected]>
Branch: bitstring
Changeset: r83912:5f39c39b300f
Date: 2016-04-26 16:50 +0200
http://bitbucket.org/pypy/pypy/changeset/5f39c39b300f/

Log:    Comments and tweaks

diff --git a/rpython/jit/codewriter/effectinfo.py 
b/rpython/jit/codewriter/effectinfo.py
--- a/rpython/jit/codewriter/effectinfo.py
+++ b/rpython/jit/codewriter/effectinfo.py
@@ -440,6 +440,8 @@
     for descr in all_descrs:
         if hasattr(descr, 'get_extra_info'):
             ei = descr.get_extra_info()
+            if ei is None:
+                continue
             if ei._readonly_descrs_fields is None:
                 for key in descrs:
                     assert getattr(ei, '_readonly_descrs_' + key) is None
@@ -453,17 +455,33 @@
                     descrs[key].update(getattr(ei, '_write_descrs_' + key))
         else:
             descr.ei_index = sys.maxint
+
     for key in descrs:
-        mapping = {}
+        all_sets = []
         for descr in descrs[key]:
-            assert descr.ei_index == sys.maxint    # not modified yet
             eisetr = [ei for ei in effectinfos
                          if descr in getattr(ei, '_readonly_descrs_' + key)]
             eisetw = [ei for ei in effectinfos
                          if descr in getattr(ei, '_write_descrs_' + key)]
+            # these are the set of all ei such that this descr is in
+            # ei._readonly_descrs or ei._write_descrs
             eisetr = frozenset(eisetr)
             eisetw = frozenset(eisetw)
+            all_sets.append((descr, eisetr, eisetw))
+
+        # heuristic to reduce the total size of the bitstrings: start with
+        # numbering the descrs that are seen in many EffectInfos.  If instead,
+        # by lack of chance, such a descr had a high number, then all these
+        # EffectInfos' bitstrings would need to store the same high number.
+        def size_of_both_sets((d, r, w)):
+            return len(r) + len(w)
+        all_sets.sort(key=size_of_both_sets, reverse=True)
+
+        mapping = {}
+        for (descr, eisetr, eisetw) in all_sets:
+            assert descr.ei_index == sys.maxint    # not modified yet
             descr.ei_index = mapping.setdefault((eisetr, eisetw), len(mapping))
+
         for ei in effectinfos:
             bitstrr = [descr.ei_index
                            for descr in getattr(ei, '_readonly_descrs_' + key)]
diff --git a/rpython/jit/metainterp/history.py 
b/rpython/jit/metainterp/history.py
--- a/rpython/jit/metainterp/history.py
+++ b/rpython/jit/metainterp/history.py
@@ -1,3 +1,4 @@
+import sys
 from rpython.rtyper.extregistry import ExtRegistryEntry
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
 from rpython.rlib.objectmodel import we_are_translated, Symbolic
@@ -87,9 +88,10 @@
 
 
 class AbstractDescr(AbstractValue):
-    __slots__ = ('descr_index',)
+    __slots__ = ('descr_index', 'ei_index')
     llopaque = True
     descr_index = -1
+    ei_index = sys.maxint
 
     def repr_of_descr(self):
         return '%r' % (self,)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to