[pypy-svn] r66651 - in pypy/branch/pyjitpl5/pypy/jit: backend/llgraph backend/llvm backend/test backend/x86 backend/x86/test metainterp metainterp/test

arigo at codespeak.net arigo at codespeak.net
Mon Jul 27 14:58:49 CEST 2009


Author: arigo
Date: Mon Jul 27 14:58:46 2009
New Revision: 66651

Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py
   pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py
   pypy/branch/pyjitpl5/pypy/jit/backend/llvm/compile.py
   pypy/branch/pyjitpl5/pypy/jit/backend/test/runner_test.py
   pypy/branch/pyjitpl5/pypy/jit/backend/test/test_random.py
   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/test/test_runner.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/executor.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/resoperation.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_basic.py
Log:
Add rop.SAME_AS.  Normally not used, because it is just removed by
optimize.py, but it's useful to have it during tracing (see test).
Implemented it anyway in the backends, for completeness and for
tests running without optimize.py.


Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py	Mon Jul 27 14:58:46 2009
@@ -83,6 +83,7 @@
     'uint_ge'         : (('int', 'int'), 'bool'),
     'uint_xor'        : (('int', 'int'), 'int'),
     'uint_rshift'     : (('int', 'int'), 'int'),
+    'same_as'         : (('int',), 'int'),      # could also be ptr=>ptr
     'new_with_vtable' : (('ptr',), 'ptr'),
     'new'             : ((), 'ptr'),
     'new_array'       : (('int',), 'ptr'),

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py	Mon Jul 27 14:58:46 2009
@@ -377,6 +377,9 @@
             llimpl.do_setfield_raw_int(struct, fielddescr.ofs, newvalue,
                                        self.memo_cast)
 
+    def do_same_as(self, args, descr=None):
+        return args[0].clonebox()
+
     def do_newstr(self, args, descr=None):
         assert descr is None
         length = args[0].getint()

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llvm/compile.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llvm/compile.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llvm/compile.py	Mon Jul 27 14:58:46 2009
@@ -563,6 +563,12 @@
             self.getptrarg(op.args[0]),
             self.cpu.const_null_charptr, "")
 
+    def generate_SAME_AS(self, op):
+        if op.args[0].type == INT:
+            self.vars[op.result] = self.getintarg(op.args[0])
+        else:
+            self.vars[op.result] = self.getptrarg(op.args[0])
+
     def _generate_len_gep(self, array_ref, ty, const_index_length):
         array = llvm_rffi.LLVMBuildBitCast(self.builder,
                                            array_ref, ty, "")

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/test/runner_test.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/test/runner_test.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/test/runner_test.py	Mon Jul 27 14:58:46 2009
@@ -506,6 +506,13 @@
                                    'int')
         assert r.value == 31313
 
+    def test_same_as(self):
+        r = self.execute_operation(rop.SAME_AS, [ConstInt(5)], 'int')
+        assert r.value == 5
+        u_box = self.alloc_unicode(u"hello\u1234")
+        r = self.execute_operation(rop.SAME_AS, [u_box.constbox()], 'ptr')
+        assert r.value == u_box.value
+
 
 class LLtypeBackendTest(BaseBackendTest):
 

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/test/test_random.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/test/test_random.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/test/test_random.py	Mon Jul 27 14:58:46 2009
@@ -196,6 +196,10 @@
         v = builder.get_bool_var(r)
         self.put(builder, [v])
 
+class ConstUnaryOperation(UnaryOperation):
+    def produce_into(self, builder, r):
+        self.put(builder, [ConstInt(r.random_integer())])
+
 class BinaryOperation(AbstractOperation):
     def __init__(self, opnum, and_mask=-1, or_mask=0, boolres=False):
         AbstractOperation.__init__(self, opnum, boolres=boolres)
@@ -318,6 +322,7 @@
 
 OPERATIONS.append(UnaryOperation(rop.INT_IS_TRUE, boolres=True))
 OPERATIONS.append(BooleanUnaryOperation(rop.BOOL_NOT, boolres=True))
