[pypy-svn] r17899 - in pypy/dist/pypy/translator/backendopt: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Sep 27 12:40:01 CEST 2005


Author: cfbolz
Date: Tue Sep 27 12:40:01 2005
New Revision: 17899

Modified:
   pypy/dist/pypy/translator/backendopt/propagate.py
   pypy/dist/pypy/translator/backendopt/test/test_propagate.py
Log:
fix a few issues of propagate: coalesce_links did the wrong thing with
except link: fix + test (thanks eric)
cast_ptr_to_int should of course _not_ be folded (thanks samuele)
one more test that fails in llvm, but seems to pass for me


Modified: pypy/dist/pypy/translator/backendopt/propagate.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/propagate.py	(original)
+++ pypy/dist/pypy/translator/backendopt/propagate.py	Tue Sep 27 12:40:01 2005
@@ -62,6 +62,8 @@
             return
         if len(block.exits) != 2:
             return
+        if block.exitswitch == Constant(last_exception):
+            return
         if (block.exits[0].args == block.exits[1].args and
             block.exits[0].target is block.exits[1].target):
             candidates[block] = True
@@ -103,11 +105,11 @@
                 del link.args[i]
             var = block.inputargs[i]
             del block.inputargs[i]
-	    op = SpaceOperation("same_as", [const], var)
-	    block.operations.insert(0, op)
+            op = SpaceOperation("same_as", [const], var)
+            block.operations.insert(0, op)
             changed[0] = True
     if changed[0]:
-    	remove_same_as(graph)
+        remove_same_as(graph)
         checkgraph(graph)
         return True
     return False
@@ -115,7 +117,7 @@
 _op = """getarrayitem setarrayitem malloc malloc_varsize flavored_malloc
          flavored_free getfield setfield getsubstruct getarraysubstruct
          getarraysize raw_malloc raw_free raw_memcopy raw_load
-         raw_store direct_call cast_pointer""".split()
+         raw_store direct_call cast_pointer cast_ptr_to_int""".split()
 from pypy.objspace.flow.operation import FunctionByName
 _op += FunctionByName.keys() #operations with PyObjects are dangerous
 cannot_constant_fold = {}

Modified: pypy/dist/pypy/translator/backendopt/test/test_propagate.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_propagate.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_propagate.py	Tue Sep 27 12:40:01 2005
@@ -85,3 +85,36 @@
     assert len(graph.startblock.operations) == 1
     check_graph(graph, [10], g(10), t)
 
+def getitem(l, i):  #LookupError, KeyError
+    if not isinstance(i, int):
+        raise TypeError
+    if i < 0:
+        i = len(l) - i
+    if i>= len(l):
+        raise IndexError
+    return l[i]
+
+def test_dont_coalesce_except():
+    def fn(n):
+        lst = range(10)
+        try:
+            getitem(lst,n)
+        except:
+            pass
+        return 4
+    graph, t = get_graph(fn, [int])
+    coalesce_links(graph)
+    check_graph(graph, [-1], fn(-1), t)
+
+def list_default_argument(i1, l1=[0]):
+    l1.append(i1)
+    return len(l1) + l1[-2]
+
+def call_list_default_argument(i1):
+    return list_default_argument(i1)
+    
+def test_call_list_default_argument():
+    graph, t = get_graph(call_list_default_argument, [int])
+    t.backend_optimizations(propagate=True, ssa_form=False) 
+    for i in range(10):
+        check_graph(graph, [i], call_list_default_argument(i), t)



More information about the Pypy-commit mailing list