[pypy-svn] r69727 - in pypy/branch/virtual-forcing/pypy/jit: backend/llgraph metainterp metainterp/test

arigo at codespeak.net arigo at codespeak.net
Sun Nov 29 12:28:47 CET 2009


Author: arigo
Date: Sun Nov 29 12:28:46 2009
New Revision: 69727

Modified:
   pypy/branch/virtual-forcing/pypy/jit/backend/llgraph/llimpl.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/compile.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_virtualizable.py
Log:
Minor fixes with a new test:

- prevent GUARD_NOT_FORCED from ever being compiled.

- in the llgraph backend, make sure that frame.loop is kept
  up-to-date by the JUMP operation!  :-(


Modified: pypy/branch/virtual-forcing/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/backend/llgraph/llimpl.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/backend/llgraph/llimpl.py	Sun Nov 29 12:28:46 2009
@@ -466,7 +466,8 @@
             if op.opnum == rop.JUMP:
                 assert len(op.jump_target.inputargs) == len(args)
                 self.env = dict(zip(op.jump_target.inputargs, args))
-                operations = op.jump_target.operations
+                self.loop = op.jump_target
+                operations = self.loop.operations
                 opindex = 0
                 _stats.exec_jumps += 1
             elif op.opnum == rop.FINISH:
@@ -497,7 +498,7 @@
         try:
             res = ophandler(self, descr, *values)
         finally:
-            if verbose:
+            if 0:     # if verbose:
                 argtypes, restype = TYPES[opname]
                 if res is None:
                     resdata = ''
@@ -506,9 +507,9 @@
                 else:
                     resdata = '-> ' + repr1(res, restype, self.memocast)
                 # fish the types
-                #log.cpu('\t%s %s %s' % (opname, repr_list(values, argtypes,
-                #                                          self.memocast),
-                #                        resdata))
+                log.cpu('\t%s %s %s' % (opname, repr_list(values, argtypes,
+                                                          self.memocast),
+                                        resdata))
         return res
 
     def as_int(self, x):
@@ -796,7 +797,10 @@
     def op_call_may_force(self, calldescr, func, *args):
         assert not self._forced
         self._may_force = self.opindex
-        return self.op_call(calldescr, func, *args)
+        try:
+            return self.op_call(calldescr, func, *args)
+        finally:
+            self._may_force = -1
 
     def op_guard_not_forced(self, descr):
         forced = self._forced
@@ -1077,6 +1081,7 @@
     assert frame._may_force >= 0
     call_op = frame.loop.operations[frame._may_force]
     guard_op = frame.loop.operations[frame._may_force+1]
+    assert call_op.opnum == rop.CALL_MAY_FORCE
     frame._populate_fail_args(guard_op, skip=call_op.result)
     return frame.fail_index
 

Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/compile.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/compile.py	Sun Nov 29 12:28:46 2009
@@ -245,6 +245,7 @@
         metainterp = MetaInterp(metainterp_sd)
         token = metainterp_sd.cpu.get_latest_force_token()
         metainterp._already_allocated_resume_virtuals = self.fetch_data(token)
+        self.counter = -2     # never compile
         return metainterp.handle_guard_failure(self)
 
     def force_virtualizable(self, vinfo, virtualizable, force_token):

Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/pyjitpl.py	Sun Nov 29 12:28:46 2009
@@ -925,7 +925,6 @@
         if isinstance(box, Const):    # no need for a guard
             return
         metainterp = self.metainterp
-        metainterp_sd = metainterp.staticdata
         if metainterp.is_blackholing():
             return
         saved_pc = self.pc
@@ -934,6 +933,7 @@
             moreargs = [box] + extraargs
         else:
             moreargs = list(extraargs)
+        metainterp_sd = metainterp.staticdata
         original_greenkey = metainterp.resumekey.original_greenkey
         if opnum == rop.GUARD_NOT_FORCED:
             resumedescr = compile.ResumeGuardForcedDescr(metainterp_sd,

Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_virtualizable.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_virtualizable.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_virtualizable.py	Sun Nov 29 12:28:46 2009
@@ -736,6 +736,42 @@
         res = self.meta_interp(f, [123], policy=StopAtXPolicy(g))
         assert res == f(123)
 
+    def test_external_read_sometimes_dont_compile_guard(self):
+        jitdriver = JitDriver(greens = [], reds = ['frame'],
+                              virtualizables = ['frame'])
+        
+        class Frame(object):
+            _virtualizable2_ = ['x', 'y']
+        class SomewhereElse:
+            pass
+        somewhere_else = SomewhereElse()
+
+        def g():
+            somewhere_else.counter += 1
+            if somewhere_else.counter == 70:
+                result = somewhere_else.top_frame.y     # external read
+                debug_print(lltype.Void, '-+-+-+-+- external read:', result)
+                assert result == 79
+            else:
+                result = 1
+            return result
+
+        def f(n):
+            frame = Frame()
+            frame.x = n
+            frame.y = 10
+            somewhere_else.counter = 0
+            somewhere_else.top_frame = frame
+            while frame.x > 0:
+                jitdriver.can_enter_jit(frame=frame)
+                jitdriver.jit_merge_point(frame=frame)
+                frame.x -= g()
+                frame.y += 1
+            return frame.x
+
+        res = self.meta_interp(f, [123], policy=StopAtXPolicy(g), repeat=7)
+        assert res == f(123)
+
     def test_promote_index_in_virtualizable_list(self):
         jitdriver = JitDriver(greens = [], reds = ['frame', 'n'],
                               virtualizables = ['frame'])



More information about the Pypy-commit mailing list