+OPERATIONS.append(ConstUnaryOperation(rop.SAME_AS, boolres=True))
 
 for _op in [rop.INT_ADD_OVF,
             rop.INT_SUB_OVF,

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	Mon Jul 27 14:58:46 2009
@@ -449,6 +449,9 @@
         self.mc.MOV(resloc, imm8(0))
         self.mc.SETE(lower_byte(resloc))
 
+    def genop_same_as(self, op, arglocs, resloc):
+        self.mc.MOV(resloc, arglocs[0])
+
     def genop_int_mod(self, op, arglocs, resloc):
         self.mc.CDQ()
         self.mc.IDIV(ecx)

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	Mon Jul 27 14:58:46 2009
@@ -1110,6 +1110,12 @@
     consider_ooisnull = _consider_nullity
     consider_oononnull = _consider_nullity
 
+    def consider_same_as(self, op, ignored):
+        argloc = self.loc(op.args[0])
+        self.eventually_free_var(op.args[0])
+        resloc = self.force_allocate_reg(op.result, [])
+        self.Perform(op, [argloc], resloc)
+
     def consider_strlen(self, op, ignored):
         base_loc = self.make_sure_var_in_reg(op.args[0], op.args)
         self.eventually_free_vars(op.args)

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	Mon Jul 27 14:58:46 2009
@@ -107,18 +107,6 @@
             ]:
             assert self.execute_operation(op, args, 'int').value == res
 
-    def test_same_as(self):
-        py.test.skip("rewrite")
-        u = lltype.malloc(U)
-        uadr = lltype.cast_opaque_ptr(llmemory.GCREF, u)
-        for op, args, tp, res in [
-            ('same_as', [BoxInt(7)], 'int', 7),
-            ('same_as', [ConstInt(7)], 'int', 7),
-            ('same_as', [BoxPtr(uadr)], 'ptr', uadr),
-            ('same_as', [ConstPtr(uadr)], 'ptr', uadr),
-            ]:
-            assert self.execute_operation(op, args, tp).value == res
-
     def test_unicode(self):
         ofs = symbolic.get_field_token(rstr.UNICODE, 'chars', False)[0]
         u = rstr.mallocunicode(13)

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/executor.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/executor.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/executor.py	Mon Jul 27 14:58:46 2009
@@ -99,6 +99,9 @@
 def do_bool_not(cpu, args, descr=None):
     return ConstInt(not args[0].getint())
 
+def do_same_as(cpu, args, descr=None):
+    return args[0]
+
 def do_oononnull(cpu, args, descr=None):
     tp = args[0].type
     if tp == INT:

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	Mon Jul 27 14:58:46 2009
@@ -780,7 +780,7 @@
         self.generate_merge_point(pc, self.env)
         if self.metainterp.seen_can_enter_jit:
             self.metainterp.seen_can_enter_jit = False
-            self.metainterp.reached_can_enter_jit(self.env[:])
+            self.metainterp.reached_can_enter_jit(self.env)
 
     @arguments("jumptarget")
     def opimpl_setup_exception_block(self, exception_target):
@@ -1223,10 +1223,22 @@
         except GenerateMergePoint, gmp:
             return self.designate_target_loop(gmp)
 
+    def forget_consts(self, boxes, startindex=0):
+        for i in range(startindex, len(boxes)):
+            box = boxes[i]
+            if isinstance(box, Const):
+                constbox = box
+                box = constbox.clonebox()
+                boxes[i] = box
+                self.history.record(rop.SAME_AS, [constbox], box)
+
     def reached_can_enter_jit(self, live_arg_boxes):
+        self.forget_consts(live_arg_boxes, self.staticdata.num_green_args)
+        live_arg_boxes = live_arg_boxes[:]
         if self.staticdata.virtualizable_info is not None:
             # we use ':-1' to remove the last item, which is the virtualizable
             # itself
+            self.forget_consts(self.virtualizable_boxes)
             live_arg_boxes += self.virtualizable_boxes[:-1]
         # Called whenever we reach the 'can_enter_jit' hint.
         # First, attempt to make a bridge:

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/resoperation.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/resoperation.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/resoperation.py	Mon Jul 27 14:58:46 2009
@@ -154,6 +154,8 @@
     INT_INVERT             = 62
     BOOL_NOT               = 63
     #
+    SAME_AS                = 64      # gets a Const, turns it into a Box
+    #
     _NOSIDEEFFECT_PTR_FIRST = 70 # -- start of no_side_effect_ptr operations --
     OONONNULL              = 70
     OOISNULL               = 71

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_basic.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_basic.py	Mon Jul 27 14:58:46 2009
@@ -731,7 +731,6 @@
         self.meta_interp(f, [40, 0])
 
     def test_const_inputargs(self):
-        py.test.skip("in-progress")
         myjitdriver = JitDriver(greens = ['m'], reds = ['n', 'x'])
         def f(n, x):
             m = 0x7FFFFFFF



More information about the Pypy-commit mailing list