Commits

Maciej Fijalkowski committed 47e28c4

(fijal, rguillebert) few fixes to pass test_loop

Comments (0)

Files changed (3)

rpython/jit/metainterp/history.py

         self.inputlocs = None
         self.operations = []
 
+    def any_operation(self):
+        for op in self.operations:
+            if not op.is_resume():
+                return True
+        return False
+
     def record(self, opnum, argboxes, resbox, descr=None):
         op = ResOperation(opnum, argboxes, resbox, descr)
         self.operations.append(op)

rpython/jit/metainterp/pyjitpl.py

             elif box.type == history.FLOAT: self.registers_f[index] = box
             else: raise AssertionError(box.type)
 
-    def get_current_position_info(self):
+    def get_current_position_info(self, resumepc=-1):
+        if resumepc != -1:
+            return self.jitcode.get_live_vars_info(resumepc)
         return self.jitcode.get_live_vars_info(self.pc)
 
     def replace_active_box_in_frame(self, oldbox, newbox):
     @arguments("int", "boxes3", "jitcode_position", "boxes3", "orgpc")
     def opimpl_jit_merge_point(self, jdindex, greenboxes,
                                jcposition, redboxes, orgpc):
-        any_operation = len(self.metainterp.history.operations) > 0
+        any_operation = self.metainterp.history.any_operation()
         jitdriver_sd = self.metainterp.staticdata.jitdrivers_sd[jdindex]
         self.verify_green_args(jitdriver_sd, greenboxes)
         self.debug_merge_point(jitdriver_sd, jdindex,
         self.retracing_from = -1
         self.call_pure_results = args_dict_box()
         self.heapcache = HeapCache()
-        self.resumerecorder = ResumeRecorder(self)
 
         self.call_ids = []
         self.current_call_id = 0
                 duplicates[box] = None
 
     def reached_loop_header(self, greenboxes, redboxes, resumedescr):
+        self.resumerecorder.leave_frame()
         self.heapcache.reset()
 
         duplicates = {}
         # Otherwise, no loop found so far, so continue tracing.
         start = len(self.history.operations)
         self.current_merge_points.append((live_arg_boxes, start))
+        self.resumerecorder.enter_frame(-1, self.jitdriver_sd.mainjitcode)
 
     def _unpack_boxes(self, boxes, start, stop):
         ints = []; refs = []; floats = []
         # ----- make a new frame -----
         self.portal_call_depth = -1 # always one portal around
         self.framestack = []
+        self.resumerecorder = ResumeRecorder(self, False)
         f = self.newframe(self.jitdriver_sd.mainjitcode)
         f.setup_call(original_boxes)
         assert self.portal_call_depth == 0
             self.history = history.History()
             state = self.rebuild_state_after_failure(resumedescr, deadframe)
             self.history.inputframes, self.history.inputlocs = state
+            self.resumerecorder = ResumeRecorder(self, True)
         finally:
             rstack._stack_criticalcode_stop()
 

rpython/jit/metainterp/resume2.py

 class ResumeRecorder(object):
     """ Created by metainterp to record the resume as we record operations
     """
-    def __init__(self, metainterp):
+    def __init__(self, metainterp, is_bridge=False):
         self.metainterp = metainterp
         self.cachestack = []
+        if is_bridge:
+            for frame in metainterp.framestack:
+                self.cachestack.append([None] * frame.jitcode.num_regs())
 
     def enter_frame(self, pc, jitcode):
         self.metainterp.history.record(rop.ENTER_FRAME, [ConstInt(pc)], None,
     def resume_point(self, resumedescr, resumepc):
         framestack = self.metainterp.framestack
         for i, frame in enumerate(framestack):
-            self._emit_resume_data(resumepc, frame, i, not i == len(framestack))
+            in_a_call = not i == len(framestack) - 1
+            self._emit_resume_data(resumepc, frame, i, in_a_call)
 
     def process_box(self, index_in_frontend, frame_pos, box):
         cache = self.cachestack[frame_pos]
             elif argcode == 'f': frame.registers_f[index] = history.CONST_FZERO
             frame._result_argcode = '?'     # done
         #
-        info = frame.get_current_position_info()
+        if not in_a_call and resume_pc != -1:
+            info = frame.get_current_position_info(resume_pc)
+        else:
+            info = frame.get_current_position_info()
         start_i = 0
-        start_r = start_i + info.get_register_count_i()
-        start_f = start_r + info.get_register_count_r()
+        start_r = start_i + frame.jitcode.num_regs_i()
+        start_f = start_r + frame.jitcode.num_regs_r()
         # fill it now
         for i in range(info.get_register_count_i()):
             index = info.get_register_index_i(i)
         for i in range(info.get_register_count_r()):
             index = info.get_register_index_r(i)
             self.process_box(index + start_r, frame_pos,
-                             frame.registers_i[index])
+                             frame.registers_r[index])
         for i in range(info.get_register_count_f()):
             index = info.get_register_index_f(i)
             self.process_box(index + start_f, frame_pos,
-                             frame.registers_i[index])
+                             frame.registers_f[index])
 
         mi_history = self.metainterp.history
         cache = self.cachestack[frame_pos]