Commits

Maciej Fijalkowski  committed 5ce191f

(fijal, rguillebert) support for the very basic resume_new

  • Participants
  • Parent commits 1e68499
  • Branches resume-refactor

Comments (0)

Files changed (4)

File rpython/jit/metainterp/optimizeopt/optimizer.py

                                                      ImmutableIntUnbounded, \
                                                      IntLowerBound, MININT, MAXINT
 from rpython.jit.metainterp.optimizeopt.util import make_dispatcher_method
+from rpython.jit.metainterp.optimizeopt.resumeopt import OptResumeBuilder
 from rpython.jit.metainterp.resoperation import rop, ResOperation, AbstractResOp
 from rpython.jit.metainterp.typesystem import llhelper
 from rpython.tool.pairtype import extendabletype
             self.call_pure_results = loop.call_pure_results
 
         self.set_optimizations(optimizations)
-        self.resume_stack = []
+        self.resumebuilder = OptResumeBuilder(self)
         self.setup()
 
     def set_optimizations(self, optimizations):
             o.force_at_end_of_preamble()
 
     def flush(self):
-        self.resume_flush()
+        self.resumebuilder.resume_flush()
         for o in self.optimizations:
             o.flush()
 
         self.metainterp_sd.profiler.count(jitprof.Counters.OPT_OPS)
         if op.is_guard():
             self.metainterp_sd.profiler.count(jitprof.Counters.OPT_GUARDS)
+            pendingfields = self.pendingfields
             self.pendingfields = None
             if self.replaces_guard and op in self.replaces_guard:
                 self.replace_op(self.replaces_guard[op], op)
                 del self.replaces_guard[op]
                 return
+            self.resumebuilder.guard_seen(op, pendingfields)
         elif op.can_raise():
             self.exception_might_have_happened = True
         if op.result:
     # pending refactor
 
     def optimize_ENTER_FRAME(self, op):
-        self.resume_stack.append(op)
+        self.resumebuilder.enter_frame(op.getarg(0).getint(), op.getdescr())
+        self.optimize_default(op)
 
     def optimize_LEAVE_FRAME(self, op):
-        if self.resume_stack:
-            self.resume_stack.pop()
-        else:
-            self.emit_operation(op)
-
-    def optimize_RESUME_PUT(self, op):
-        self.resume_flush()
+        self.resumebuilder.leave_frame(op)
         self.optimize_default(op)
 
-    def resume_flush(self):
-        for op in self.resume_stack:
-            self.emit_operation(op)
-        self.resume_stack = []
-
 dispatch_opt = make_dispatcher_method(Optimizer, 'optimize_',
         default=Optimizer.optimize_default)
 

File rpython/jit/metainterp/optimizeopt/resumeopt.py

+
+from rpython.jit.metainterp.history import ConstInt, BoxPtr
+from rpython.jit.metainterp.resoperation import rop, ResOperation
+from rpython.jit.codewriter.jitcode import JitCode
+
+class ResumeFrame(object):
+    def __init__(self, pc, jitcode):
+        self.pc = pc
+        assert isinstance(jitcode, JitCode)
+        self.jitcode = jitcode
+        self.boxes = [None] * jitcode.num_regs()
+
+class OptResumeBuilder(object):
+    def __init__(self, opt):
+        self.framestack = []
+        self.last_flushed_pos = 0
+        self.opt = opt
+        self.virtuals = {}
+
+    def enter_frame(self, pc, jitcode):
+        self.framestack.append(ResumeFrame(pc, jitcode))
+
+    def leave_frame(self, op):
+        #if self.last_flushed_pos < len(self.framestack) - 1:
+        #    self.emit_missing_enter_frame()
+        #else:
+        #    self.opt.emit_operation(op)
+        #    self.last_flushed_pos -= 1
+        self.framestack.pop()
+
+    def resume_flush(self):
+        return
+        for i in range(self.last_flushed_pos, len(self.framestack)):
+            frame = self.framestack[i]
+            resop = ResOperation(rop.ENTER_FRAME, [ConstInt(frame.pc)],
+                                 None, descr=frame.jitcode)
+            self.opt.emit_operation(resop)
+        self.last_flushed_pos = len(self.framestack)
+
+    def resume_put(self, op):
+        self.resume_flush()
+        box = op.getarg(0)
+        value = self.opt.getvalue(box)
+        if value.is_virtual():
+            op = ResOperation(rop.RESUME_PUT, [value.resume_box,
+                                               op.getarg(1),
+                                               op.getarg(2)], None)
+            self.opt._newoperations.append(op)
+        else:
+            self.opt.emit_operation(op)
+        #no = op.getarg(2).getint()
+        #box = self.opt.getvalue(op.getarg(0)).box
+        #self.framestack[op.getarg(1).getint()].boxes[no] = box
+
+    def new_virtual(self, box):
+        xxx
+        self.optimizer.emit_operation(rop.RESUME_NEW)
+
+    def new_virtual_struct(self, box, vstruct, structdescr):
+        newbox = BoxPtr()
+        vstruct.resume_box = newbox
+        op = ResOperation(rop.RESUME_NEW, [], newbox, descr=structdescr)
+        self.opt._newoperations.append(op)
+
+    def guard_seen(self, op, pendingfields):
+        #xxx
+        pass

File rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py

         """
         self.optimize_loop(ops, expected)
 
+    def test_virtual_resume_info(self):
+        ops = """
+        [i0]
+        enter_frame(-1, descr=jitcode)
+        p0 = new(descr=ssize)
+        resume_put(p0, 0, 0)
+        guard_true(i0)
+        leave_frame()
+        finish()
+        """
+        expected = """
+        [i0]
+        enter_frame(-1, descr=jitcode)
+        p0 = resume_new(descr=ssize)
+        resume_put(p0, 0, 0)
+        guard_true(i0)
+        leave_frame()
+        finish()
+        """
+        self.optimize_loop(ops, expected)
+
     def test_ooisnull_oononnull_via_virtual(self):
         ops = """
         [p0]

File rpython/jit/metainterp/optimizeopt/virtualize.py

 
 
 class AbstractVirtualValue(optimizer.OptValue):
-    _attrs_ = ('keybox', 'source_op', '_cached_vinfo')
+    _attrs_ = ('keybox', 'source_op', '_cached_vinfo', 'resume_box')
     box = None
     level = optimizer.LEVEL_NONNULL
     is_about_raw = False
 
     def make_virtual(self, known_class, box, source_op=None):
         vvalue = VirtualValue(self.optimizer.cpu, known_class, box, source_op)
+        self.optimizer.resumebuilder.new_virtual(box)
         self.make_equal_to(box, vvalue)
         return vvalue
 
 
     def make_vstruct(self, structdescr, box, source_op=None):
         vvalue = VStructValue(self.optimizer.cpu, structdescr, box, source_op)
+        self.optimizer.resumebuilder.new_virtual_struct(box, vvalue,
+                                                        structdescr)
         self.make_equal_to(box, vvalue)
         return vvalue
 
         value.ensure_nonnull()
         self.emit_operation(op)
 
+    def optimize_RESUME_PUT(self, op):
+        self.optimizer.resumebuilder.resume_put(op)
+
 
 dispatch_opt = make_dispatcher_method(OptVirtualize, 'optimize_',
         default=OptVirtualize.emit_operation)