Commits

Hakan Ardo committed 6b229fd

rename boxes surviving the retraced preamble in a new position of the inputargs to allow us to replace the full preamble with the short preamble and only keep around the preamble of the initial trace

Comments (0)

Files changed (3)

pypy/jit/metainterp/compile.py

                               [ResOperation(rop.JUMP, original_target_token.exported_state.jump_args,
                                             None, descr=loop_jitcell_token)]
         try:
-            optimize_trace(metainterp_sd, preamble, jitdriver_sd.warmstate.enable_opts)
+            optimize_trace(metainterp_sd, preamble, jitdriver_sd.warmstate.enable_opts, retraced_preamble=True)
         except InvalidLoop:
             assert False
 

pypy/jit/metainterp/optimizeopt/__init__.py

 
     return optimizations, unroll
 
-def optimize_trace(metainterp_sd, loop, enable_opts, inline_short_preamble=True):
+def optimize_trace(metainterp_sd, loop, enable_opts, inline_short_preamble=True, retraced_preamble=False):
     """Optimize loop.operations to remove internal overheadish operations.
     """
 
                                                           loop.operations)
         optimizations, unroll = build_opt_chain(metainterp_sd, enable_opts)
         if unroll:
-            optimize_unroll(metainterp_sd, loop, optimizations, inline_short_preamble)
+            optimize_unroll(metainterp_sd, loop, optimizations, inline_short_preamble, retraced_preamble)
         else:
             optimizer = Optimizer(metainterp_sd, loop, optimizations)
             optimizer.propagate_all_forward()

pypy/jit/metainterp/optimizeopt/unroll.py

 
 # FIXME: Introduce some VirtualOptimizer super class instead
 
-def optimize_unroll(metainterp_sd, loop, optimizations, inline_short_preamble=True):
+def optimize_unroll(metainterp_sd, loop, optimizations, inline_short_preamble=True, retraced_preamble=False):
     opt = UnrollOptimizer(metainterp_sd, loop, optimizations)
     opt.inline_short_preamble = inline_short_preamble
+    opt.retraced_preamble = retraced_preamble
     opt.propagate_all_forward()
 
 class UnrollableOptimizer(Optimizer):
         self.optimizer.flush()
         KillHugeIntBounds(self.optimizer).apply()
 
+        if self.retraced_preamble:
+            self.rename_sruviving_boxes(start_label, stop_label)
         loop.operations = self.optimizer.get_newoperations()
         self.export_state(stop_label)
         loop.operations.append(stop_label)
 
+    def rename_sruviving_boxes(self, start, stop):
+        assert start.getdescr().targeting_jitcell_token is not stop.getdescr().targeting_jitcell_token
+        assert start.numargs() == stop.numargs()
+        start_args = {}
+        for a in start.getarglist():
+            start_args[a] = True
+        for i in range(start.numargs()):
+            arg = stop.getarg(i)
+            if arg is not start.getarg(i) and arg in start_args:
+                newarg = arg.clonebox()
+                op = ResOperation(rop.SAME_AS, [arg], newarg)
+                self.optimizer.send_extra_operation(op)
+                stop.setarg(i, newarg)
+
     def jump_to_start_label(self, start_label, stop_label):
         if not start_label or not stop_label:
             return False