Commits

Hakan Ardo committed a2aeb3b

interface to specify which boxes will survive into next iteration

  • Participants
  • Parent commits 9d324e8
  • Branches jit-fromstart

Comments (0)

Files changed (9)

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

     def __init__(self):
         self.funcinfo = None
 
-    def clone_for_next_iteration(self, optimizer, valuemap):
+    def clone_for_next_iteration(self, surviving_boxes, optimizer, valuemap):
         return OptFfiCall()
         # FIXME: Should any status be saved for next iteration?
 

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

         self.lazy_setfields = {}
         self.lazy_setfields_descrs = []     # keys (at least) of previous dict
 
-    def clone_for_next_iteration(self, optimizer, valuemap):
+    def clone_for_next_iteration(self, surviving_boxes, optimizer, valuemap):
         new = OptHeap()
-        return new
-        # FIXME:
 
-        if True:
-            self.force_all_lazy_setfields()
-            assert not self.lazy_setfields_descrs
-            assert not self.lazy_setfields
-        else:
-            new.lazy_setfields_descrs = self.lazy_setfields_descrs
-            new.lazy_setfields = self.lazy_setfields
+        self.force_all_lazy_setfields()
+        assert not self.lazy_setfields_descrs
+        assert not self.lazy_setfields
         
         for descr, d in self.cached_fields.items():
             newd = {}
             new.cached_fields[descr] = newd
             for value, fieldvalue in d.items():
                 newd[value.get_reconstructed(optimizer, valuemap)] = \
-                                       fieldvalue.get_reconstructed(optimizer, valuemap)
+                             fieldvalue.get_reconstructed(optimizer, valuemap)
             
         for descr, d in self.known_heap_fields.items():
             newd = {}
             new.known_heap_fields[descr] = newd
             for value, fieldvalue in d.items():
                 newd[value.get_reconstructed(optimizer, valuemap)] = \
-                                       fieldvalue.get_reconstructed(optimizer, valuemap)
-            
+                             fieldvalue.get_reconstructed(optimizer, valuemap)
+
         new.cached_arrayitems = {}
         for descr, d in self.cached_arrayitems.items():
             newd = {}
                 newd[value.get_reconstructed(optimizer, valuemap)] = newcache
                 if cache.var_index_item:
                     newcache.var_index_item = \
-                          cache.var_index_item.get_reconstructed(optimizer, valuemap)
+                          cache.var_index_item.get_reconstructed(optimizer,
+                                                                 valuemap)
                 if cache.var_index_indexvalue:
                     newcache.var_index_indexvalue = \
-                          cache.var_index_indexvalue.get_reconstructed(optimizer, valuemap)
+                        cache.var_index_indexvalue.get_reconstructed(optimizer,
+                                                                     valuemap)
                 for index, fieldvalue in cache.fixed_index_items.items():
                     newcache.fixed_index_items[index] = \
                            fieldvalue.get_reconstructed(optimizer, valuemap)

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

         self.posponedop = None
         self.nextop = None
 
-    def clone_for_next_iteration(self, optimizer, valuemap):
+    def clone_for_next_iteration(self, surviving_boxes, optimizer, valuemap):
         assert self.posponedop is None
         return OptIntBounds()
 

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

     def turned_constant(self, value):
         pass
 
-    def clone_for_next_iteration(self, optimizer=None, valuemap=None):
+    def clone_for_next_iteration(self, surviving_boxes=None,
+                                 optimizer=None, valuemap=None):
         raise NotImplementedError
     
 
         for o in self.optimizations:
             o.force_at_end_of_preamble()
             
-    def clone_for_next_iteration(self, optimizer=None, valuemap=None):
+    def clone_for_next_iteration(self, surviving_boxes=None,
+                                 optimizer=None, valuemap=None):
         assert optimizer is None
         assert valuemap is None
+        if surviving_boxes is None:
+            surviving_boxes = []
+        else:
+            surviving_boxes = surviving_boxes[:]
         valuemap = {}
         new = Optimizer(self.metainterp_sd, self.loop)
         new.values = {}
-        optimizations = [o.clone_for_next_iteration(new, valuemap) for o in 
-                         self.optimizations]
+        optimizations = [o.clone_for_next_iteration(surviving_boxes, 
+                                                    new, valuemap)
+                         for o in self.optimizations]
         new.set_optimizations(optimizations)
 
         # FIXME: new.interned_refs = self.interned_refs
             for i in range(len(newargs)):
                 if isinstance(newargs[i], OptValue):
                     newargs[i] = newargs[i].get_reconstructed(new, valuemap)
-            v = self.getvalue(op.result)
-            new.values[op.result] = v.get_reconstructed(new, valuemap)
+            surviving_boxes.append(op.result)
             new.pure_operations[newargs] = op
             # FIXME: This will not work for ops with mutable descr
             
         # FIXME: Any point in propagating these? new.producer = self.producer
+
         assert self.posponedop is None
 
+        for box in surviving_boxes:
+            v = self.getvalue(box)
+            new.values[box] = v.get_reconstructed(new, valuemap)
+
         return new
 
     def turned_constant(self, value):

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

        This includes already executed operations and constants.
     """
 
-    def clone_for_next_iteration(self, optimizer, valuemap):
+    def clone_for_next_iteration(self, surviving_boxes, optimizer, valuemap):
         return OptRewrite()
     
     def propagate_forward(self, op):

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

     "Handling of strings and unicodes."
     enabled = True
 
-    def clone_for_next_iteration(self, optimizer, valuemap):
+    def clone_for_next_iteration(self, surviving_boxes, optimizer, valuemap):
         return OptString()
     
     def make_vstring_plain(self, box, source_op, mode):

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

             jumpop.initarglist([])            
 
             preamble_optmizer = self.optimizer
-            self.optimizer = preamble_optmizer.clone_for_next_iteration()
+            self.optimizer = \
+                        preamble_optmizer.clone_for_next_iteration(jump_args)
             inputargs = self.inline(self.cloned_operations,
                                     loop.inputargs, jump_args)
 
 
                 if True:
                     self.optimizer = \
-                            preamble_optmizer.clone_for_next_iteration()
+                          preamble_optmizer.clone_for_next_iteration(jump_args)
                     self.optimizer.extraargs = loop.inputargs
                     loop.inputargs = self.inline(self.cloned_operations,
                                              loop_inputargs, jump_args)
         return self.map[loopbox]
 
 class OptInlineShortPreamble(Optimization):
-    def clone_for_next_iteration(self, optimizer, valuemap):
+    def clone_for_next_iteration(self, surviving_boxes, optimizer, valuemap):
         return OptInlineShortPreamble()
     
     def propagate_forward(self, op):

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

 class OptVirtualize(optimizer.Optimization):
     "Virtualize objects until they escape."
 
-    def clone_for_next_iteration(self, optimizer, valuemap):
+    def clone_for_next_iteration(self, surviving_boxes, optimizer, valuemap):
         return OptVirtualize()
 
     def make_virtual(self, known_class, box, source_op=None):

File pypy/jit/metainterp/test/test_optimizeopt.py

         i1 = ptr_eq(p0, NULL)
         guard_false(i1) []
         i2 = ptr_ne(NULL, p0)
-        guard_true(i0) []
+        guard_true(i2) []
         i3 = ptr_eq(NULL, p0)
-        guard_false(i1) []
+        guard_false(i3) []
         guard_nonnull(p0) []
         jump(p0)
         """