Commits

Maciej Fijalkowski committed 748b649

improve hashing

  • Participants
  • Parent commits 8e8b239
  • Branches result-in-resops

Comments (0)

Files changed (6)

 
-* make OptValue somehow leaner using subclassing instead of one-size-fit-most
+* make OptValue somehow leaner using subclassing instead of one-size-fit-most.
+  right now we have 1-1, so should be easy to make OptValue immutable
 
 * rethink interning vs other ideas of caching for getinterned on optimizer
   and cache fields

File pypy/jit/metainterp/optimizeopt/optimizer.py

      Const, ConstInt, ConstFloat, AbstractValue
 from pypy.jit.metainterp.typesystem import llhelper
 from pypy.rlib.objectmodel import specialize
+from pypy.tool.pairtype import extendabletype
 
 LEVEL_UNKNOWN    = '\x00'
 LEVEL_NONNULL    = '\x01'
 
 class OptValue(object):
     _attrs_ = ('known_class', 'last_guard', 'level', 'intbound', 'lenbound', 'is_bool_box')
+
+    __metaclass__ = extendabletype
+    
     last_guard = None
-
     level = LEVEL_UNKNOWN
     known_class = None
     intbound = ImmutableIntUnbounded()

File pypy/jit/metainterp/optimizeopt/pure.py

                 return
 
             # did we do the exact same operation already?
+            import pdb
+            pdb.set_trace()
             oldop = self.pure_operations.get(op)
             if oldop is not None:
                 self.replace(op, oldop)

File pypy/jit/metainterp/optimizeopt/util.py

                 a.values = self.values[:]
             return a
 
-        def __repr__(self):
-            return 'ArgsSet(%s)' % ([item for item in self.buckets if item is not None],)
+        if has_value:
+            def __repr__(self):
+                return 'ArgsDict(%s)' % (['%s: %s' % (item, self.values[i])
+                                          for i, item in
+                                          enumerate(self.buckets)
+                                          if item is not None],)
+        else:
+            def __repr__(self):
+                return 'ArgsSet(%s)' % ([item for item in self.buckets
+                                         if item is not None],)
     return ArgsSet
 ArgsSet = new_args_set()
 ArgsDict = new_args_set(True)

File pypy/jit/metainterp/optimizeopt/vstring.py

 from pypy.jit.metainterp.optimizeopt.optimizer import llhelper, REMOVED
 from pypy.jit.metainterp.optimizeopt.util import make_dispatcher_method
 from pypy.jit.metainterp.resoperation import rop, Const, ConstInt, ConstPtr,\
-     BoxInt, BoxPtr, REF, INT
+     BoxInt, BoxPtr, REF, INT, create_resop_1
 from pypy.rlib.objectmodel import specialize, we_are_translated
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rpython import annlowlevel
         if string_optimizer is None:
             return None
         self.ensure_nonnull()
-        box = self.force_box(string_optimizer)
-        if lengthbox is None:
-            lengthbox = BoxInt()
-        string_optimizer.emit_operation(ResOperation(mode.STRLEN, [box], lengthbox))
+        self.force_box(string_optimizer)
+        # ???
+        #lengthop = create_resop_1(mode.STRLEN, 0, box)
+        string_optimizer.emit_operation(lengthbox)
         return lengthbox
 
     @specialize.arg(1)
 
     def _optimize_STRLEN(self, op, mode):
         value = self.getvalue(op.getarg(0))
-        lengthbox = value.getstrlen(self, mode, op.result)
-        if op.result in self.optimizer.values:
-            assert self.getvalue(op.result) is self.getvalue(lengthbox)
-        elif op.result is not lengthbox:
-            self.make_equal_to(op.result, self.getvalue(lengthbox))
+        lengthbox = value.getstrlen(self, mode, op)
+        if op.has_extra("optimize_value"):
+            assert self.getvalue(op) is self.getvalue(lengthbox)
+        elif op is not lengthbox:
+            self.replace(op, lengthbox)
 
     def optimize_COPYSTRCONTENT(self, op):
         self._optimize_COPYSTRCONTENT(op, mode_string)

File pypy/jit/metainterp/resoperation.py

     def nonconstbox(self):
         return self
 
+    def _get_hash_(self):
+        return compute_identity_hash(self)
+
     def __repr__(self):
         result = str(self)
         if self._extended_display:
     def getaddr(self):
         return heaptracker.int2adr(self.value)
 
-    def _get_hash_(self):
-        return make_hashable_int(self.value)
-
     def nonnull(self):
         return self.value != 0
 
     def getfloatstorage(self):
         return self.value
 
-    def _get_hash_(self):
-        return longlong.gethash(self.value)
-
     def nonnull(self):
         return self.value != longlong.ZEROF
 
     def getaddr(self):
         return llmemory.cast_ptr_to_adr(self.value)
 
-    def _get_hash_(self):
-        if self.value:
-            return lltype.identityhash(self.value)
-        else:
-            return 0
-
     def nonnull(self):
         return bool(self.value)
 
         if self._hash != 0:
             return self._hash
         hash = (self.getopnum() ^
-                self.get_result_hash() ^
+                intmask(self.get_result_hash() << 4) ^
                 self.get_descr_hash() ^
                 self.get_arg_hash())
         if hash == 0:
         return res
 
     def get_arg_hash(self):
-        return (intmask(self._arg0._get_hash_() << 16) +
+        return (intmask(self._arg0._get_hash_() << 1) ^
                 self._arg1._get_hash_())
 
     def args_eq(self, other):
         return r
 
     def get_arg_hash(self):
-        return (intmask(self._arg0._get_hash_() << 24) +
-                intmask(self._arg1._get_hash_() << 16) +
+        return (intmask(self._arg0._get_hash_() << 2) ^
+                intmask(self._arg1._get_hash_() << 1) ^
                 self._arg2._get_hash_())
 
     def args_eq(self, other):