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

pedronis at codespeak.net pedronis at codespeak.net
Wed Nov 21 12:15:25 CET 2007


Author: pedronis
Date: Wed Nov 21 12:15:25 2007
New Revision: 48894

Modified:
   pypy/dist/pypy/translator/backendopt/all.py
   pypy/dist/pypy/translator/backendopt/support.py
   pypy/dist/pypy/translator/backendopt/test/test_all.py
Log:
(cfbolz, pedronis)

fix for test_idempotent
rerun noops removal at the end of all opts



Modified: pypy/dist/pypy/translator/backendopt/all.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/all.py	(original)
+++ pypy/dist/pypy/translator/backendopt/all.py	Wed Nov 21 12:15:25 2007
@@ -54,15 +54,18 @@
         check_virtual_methods()
 
     # remove obvious no-ops
-    for graph in graphs:
-        removenoops.remove_same_as(graph)
-        simplify.eliminate_empty_blocks(graph)
-        simplify.transform_dead_op_vars(graph, translator)
-        removenoops.remove_duplicate_casts(graph, translator)
+    def remove_obvious_noops():
+        for graph in graphs:
+            removenoops.remove_same_as(graph)
+            simplify.eliminate_empty_blocks(graph)
+            simplify.transform_dead_op_vars(graph, translator)
+            removenoops.remove_duplicate_casts(graph, translator)
 
-    if config.print_statistics:
-        print "after no-op removal:"
-        print_statistics(translator.graphs[0], translator)
+        if config.print_statistics:
+            print "after no-op removal:"
+            print_statistics(translator.graphs[0], translator)
+
+    remove_obvious_noops()
 
     if config.inline or config.mallocs:
         heuristic = get_function(config.inline_heuristic)
@@ -129,6 +132,8 @@
         from pypy.translator.backendopt import coalloc
         coalloc.malloc_to_coalloc(translator)
 
+    remove_obvious_noops()
+
     for graph in graphs:
         checkgraph(graph)
 

Modified: pypy/dist/pypy/translator/backendopt/support.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/support.py	(original)
+++ pypy/dist/pypy/translator/backendopt/support.py	Wed Nov 21 12:15:25 2007
@@ -185,9 +185,12 @@
 
 def md5digest(translator):
     import md5
-    m = md5.new()
-    for op in all_operations(translator.graphs):
-        m.update(op.opname + str(op.result))
-        for a in op.args:
-            m.update(str(a))
-    return m.digest()[:]
+    graph2digest = {}
+    for graph in translator.graphs:
+        m = md5.new()
+        for op in graph_operations(graph):
+            m.update(op.opname + str(op.result))
+            for a in op.args:
+                m.update(str(a))
+        graph2digest[graph.name] = m.digest()
+    return graph2digest

Modified: pypy/dist/pypy/translator/backendopt/test/test_all.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_all.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_all.py	Wed Nov 21 12:15:25 2007
@@ -134,20 +134,31 @@
             c = [i for i in range(n2)]
             return 33 + big() + g(10)
 
-        t  = self.translateopt(idempotent, [int, int], raisingop2direct_call=True,
-                          constfold=False)
+        t  = self.translateopt(idempotent, [int, int],
+                               raisingop2direct_call=True,
+                               constfold=False)
+        #backend_optimizations(t, raisingop2direct_call=True,
+        #                      inline_threshold=0, constfold=False)
+
         digest1 = md5digest(t)
 
         digest2 = md5digest(t)
-        assert digest1 == digest2
+        def compare(digest1, digest2):
+            diffs = []
+            assert digest1.keys() == digest2.keys()
+            for name in digest1:
+                if digest1[name] != digest2[name]:
+                    diffs.append(name)
+            assert not diffs
+
+        compare(digest1, digest2)
 
         #XXX Inlining and constfold are currently non-idempotent.
         #    Maybe they just renames variables but the graph changes in some way.
         backend_optimizations(t, raisingop2direct_call=True,
                               inline_threshold=0, constfold=False)
         digest3 = md5digest(t)
-        assert digest1 == digest3
-
+        compare(digest1, digest3)
 
     def test_bug_inlined_if(self):
         def f(x, flag):



More information about the Pypy-commit mailing list