[pypy-svn] r62657 - in pypy/branch/pyjitpl5/pypy/jit/backend/x86: . test

fijal at codespeak.net fijal at codespeak.net
Fri Mar 6 18:08:13 CET 2009


Author: fijal
Date: Fri Mar  6 18:08:12 2009
New Revision: 62657

Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/regalloc.py
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_runner.py
Log:
a bit of progress. remove again RETURN, in favor of a failing guard. should
more or less work by now, but do_call explodes


Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py	Fri Mar  6 18:08:12 2009
@@ -7,8 +7,7 @@
 from pypy.annotation import model as annmodel
 from pypy.tool.uid import fixid
 from pypy.jit.backend.x86.regalloc import (RegAlloc, FRAMESIZE, WORD, REGS,
-                                      arg_pos, lower_byte, stack_pos, Perform,
-                                      RETURN)
+                                      arg_pos, lower_byte, stack_pos, Perform)
 from pypy.rlib.objectmodel import we_are_translated, specialize
 from pypy.jit.backend.x86 import codebuf
 from pypy.jit.backend.x86.support import gc_malloc_fnaddr
@@ -419,7 +418,7 @@
 
     genop_catch = genop_merge_point
 
-    def genop_return(self, op, locs):
+    def xxx_genop_return(self, op, locs):
         if op.args:
             loc = locs[0]
             if loc is not eax:
@@ -530,17 +529,14 @@
     #    self.gen_call(op, arglocs, resloc)
     #    self.mc.MOVZX(eax, eax)
 
-genop_discard_list = [None] * (RETURN + 1)
-genop_list = [None] * (RETURN + 1)
-genop_guard_list = [None] * (RETURN + 1)
+genop_discard_list = [None] * rop._LAST
+genop_list = [None] * rop._LAST
+genop_guard_list = [None] * rop._LAST
 
 for name, value in Assembler386.__dict__.iteritems():
     if name.startswith('genop_'):
         opname = name[len('genop_'):]
-        if opname == 'return':
-            num = RETURN
-        else:
-            num = getattr(rop, opname.upper())
+        num = getattr(rop, opname.upper())
         if value.func_code.co_argcount == 3:
             genop_discard_list[num] = value
         elif value.func_code.co_argcount == 5:

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/regalloc.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/regalloc.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/regalloc.py	Fri Mar  6 18:08:12 2009
@@ -17,8 +17,6 @@
 WORD = 4
 FRAMESIZE = 1024    # XXX should not be a constant at all!!
 
-RETURN = rop._LAST + 1
-
 class TempBox(Box):
     def __init__(self):
         pass
@@ -580,7 +578,7 @@
         self.eventually_free_vars(op.liveboxes + op.args)
         return ops + [PerformDiscard(op, [x, y] + locs)]
 
-    def consider_return(self, op, ignored):
+    def xxx_consider_return(self, op, ignored):
         if op.args:
             arglocs = [self.loc(op.args[0])]
             self.eventually_free_var(op.args[0])
@@ -951,15 +949,12 @@
         self.eventually_free_vars(op.args)
         return ops + laterops + [PerformDiscard(op, [])]
 
-oplist = [None] * (RETURN + 1)
+oplist = [None] * rop._LAST
 
 for name, value in RegAlloc.__dict__.iteritems():
     if name.startswith('consider_'):
         name = name[len('consider_'):]
-        if name == 'return':
-            num = RETURN
-        else:
-            num = getattr(rop, name.upper())
+        num = getattr(rop, name.upper())
         oplist[num] = value
 
 def arg_pos(i):

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py	Fri Mar  6 18:08:12 2009
@@ -11,7 +11,7 @@
 from pypy.jit.metainterp import history
 from pypy.jit.metainterp.history import (ResOperation, Box, Const,
      ConstInt, ConstPtr, BoxInt, BoxPtr, ConstAddr)
-from pypy.jit.backend.x86.assembler import Assembler386, WORD, RETURN
+from pypy.jit.backend.x86.assembler import Assembler386, WORD
 from pypy.jit.backend.x86 import symbolic
 from pypy.jit.metainterp.resoperation import rop, opname
 from pypy.jit.backend.x86.executor import execute
