[pypy-svn] r38055 - in pypy/branch/jit-virtual-world/pypy/translator/backendopt: . test

arigo at codespeak.net arigo at codespeak.net
Wed Feb 7 13:24:46 CET 2007


Author: arigo
Date: Wed Feb  7 13:24:34 2007
New Revision: 38055

Modified:
   pypy/branch/jit-virtual-world/pypy/translator/backendopt/all.py
   pypy/branch/jit-virtual-world/pypy/translator/backendopt/removeassert.py
   pypy/branch/jit-virtual-world/pypy/translator/backendopt/test/test_removeassert.py
Log:
Update removeassert to have it turn asserts into a 'debug_assert'
lloperation.  Fix all.py, which in the case where most optimizations
are disabled, would not do any constfold even if asked to.


Modified: pypy/branch/jit-virtual-world/pypy/translator/backendopt/all.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/translator/backendopt/all.py	(original)
+++ pypy/branch/jit-virtual-world/pypy/translator/backendopt/all.py	Wed Feb  7 13:24:34 2007
@@ -69,6 +69,7 @@
         inline_malloc_removal_phase(config, translator, graphs,
                                     config.inline_threshold,
                                     inline_heuristic=heuristic)
+        constfold(config, graphs)
 
     if config.clever_malloc_removal:
         threshold = config.clever_malloc_removal_threshold
@@ -102,6 +103,7 @@
                                     threshold,
                                     inline_heuristic=heuristic,
                                     call_count_pred=call_count_pred)
+    constfold(config, graphs)
 
     if config.remove_asserts:
         remove_asserts(translator, graphs)
@@ -152,6 +154,3 @@
         if config.print_statistics:
             print "after malloc removal:"
             print_statistics(translator.graphs[0], translator)    
-
-    constfold(config, graphs)
-

Modified: pypy/branch/jit-virtual-world/pypy/translator/backendopt/removeassert.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/translator/backendopt/removeassert.py	(original)
+++ pypy/branch/jit-virtual-world/pypy/translator/backendopt/removeassert.py	Wed Feb  7 13:24:34 2007
@@ -1,6 +1,7 @@
 from pypy.objspace.flow.model import Constant, checkgraph, c_last_exception
+from pypy.rpython.rtyper import LowLevelOpList, inputconst
 from pypy.translator.simplify import eliminate_empty_blocks, join_blocks
-from pypy.translator.simplify import transform_dead_op_vars
+#from pypy.translator.simplify import transform_dead_op_vars
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.lltypesystem import rclass
 from pypy.translator.backendopt.support import log
@@ -34,7 +35,7 @@
             # the condition
             log.removeassert("removed %d asserts in %s" % (count, graph.name))
             checkgraph(graph)
-            transform_dead_op_vars(graph, translator)
+            #transform_dead_op_vars(graph, translator)
 
 
 def kill_assertion_link(graph, link):
@@ -49,6 +50,20 @@
     else:
         if block.exitswitch.concretetype is not lltype.Bool:   # a switch
             remove_condition = False
+        else:
+            # common case: if <cond>: raise AssertionError
+            # turn it into a debug_assert operation
+            assert remove_condition
+            newops = LowLevelOpList()
+            if link.exitcase:
+                v = newops.genop('bool_not', [block.exitswitch],
+                                 resulttype = lltype.Bool)
+            else:
+                v = block.exitswitch
+            msg = "assertion failed in %s" % (graph.name,)
+            c_msg = inputconst(lltype.Void, msg)
+            newops.genop('debug_assert', [v, c_msg])
+            block.operations.extend(newops)
 
     exits.remove(link)
     if remove_condition:

Modified: pypy/branch/jit-virtual-world/pypy/translator/backendopt/test/test_removeassert.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/translator/backendopt/test/test_removeassert.py	(original)
+++ pypy/branch/jit-virtual-world/pypy/translator/backendopt/test/test_removeassert.py	Wed Feb  7 13:24:34 2007
@@ -38,7 +38,7 @@
     graph, t = get_graph(fn, [int])
     assert summary(graph) == {'int_ge': 1, 'int_sub': 1}
     remove_asserts(t, [graph])
-    assert summary(graph) == {'int_sub': 1}
+    assert summary(graph) == {'int_ge': 1, 'debug_assert': 1, 'int_sub': 1}
     check_graph(graph, [1], 0, t)
 
 def test_and():



More information about the Pypy-commit mailing list