Commits

Hakan Ardo committed 04e607c

Pass the parent resume_at_jump_descr among the exported_state to allow target_token.resume_at_jump_descr to always be the inlined version beloning the produced short preamble. Produce the short_inputargs during the state import. This allows repeated imports of the state without obscure hacks.

  • Participants
  • Parent commits 32a9f53
  • Branches jit-usable_retrace_3

Comments (0)

Files changed (2)

pypy/jit/metainterp/compile.py

             if descr.original_jitcell_token is not original_jitcell_token:
                 assert descr.original_jitcell_token is not None
                 original_jitcell_token.record_jump_to(descr.original_jitcell_token)
-            # exported_state is clear by optimizeopt when the short preamble is
-            # constrcucted. if that did not happen the label should not show up
-            # in a trace that will be used
-            assert descr.exported_state is None 
+            descr.exported_state = None 
             if not we_are_translated():
                 op._descr_wref = weakref.ref(op._descr)
             op.cleardescr()    # clear reference to prevent the history.Stats
     orignial_label = partial_trace.operations[-1].clone()
     original_target_token = orignial_label.getdescr()
     assert isinstance(original_target_token, TargetToken)
-    original_short_preamble = original_target_token.short_preamble
-    original_target_token.short_preamble = None
 
     h_ops = history.operations
 
                 preamble.operations.append(ResOperation(rop.SAME_AS, [a1], a2))
 
     except InvalidLoop:
-        original_target_token.short_preamble = original_short_preamble
         preamble.operations = [orignial_label] + \
                               [ResOperation(rop.JUMP, inputargs[:],
                                             None, descr=loop_jitcell_token)]

pypy/jit/metainterp/optimizeopt/unroll.py

             
         values = [self.getvalue(arg) for arg in jump_args]
         inputargs = virtual_state.make_inputargs(values, self.optimizer)
-        short_inputargs = virtual_state.make_inputargs(values, self.optimizer, keyboxes=True)
-
 
         if self.boxes_created_this_iteration is not None:
             for box in self.inputargs:
         assert isinstance(target_token, TargetToken)
         targetop.initarglist(inputargs)
         target_token.virtual_state = virtual_state
-        target_token.short_preamble = [ResOperation(rop.LABEL, short_inputargs, None)]
-        target_token.resume_at_jump_descr = resume_at_jump_descr
 
         exported_values = {}
         for box in inputargs:
                 exported_values[box] = self.optimizer.getvalue(box)
             
         target_token.exported_state = ExportedState(short_boxes, inputarg_setup_ops,
-                                                    exported_values, jump_args)
+                                                    exported_values, jump_args, resume_at_jump_descr)
 
     def import_state(self, targetop):
         if not targetop: # Trace did not start with a label
             self.initial_virtual_state = virtual_state
             return
         
-        if target_token.short_preamble:
-            self.short = target_token.short_preamble[:]
-        else:
-            self.short = None
         self.short_seen = {}
         self.short_boxes = exported_state.short_boxes
-        self.short_resume_at_jump_descr = target_token.resume_at_jump_descr
+        self.short_resume_at_jump_descr = exported_state.resume_at_jump_descr
         self.initial_virtual_state = target_token.virtual_state
 
         seen = {}
         self.optimizer.flush()
         self.optimizer.emitting_dissabled = False
 
+        values = [self.getvalue(a) for a in exported_state.jump_args]
+        short_inputargs = self.initial_virtual_state.make_inputargs(values, self.optimizer, keyboxes=True)
+        self.short = [ResOperation(rop.LABEL, short_inputargs, None)]
+
         if exported_state.generalize_virtual_state:
             # XXX: Hack
             # FIXME: Rearange stuff to emit label after this (but prior to inputarg_setup_ops)?
             if op.is_guard():
                 op = op.clone()
                 op.setfailargs(None)
-                descr = target_token.resume_at_jump_descr.clone_if_mutable()
+                descr = self.short_resume_at_jump_descr.clone_if_mutable()
                 op.setdescr(descr)
                 short[i] = op
 
             if op.result and op.result in self.short_boxes.assumed_classes:
                 target_token.assumed_classes[newop.result] = self.short_boxes.assumed_classes[op.result]
             short[i] = newop
-        target_token.resume_at_jump_descr = target_token.resume_at_jump_descr.clone_if_mutable()
+        target_token.resume_at_jump_descr = self.short_resume_at_jump_descr.clone_if_mutable()
         inliner.inline_descr_inplace(target_token.resume_at_jump_descr)
 
         # Forget the values to allow them to be freed
             if op.result:
                 op.result.forget_value()
         target_token.short_preamble = self.short
-        target_token.exported_state = None
 
     def ensure_short_op_emitted(self, op, optimizer, seen):
         if op is None:
         self.unroll.add_op_to_short(self.op, False, True)        
 
 class ExportedState(object):
-    def __init__(self, short_boxes, inputarg_setup_ops, exported_values, jump_args):
+    def __init__(self, short_boxes, inputarg_setup_ops, exported_values, jump_args, resume_at_jump_descr):
         self.short_boxes = short_boxes
         self.inputarg_setup_ops = inputarg_setup_ops
         self.exported_values = exported_values
         self.jump_args = jump_args
         self.generalize_virtual_state = None
+        self.resume_at_jump_descr = resume_at_jump_descr