@@ -29,6 +29,7 @@
     BOOTSTRAP_TP = lltype.FuncType([lltype.Signed,
                                     lltype.Ptr(rffi.CArray(lltype.Signed))],
                                    lltype.Signed)
+
     return_value_box = None
 
     def __init__(self, rtyper, stats, translate_support_code=False,
@@ -148,81 +149,81 @@
     def get_exc_value(self, frame):
         return self.cast_int_to_gcref(self.assembler._exception_data[1])
 
-    def execute_operation(self, opnum, valueboxes, result_type):
-        xxx
-        if execute[opnum] is not None:
-            return execute[opnum](valueboxes)
+#     def execute_operation(self, opnum, valueboxes, result_type):
+#         xxx
+#         if execute[opnum] is not None:
+#             return execute[opnum](valueboxes)
         
-        # mostly a hack: fall back to compiling and executing the single
-        # operation.
-        key = []
-        for valuebox in valueboxes:
-            if isinstance(valuebox, Box):
-                key.append(valuebox.type)
-            else:
-                key.append(str(valuebox.get_()))
-        mp = self.get_compiled_single_operation(opnum, result_type,
-                                                key, valueboxes)
-        res = self.execute_operations_in_new_frame(opname[opnum], mp,
-                                                   valueboxes,
-                                                   result_type)
-        if not self.translate_support_code:
-            if self.assembler._exception_data[0] != 0:
-                TP = lltype.Ptr(rclass.OBJECT_VTABLE)
-                TP_V = lltype.Ptr(rclass.OBJECT)
-                exc_t_a = self.cast_int_to_adr(self.get_exception(None))
-                exc_type = llmemory.cast_adr_to_ptr(exc_t_a, TP)
-                exc_v_a = self.get_exc_value(None)
-                exc_val = lltype.cast_opaque_ptr(TP_V, exc_v_a)
-                # clean up the exception
-                self.assembler._exception_data[0] = 0
-                raise LLException(exc_type, exc_val)
-        # otherwise exception data is set correctly, no problem at all
-        return res
-
-    def get_compiled_single_operation(self, opnum, result_type, key,
-                                      valueboxes):
-        xxx
-        real_key = '%d,%s' % (opnum, result_type) + ','.join(key)
-        try:
-            return self._compiled_ops[real_key]
-        except KeyError:
-            livevarlist = []
-            i = 0
-            # clonebox below is necessary, because sometimes we know
-            # that the value is constant (ie ArrayDescr), but we're not
-            # going to get the contant. So instead we get a box with correct
-            # value
-            for box in valueboxes:
-                if box.type == 'int':
-                    box = valueboxes[i].clonebox()
-                elif box.type == 'ptr':
-                    box = valueboxes[i].clonebox()
-                else:
-                    raise ValueError(type)
-                livevarlist.append(box)
-                i += 1
-            mp = ResOperation(rop.MERGE_POINT, livevarlist, None)
-            if result_type == 'void':
-                result = None
-            elif result_type == 'int':
-                result = history.BoxInt()
-            elif result_type == 'ptr':
-                result = history.BoxPtr()
-            else:
-                raise ValueError(result_type)
-            if result is None:
-                results = []
-            else:
-                results = [result]
-            operations = [mp,
-                          ResOperation(opnum, livevarlist, result),
-                          ResOperation(rop.RETURN, results, None)]
-            if operations[1].is_guard():
-                operations[1].liveboxes = []
-            self.compile_operations(operations, verbose=False)
-            self._compiled_ops[real_key] = mp
-            return mp
+#         # mostly a hack: fall back to compiling and executing the single
+#         # operation.
+#         key = []
+#         for valuebox in valueboxes:
+#             if isinstance(valuebox, Box):
+#                 key.append(valuebox.type)
+#             else:
+#                 key.append(str(valuebox.get_()))
+#         mp = self.get_compiled_single_operation(opnum, result_type,
+#                                                 key, valueboxes)
+#         res = self.execute_operations_in_new_frame(opname[opnum], mp,
+#                                                    valueboxes,
+#                                                    result_type)
+#         if not self.translate_support_code:
+#             if self.assembler._exception_data[0] != 0:
+#                 TP = lltype.Ptr(rclass.OBJECT_VTABLE)
+#                 TP_V = lltype.Ptr(rclass.OBJECT)
+#                 exc_t_a = self.cast_int_to_adr(self.get_exception(None))
+#                 exc_type = llmemory.cast_adr_to_ptr(exc_t_a, TP)
+#                 exc_v_a = self.get_exc_value(None)
+#                 exc_val = lltype.cast_opaque_ptr(TP_V, exc_v_a)
+#                 # clean up the exception
+#                 self.assembler._exception_data[0] = 0
+#                 raise LLException(exc_type, exc_val)
+#         # otherwise exception data is set correctly, no problem at all
+#         return res
+
+#     def get_compiled_single_operation(self, opnum, result_type, key,
+#                                       valueboxes):
+#         xxx
+#         real_key = '%d,%s' % (opnum, result_type) + ','.join(key)
+#         try:
+#             return self._compiled_ops[real_key]
+#         except KeyError:
+#             livevarlist = []
+#             i = 0
+#             # clonebox below is necessary, because sometimes we know
+#             # that the value is constant (ie ArrayDescr), but we're not
+#             # going to get the contant. So instead we get a box with correct
+#             # value
+#             for box in valueboxes:
+#                 if box.type == 'int':
+#                     box = valueboxes[i].clonebox()
+#                 elif box.type == 'ptr':
+#                     box = valueboxes[i].clonebox()
+#                 else:
+#                     raise ValueError(type)
+#                 livevarlist.append(box)
+#                 i += 1
+#             mp = ResOperation(rop.MERGE_POINT, livevarlist, None)
+#             if result_type == 'void':
+#                 result = None
+#             elif result_type == 'int':
+#                 result = history.BoxInt()
+#             elif result_type == 'ptr':
+#                 result = history.BoxPtr()
+#             else:
+#                 raise ValueError(result_type)
+#             if result is None:
+#                 results = []
+#             else:
+#                 results = [result]
+#             operations = [mp,
+#                           ResOperation(opnum, livevarlist, result),
+#                           ResOperation(rop.RETURN, results, None)]
+#             if operations[1].is_guard():
+#                 operations[1].liveboxes = []
+#             self.compile_operations(operations, verbose=False)
+#             self._compiled_ops[real_key] = mp
+#             return mp
 
     def compile_operations(self, operations, guard_op=None, verbose=True):
         self.assembler.assemble(operations, guard_op, verbose=verbose)
@@ -258,9 +259,9 @@
             raise ValueError('get_box_value_as_int, wrong arg')
 
     def get_valuebox_from_int(self, type, x):
-        if type == 'int':
+        if type == INT:
             return history.BoxInt(x)
-        elif type == 'ptr':
+        elif type == PTR:
             return history.BoxPtr(self.cast_int_to_gcref(x))
         else:
             raise ValueError('get_valuebox_from_int: %s' % (type,))
@@ -271,12 +272,13 @@
         actual = self.generated_mps[argnum]
         if actual is not None:
             return actual
-        args = [BoxInt(0) for i in range(argnum + 1)]
+        args = [BoxInt(0) for i in range(argnum + 3)]
         result = BoxInt(0)
         operations = [
             ResOperation(rop.MERGE_POINT, args, None),
-            ResOperation(rop.CALL, args, result),
-            ResOperation(RETURN, [result], None)]
+            ResOperation(rop.CALL, args[:-1], result),
+            ResOperation(rop.GUARD_FALSE, [args[-1]], None)]
+        operations[-1].liveboxes = [result]
         self.compile_operations(operations)
         self.generated_mps[argnum] = operations
         return operations
