Commits

Maciej Fijalkowski committed 3d4afd8

(fijal, rguillebert) Deal with duplicates in inputframes

Comments (0)

Files changed (4)

rpython/jit/backend/llsupport/assembler.py

             coeff = 1
         else:
             coeff = 2
+        all = {}
         for i, frame in enumerate(inputframes):
             inputlocs = loc_positions[i]
             assert len(inputlocs) == len(frame)
             for j, item in enumerate(frame):
-                if item is None or isinstance(item, Const):
+                if item is None or isinstance(item, Const) or item in all:
                     continue
+                all[item] = None
                 pos = inputlocs[j]
                 if pos < GPR_REGS:
                     locs.append(self.cpu.gen_regs[pos])

rpython/jit/backend/llsupport/regalloc.py

         """
         locs = []
         base_ofs = self.assembler.cpu.get_baseofs_of_frame_field()
+
         for box in inputargs:
             assert isinstance(box, Box)
             loc = self.fm.get_new_loc(box)

rpython/jit/backend/resumebuilder.py

         self.virtuals = {}
         if inputlocs is not None:
             i = 0
+            all = {}
             for frame_pos, frame in enumerate(inputframes):
                 for pos_in_frame, box in enumerate(frame):
-                    if box is None:
+                    if box is None or isinstance(box, Const) or box in all:
                         loc_pos = -1
                     else:
                         loc_pos = inputlocs[i].get_jitframe_position()
                         i += 1
                         self.frontend_pos[box] = (ConstInt(frame_pos),
                                                   ConstInt(pos_in_frame))
-                    self.current_attachment[box] = loc_pos
+                        all[box] = None
+                    if box not in self.current_attachment:
+                        self.current_attachment[box] = loc_pos
 
     def process(self, op):
         if op.getopnum() == rop.RESUME_PUT:
 
 def flatten(inputframes):
     count = 0
+    all = {}
     for frame in inputframes:
         for x in frame:
-            if x is not None and not isinstance(x, Const):
+            if x is not None and not isinstance(x, Const) and x not in all:
                 count += 1
+                all[x] = None
     inputargs = [None] * count
     pos = 0
+    all = {}
     for frame in inputframes:
         for item in frame:
-            if item is not None and not isinstance(item, Const):
+            if (item is not None and not isinstance(item, Const) and
+                item not in all):
                 inputargs[pos] = item
+                all[item] = None
                 pos += 1
     return inputargs
 

rpython/jit/metainterp/resume2.py

         AbstractResumeReader.__init__(self)
 
     def store_int_box(self, res, pos, miframe, i, jitframe_pos):
-        if jitframe_pos == -1:
+        if jitframe_pos in self.cache:
+            box = self.cache[jitframe_pos]
+        elif jitframe_pos == -1:
             return
-        if jitframe_pos >= 0:
+        elif jitframe_pos >= 0:
             box = BoxInt(self.metainterp.cpu.get_int_value(self.deadframe,
                                                            jitframe_pos))
         elif jitframe_pos <= -2:
             box = self.consts[-jitframe_pos - 2]
         miframe.registers_i[i] = box
+        self.cache[jitframe_pos] = box
         res[-1][pos] = box
 
     def store_ref_box(self, res, pos, miframe, i, jitframe_pos):
-        if jitframe_pos == -1:
+        if jitframe_pos in self.cache:
+            box = self.cache[jitframe_pos]
+        elif jitframe_pos == -1:
             return
-        if jitframe_pos >= 0:
+        elif jitframe_pos >= 0:
             box = BoxPtr(self.metainterp.cpu.get_ref_value(self.deadframe,
                                                            jitframe_pos))
         elif jitframe_pos <= -2:
             box = self.consts[-jitframe_pos - 2]
         miframe.registers_r[i] = box
+        self.cache[jitframe_pos] = box
         res[-1][pos] = box
 
     def store_float_box(self, res, pos, miframe, i, jitframe_pos):
-        if jitframe_pos == -1:
+        if jitframe_pos in self.cache:
+            box = self.cache[jitframe_pos]
+        elif jitframe_pos == -1:
             return
-        if jitframe_pos >= 0:
+        elif jitframe_pos >= 0:
             box = BoxFloat(self.metainterp.cpu.get_float_value(self.deadframe,
                                                              jitframe_pos))
         elif jitframe_pos <= -2:
             box = self.consts[-jitframe_pos - 2]
         miframe.registers_f[i] = box
+        self.cache[jitframe_pos] = box
         res[-1][pos] = box
 
     def finish(self):
         res = []
+        self.cache = {}
         for frame in self.framestack:
             jitcode = frame.jitcode
             res.append([None] * jitcode.num_regs())
             for i in range(jitcode.num_regs_f()):
                 self.store_float_box(res, pos, miframe, i, frame.registers[pos])
                 pos += 1
+        self.cache = None
         return res, [f.registers for f in self.framestack]
             
 def rebuild_from_resumedata(metainterp, deadframe, faildescr):