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)


                               [ResOperation(rop.JUMP, original_target_token.exported_state.jump_args,
                                             None, descr=loop_jitcell_token)]
-            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


     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.
         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)
             optimizer = Optimizer(metainterp_sd, loop, optimizations)


 # 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
 class UnrollableOptimizer(Optimizer):
+        if self.retraced_preamble:
+            self.rename_sruviving_boxes(start_label, stop_label)
         loop.operations = self.optimizer.get_newoperations()
+    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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.