Commits

Antonio Cuni committed e41f063

implement forcing of the virtual raw memory

Comments (0)

Files changed (2)

pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py

         """
         self.optimize_loop(ops, expected)
 
+    def test_virtual_raw_malloc_force(self):
+        ops = """
+        [i1]
+        i2 = call('malloc', 10, descr=raw_malloc_descr)
+        setarrayitem_raw(i2, 0, i1, descr=rawarraydescr)
+        setarrayitem_raw(i2, 2, 456, descr=rawarraydescr)
+        setarrayitem_raw(i2, 1, 123, descr=rawarraydescr)
+        escape(i2)
+        call('free', i2, descr=raw_free_descr)
+        jump(i1)
+        """
+        expected = """
+        [i1]
+        i2 = call('malloc', 10, descr=raw_malloc_descr)
+        setarrayitem_raw(i2, 0, i1, descr=rawarraydescr)
+        i3 = int_add(i2, 8)
+        setarrayitem_raw(i3, 0, 123, descr=rawarraydescr)
+        i4 = int_add(i2, 16)
+        setarrayitem_raw(i4, 0, 456, descr=rawarraydescr)
+        escape(i2)
+        call('free', i2, descr=raw_free_descr)
+        jump(i1)
+        """
+        self.optimize_loop(ops, expected)
+
     def test_duplicate_getfield_1(self):
         ops = """
         [p1, p2]

pypy/jit/metainterp/optimizeopt/virtualize.py

         self.buffer = RawBuffer()
 
     def _really_force(self, optforce):
-        import pdb;pdb.set_trace()
+        op = self.source_op
+        assert op is not None
+        if not we_are_translated():
+            op.name = 'FORCE ' + self.source_op.name
+        optforce.emit_operation(self.source_op)
+        self.box = box = self.source_op.result
+        for i in range(len(self.buffer.offsets)):
+            # get a pointer to self.box+offset
+            offset = self.buffer.offsets[i]
+            if offset == 0:
+                arraybox = self.box
+            else:
+                arraybox = BoxInt()
+                op = ResOperation(rop.INT_ADD,
+                                  [self.box, ConstInt(offset)], arraybox)
+                optforce.emit_operation(op)
+            #
+            # write the value
+            descr = self.buffer.descrs[i]
+            itemvalue = self.buffer.values[i]
+            itembox = itemvalue.force_box(optforce)
+            op = ResOperation(rop.SETARRAYITEM_RAW,
+                              [arraybox, ConstInt(0), itembox], None,
+                              descr=descr)
+            optforce.emit_operation(op)
 
     def setitem_raw(self, offset, length, descr, value):
         try: