Commits

Armin Rigo committed 6280268

Progress, by fighting the urge to fix seven things in the same branch.

  • Participants
  • Parent commits c2481d2
  • Branches remove-globals-in-jit

Comments (0)

Files changed (2)

File pypy/jit/backend/llgraph/runner.py

 
 
 class LLDeadFrame(object):
+    _TYPE = llmemory.GCREF
 
     def __init__(self, latest_descr, values,
                  last_exception=None, saved_data=None):
         return support.cast_result(descr.RESULT, result)
 
     def execute_call_assembler(self, descr, *args):
+        # XXX simplify the following a bit
+        #
         # pframe = CALL_ASSEMBLER(args..., descr=looptoken)
         # ==>
         #     pframe = CALL looptoken.loopaddr(*args)
-        #     JUMP_IF_NOT_CARRY @forward
-        #     pframe = CALL assembler_call_helper(pframe)
-        #     @forward:
-        #
-        # CARRY is set before most returns, and cleared only
-        # on FINISH with descr.fast_path_done.
+        #     JUMP_IF_FAST_PATH @fastpath
+        #     res = CALL assembler_call_helper(pframe)
+        #     jmp @done
+        #   @fastpath:
+        #     RESET_VABLE
+        #     res = GETFIELD(pframe, 'result')
+        #   @done:
         #
         call_op = self.lltrace.operations[self.current_index]
         guard_op = self.lltrace.operations[self.current_index + 1]
         assert guard_op.getopnum() == rop.GUARD_NOT_FORCED
         self.force_guard_op = guard_op
+        pframe = self.cpu._execute_token(descr, *args)
+        del self.force_guard_op
         #
-        pframe = self.cpu._execute_token(descr, *args)
-        if not pframe._fast_path_done:
-            jd = descr.outermost_jitdriver_sd
-            assembler_helper_ptr = jd.assembler_helper_adr.ptr  # fish
-            try:
-                result = assembler_helper_ptr(pframe)
-            except LLException, lle:
-                assert self.last_exception is None, "exception left behind"
-                self.last_exception = lle
-                return lltype.nullptr(llmemory.GCREF.TO)
-            assert result is pframe
+        jd = descr.outermost_jitdriver_sd
+        assert jd is not None, ("call_assembler(): the loop_token needs "
+                                "to have 'outermost_jitdriver_sd'")
+        if jd.index_of_virtualizable != -1:
+            vable = args[jd.index_of_virtualizable]
+        else:
+            vable = lltype.nullptr(llmemory.GCREF.TO)
         #
-        del self.force_guard_op
-        return pframe
+        # Emulate the fast path
+        def reset_vable(jd, vable):
+            if jd.index_of_virtualizable != -1:
+                fielddescr = jd.vable_token_descr
+                do_setfield_gc_int(vable, fielddescr.ofs, 0)
+        faildescr = self.cpu.get_latest_descr(pframe)
+        failindex = self.cpu.get_fail_descr_number(faildescr)
+        if failindex == self.cpu.done_with_this_frame_int_v:
+            reset_vable(jd, vable)
+            return self.cpu.get_latest_value_int(pframe, 0)
+        if failindex == self.cpu.done_with_this_frame_ref_v:
+            reset_vable(jd, vable)
+            return self.cpu.get_latest_value_ref(pframe, 0)
+        if failindex == self.cpu.done_with_this_frame_float_v:
+            reset_vable(jd, vable)
+            return self.cpu.get_latest_value_float(pframe, 0)
+        if failindex == self.cpu.done_with_this_frame_void_v:
+            reset_vable(jd, vable)
+            return None
+        #
+        assembler_helper_ptr = jd.assembler_helper_adr.ptr  # fish
+        try:
+            return assembler_helper_ptr(pframe, vable)
+        except LLException, lle:
+            assert _last_exception is None, "exception left behind"
+            _last_exception = lle
+            # fish op
+            xxxxxxxxxxxx
+            op = self.loop.operations[self.opindex]
+            if op.result is not None:
+                return 0
 
     def execute_same_as(self, _, x):
         return x

File pypy/jit/backend/test/runner_test.py

 
     def test_assembler_call(self):
         called = []
-        def assembler_helper(failindex, virtualizable):
-            xxxxxxxxxxxx
-            assert self.cpu.get_latest_value_int(0) == 97
-            called.append(failindex)
+        def assembler_helper(deadframe, virtualizable):
+            assert self.cpu.get_latest_value_int(deadframe, 0) == 97
+            called.append(self.cpu.get_latest_descr(deadframe))
             return 4 + 9
 
-        FUNCPTR = lltype.Ptr(lltype.FuncType([lltype.Signed, llmemory.GCREF],
+        FUNCPTR = lltype.Ptr(lltype.FuncType([llmemory.GCREF, llmemory.GCREF],
                                              lltype.Signed))
         class FakeJitDriverSD:
             index_of_virtualizable = -1
         loop = parse(ops)
         looptoken = JitCellToken()
         looptoken.outermost_jitdriver_sd = FakeJitDriverSD()
-        done_number = self.cpu.get_fail_descr_number(loop.operations[-1].getdescr())
+        finish_descr = loop.operations[-1].getdescr()
         self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
         ARGS = [lltype.Signed] * 10
         RES = lltype.Signed
         args = [i+1 for i in range(10)]
         deadframe = self.cpu.execute_token(othertoken, *args)
         assert self.cpu.get_latest_value_int(deadframe, 0) == 13
-        assert called == [done_number]
+        assert called == [finish_descr]
 
         # test the fast path, which should not call assembler_helper()
         del called[:]
-        self.cpu.done_with_this_frame_int_v = done_number
+        self.cpu.done_with_this_frame_int_v = self.cpu.get_fail_descr_number(
+            finish_descr)
         try:
             othertoken = JitCellToken()
             self.cpu.compile_loop(loop.inputargs, loop.operations, othertoken)
         if not self.cpu.supports_floats:
             py.test.skip("requires floats")
         called = []
-        def assembler_helper(failindex, virtualizable):
-            xxxxxxxxxxxxx
-            x = self.cpu.get_latest_value_float(0)
+        def assembler_helper(deadframe, virtualizable):
+            x = self.cpu.get_latest_value_float(deadframe, 0)
             assert longlong.getrealfloat(x) == 1.2 + 3.2
-            called.append(failindex)
-            return 13.5
+            called.append(self.cpu.get_latest_descr(deadframe))
+            return longlong.getfloatstorage(13.5)
 
-        FUNCPTR = lltype.Ptr(lltype.FuncType([lltype.Signed, llmemory.GCREF],
+        FUNCPTR = lltype.Ptr(lltype.FuncType([llmemory.GCREF, llmemory.GCREF],
                                              lltype.Float))
         class FakeJitDriverSD:
             index_of_virtualizable = -1
         f2 = float_add(f0, f1)
         finish(f2)'''
         loop = parse(ops)
-        done_number = self.cpu.get_fail_descr_number(loop.operations[-1].getdescr())
+        finish_descr = loop.operations[-1].getdescr()
         looptoken = JitCellToken()
         looptoken.outermost_jitdriver_sd = FakeJitDriverSD()
         self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
         deadframe = self.cpu.execute_token(othertoken, *args)
         x = self.cpu.get_latest_value_float(deadframe, 0)
         assert longlong.getrealfloat(x) == 13.5
-        assert called == [done_number]
+        assert called == [finish_descr]
 
         # test the fast path, which should not call assembler_helper()
         del called[:]
-        self.cpu.done_with_this_frame_float_v = done_number
+        self.cpu.done_with_this_frame_float_v = self.cpu.get_fail_descr_number(
+            finish_descr)
         try:
             othertoken = JitCellToken()
             self.cpu.compile_loop(loop.inputargs, loop.operations, othertoken)
         if not self.cpu.supports_floats:
             py.test.skip("requires floats")
         called = []
-        def assembler_helper(failindex, virtualizable):
-            xxxxxxxxxxxx
-            x = self.cpu.get_latest_value_float(0)
+        def assembler_helper(deadframe, virtualizable):
+            x = self.cpu.get_latest_value_float(deadframe, 0)
             assert longlong.getrealfloat(x) == 1.25 + 3.25
-            called.append(failindex)
-            return 13.5
+            called.append(self.cpu.get_latest_descr(deadframe))
+            return longlong.getfloatstorage(13.5)
 
-        FUNCPTR = lltype.Ptr(lltype.FuncType([lltype.Signed, llmemory.GCREF],
+        FUNCPTR = lltype.Ptr(lltype.FuncType([llmemory.GCREF, llmemory.GCREF],
                                              lltype.Float))
         class FakeJitDriverSD:
             index_of_virtualizable = -1
         looptoken = JitCellToken()
         looptoken.outermost_jitdriver_sd = FakeJitDriverSD()
         self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
-        done_number = self.cpu.get_fail_descr_number(loop.operations[-1].getdescr())
+        finish_descr = loop.operations[-1].getdescr()
         args = [longlong.getfloatstorage(1.25),
                 longlong.getfloatstorage(2.35)]
         deadframe = self.cpu.execute_token(looptoken, *args)
         deadframe = self.cpu.execute_token(othertoken, *args)
         x = self.cpu.get_latest_value_float(deadframe, 0)
         assert longlong.getrealfloat(x) == 13.5
-        assert called == [done_number]
+        assert called == [finish_descr]
         del called[:]
 
         # compile a replacement
         [f0, f1]
         f2 = float_sub(f0, f1)
         finish(f2)'''
-        loop = parse(ops)
+        loop2 = parse(ops)
         looptoken2 = JitCellToken()
         looptoken2.outermost_jitdriver_sd = FakeJitDriverSD()
-        self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken2)
-        done_number = self.cpu.get_fail_descr_number(loop.operations[-1].getdescr())
+        self.cpu.compile_loop(loop2.inputargs, loop2.operations, looptoken2)
+        finish_descr2 = loop2.operations[-1].getdescr()
 
         # install it
         self.cpu.redirect_call_assembler(looptoken, looptoken2)
         deadframe = self.cpu.execute_token(othertoken, *args)
         x = self.cpu.get_latest_value_float(deadframe, 0)
         assert longlong.getrealfloat(x) == 13.5
-        assert called == [done_number]
+        assert called == [finish_descr2]
 
     def test_short_result_of_getfield_direct(self):
         # Test that a getfield that returns a CHAR, SHORT or INT, signed