@@ -303,7 +305,6 @@
         if self.return_value_box is None:
             if self.debug:
                 llop.debug_print(lltype.Void, " => void result")
-            res = None
         else:
             if self.debug:
                 llop.debug_print(lltype.Void, " => ", res)
@@ -547,7 +548,7 @@
         calldescr = args[1].getint()
         num_args, tp = self.unpack_calldescr(calldescr)
         mp = self._get_mp_for_call(num_args)
-        self.execute_operations_in_new_frame('call', mp, args)
+        return self.execute_operations_in_new_frame('call', mp, args + [BoxInt(1)])
 
     # ------------------- helpers and descriptions --------------------
 

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_runner.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_runner.py	Fri Mar  6 18:08:12 2009
@@ -4,7 +4,7 @@
 from pypy.jit.metainterp.history import (BoxInt, BoxPtr, ConstInt, ConstPtr,
                                          Box)
 from pypy.jit.backend.x86.runner import CPU, GuardFailed
-from pypy.jit.backend.x86.regalloc import WORD, RETURN
+from pypy.jit.backend.x86.regalloc import WORD
 from pypy.jit.backend.x86 import symbolic
 from pypy.jit.metainterp.resoperation import rop
 import ctypes
@@ -20,7 +20,10 @@
         self.recordedvalues = [
                 gf.cpu.getvaluebox(gf.frame, gf.guard_op, i).value
                     for i in range(len(gf.guard_op.liveboxes))]
