[pypy-svn] r24721 - in pypy/dist/pypy/jit: . test

pedronis at codespeak.net pedronis at codespeak.net
Tue Mar 21 20:29:55 CET 2006


Author: pedronis
Date: Tue Mar 21 20:29:48 2006
New Revision: 24721

Modified:
   pypy/dist/pypy/jit/hintrtyper.py
   pypy/dist/pypy/jit/hinttimeshift.py
   pypy/dist/pypy/jit/test/test_hint_timeshift.py
Log:
pass test_plus_minus_all_inlined

there was a bug about green key values being carried around in their erased form instead of simply the original one.

Fold getfield/arrayitem if the arguments are green and the container immutable.



Modified: pypy/dist/pypy/jit/hintrtyper.py
==============================================================================
--- pypy/dist/pypy/jit/hintrtyper.py	(original)
+++ pypy/dist/pypy/jit/hintrtyper.py	Tue Mar 21 20:29:48 2006
@@ -59,9 +59,9 @@
             self.red_reprs[lowleveltype] = r
             return r
 
-    def generic_translate_operation(self, hop):
+    def generic_translate_operation(self, hop, force=False):
         # detect constant-foldable all-green operations
-        if hop.spaceop.opname not in rtimeshift.FOLDABLE_OPS:
+        if not force and hop.spaceop.opname not in rtimeshift.FOLDABLE_OPS:
             return None
         green = True
         for r_arg in hop.args_r:
@@ -99,13 +99,20 @@
         # don't try to generate hint operations, just discard them
         return hop.inputarg(hop.r_result, arg=0)
 
+    def translate_op_keepalive(self,hop):
+        pass
+
     def translate_op_getfield(self, hop):
         if isinstance(hop.args_r[0], BlueRepr):
             return hop.args_r[0].timeshift_getfield(hop)
         # non virtual case        
-        # XXX green getfields on an immutable structure could be more efficient
-        ts = self.timeshifter
         PTRTYPE = originalconcretetype(hop.args_s[0])
+        if PTRTYPE.TO._hints.get('immutable', False): # foldable if all green
+            res = self.generic_translate_operation(hop, force=True)
+            if res is not None:
+                return res
+            
+        ts = self.timeshifter
         RESTYPE = originalconcretetype(hop.s_result)
         v_argbox, c_fieldname = hop.inputargs(self.getredrepr(PTRTYPE),
                                               green_void_repr)
@@ -124,9 +131,13 @@
             ts.s_RedBox)
 
     def translate_op_getarrayitem(self, hop):
-        # XXX green getarrayitems on an immutable array could be more efficient
-        ts = self.timeshifter
         PTRTYPE = originalconcretetype(hop.args_s[0])
+        if PTRTYPE.TO._hints.get('immutable', False): # foldable if all green
+            res = self.generic_translate_operation(hop, force=True)
+            if res is not None:
+                return res
+
+        ts = self.timeshifter
         RESTYPE = originalconcretetype(hop.s_result)
         v_argbox, v_index = hop.inputargs(self.getredrepr(PTRTYPE),
                                           self.getredrepr(lltype.Signed))
@@ -169,7 +180,6 @@
         if isinstance(hop.args_r[0], BlueRepr):        
             return hop.args_r[0].timeshift_getsubstruct(hop)
         # non virtual case
-        # XXX green getfields on an immutable structure could be more efficient
         ts = self.timeshifter
         PTRTYPE = originalconcretetype(hop.args_s[0])
         RESTYPE = originalconcretetype(hop.s_result)

Modified: pypy/dist/pypy/jit/hinttimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/hinttimeshift.py	(original)
+++ pypy/dist/pypy/jit/hinttimeshift.py	Tue Mar 21 20:29:48 2006
@@ -295,6 +295,7 @@
         getrepr = self.rtyper.getrepr        
         items_s = []
         key_v = []
+        orig_key_v = []
         for r, newvar in zip(args_r, newinputargs):
             if isinstance(r, GreenRepr):
                 r_from = getrepr(r.annotation())
@@ -302,6 +303,7 @@
                 r_to = getrepr(erased_s)
                 items_s.append(erased_s)
                 erased_v = llops.convertvar(newvar, r_from, r_to)
+                orig_key_v.append(newvar)
                 key_v.append(erased_v)
 
         s_key_tuple = annmodel.SomeTuple(items_s)
@@ -331,13 +333,13 @@
 
         
         read_boxes_block_vars = [v_newjitstate2, v_boxes2]
-        for greenvar in key_v:
+        for greenvar in orig_key_v:
             greenvar2 = flowmodel.Variable(greenvar)
             greenvar2.concretetype = greenvar.concretetype
             read_boxes_block_vars.append(greenvar2)
 
         read_boxes_block = flowmodel.Block(read_boxes_block_vars)
-        to_read_boxes_block = flowmodel.Link([v_newjitstate, v_boxes] + key_v, read_boxes_block)
+        to_read_boxes_block = flowmodel.Link([v_newjitstate, v_boxes] + orig_key_v, read_boxes_block)
         to_read_boxes_block.exitcase = to_read_boxes_block.llexitcase = True
         to_dispatch_block = flowmodel.Link([v_oldjitstate], self.dispatchblock)
         to_dispatch_block.exitcase = to_dispatch_block.llexitcase = False

Modified: pypy/dist/pypy/jit/test/test_hint_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/test/test_hint_timeshift.py	(original)
+++ pypy/dist/pypy/jit/test/test_hint_timeshift.py	Tue Mar 21 20:29:48 2006
@@ -337,7 +337,6 @@
     assert insns == {'getsubstruct': 2, 'int_is_true': 1, 'malloc': 2, 'setfield': 2}
 
 def test_plus_minus_all_inlined():
-    py.test.skip("in-progress")
     def ll_plus_minus(s, x, y):
         acc = x
         n = len(s)
@@ -353,5 +352,5 @@
         return acc
     s = rstr.string_repr.convert_const("+-+")
     insns, res = timeshift(ll_plus_minus, [s, 0, 2], [0], inline=999)
-    assert res == ll_plus_minus(s, 0, 2)
+    assert res == ll_plus_minus("+-+", 0, 2)
     assert insns == {'int_add': 2, 'int_sub': 1}



More information about the Pypy-commit mailing list