-        gf.make_ready_for_return(BoxInt(42))
+        if len(gf.guard_op.liveboxes) > 0:
+            gf.make_ready_for_return(gf.cpu.getvaluebox(gf.frame, gf.guard_op, 0))
+        else:
+            gf.make_ready_for_return(None)
 
 MY_VTABLE = lltype.Struct('my_vtable')    # for tests only
 
@@ -39,13 +42,14 @@
 class TestX86(object):
     def setup_class(cls):
         cls.cpu = CPU(rtyper=None, stats=FakeStats())
+        cls.cpu.set_meta_interp(FakeMetaInterp())
 
     def execute_operation(self, opname, valueboxes, result_type):
         key = [opname, result_type]
         mp = self.get_compiled_single_operation(opname, result_type, valueboxes)
         boxes = [box for box in valueboxes if isinstance(box, Box)]
-        res = self.cpu.execute_operations_in_new_frame(opname, mp, boxes,
-                                                       result_type)
+        res = self.cpu.execute_operations_in_new_frame(opname, mp, boxes +
+                                                       [BoxInt(1)])
         return res
 
     def get_compiled_single_operation(self, opnum, result_type, valueboxes):
@@ -54,9 +58,10 @@
             if isinstance(box, Box):
                 box = box.clonebox()
             livevarlist.append(box)
-        mp = ResOperation(rop.MERGE_POINT,
-                        [box for box in livevarlist if isinstance(box, Box)],
-                        None)
+        args = [box for box in livevarlist if isinstance(box, Box)]
+        checker = BoxInt(1)
+        args.append(checker)
+        mp = ResOperation(rop.MERGE_POINT, args, None)
         if result_type == 'void':
             result = None
         elif result_type == 'int':
@@ -71,11 +76,12 @@
             results = [result]
         operations = [mp,
                       ResOperation(opnum, livevarlist, result),
-                      ResOperation(RETURN, results, None)]
+                      ResOperation(rop.GUARD_FALSE, [checker], None)]
+        operations[-1].liveboxes = results
         if operations[1].is_guard():
             operations[1].liveboxes = []
         self.cpu.compile_operations(operations, verbose=False)
-        return mp
+        return operations
 
 
     def test_int_binary_ops(self):
@@ -136,10 +142,9 @@
         operations[-1].jump_target = startmp
         operations[-2].liveboxes = [t, u, z]
         cpu.compile_operations(operations)
-        res = self.cpu.execute_operations_in_new_frame('foo', startmp,
-                                                       [BoxInt(0), BoxInt(10)],
-                                                       'int')
-        assert res.value == 42
+        res = self.cpu.execute_operations_in_new_frame('foo', operations,
+                                                       [BoxInt(0), BoxInt(10)])
+        assert res.value == 0
         gf = cpu.metainterp.gf
         assert cpu.metainterp.recordedvalues == [0, True, 55]
         assert gf.guard_op is operations[-2]



More information about the Pypy-commit mailing list