[pypy-svn] r34015 - in pypy/dist/pypy/translator: . backendopt backendopt/test c/test llvm

cfbolz at codespeak.net cfbolz at codespeak.net
Wed Nov 1 13:43:38 CET 2006


Author: cfbolz
Date: Wed Nov  1 13:43:37 2006
New Revision: 34015

Modified:
   pypy/dist/pypy/translator/backendopt/all.py
   pypy/dist/pypy/translator/backendopt/test/test_all.py
   pypy/dist/pypy/translator/backendopt/test/test_merge_if_blocks.py
   pypy/dist/pypy/translator/backendopt/test/test_removenoops.py
   pypy/dist/pypy/translator/c/test/test_backendoptimized.py
   pypy/dist/pypy/translator/driver.py
   pypy/dist/pypy/translator/llvm/genllvm.py
Log:
(cfbolz, arigo and pedronis discussing)
fix failing backend optimization tests


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  1 13:43:37 2006
@@ -11,25 +11,14 @@
 from pypy.translator.backendopt.support import log
 from pypy.objspace.flow.model import checkgraph
 
-def backend_optimizations(translator, graphs=None,
-                                      raisingop2direct_call_all=False,
-                                      inline_threshold=1,
-                                      mallocs=True,
-                                      merge_if_blocks_to_switch=True,
-                                      constfold=True,
-                                      heap2stack=False,
-                                      clever_malloc_removal=False):
-
-    config = translator.config.translation.backendopt
-    # ZZZ the arguments here should disappear
-    raisingop2direct_call_all = (config.raisingop2direct_call or
-        raisingop2direct_call_all)
-    mallocs = config.mallocs or mallocs
-    merge_if_blocks_to_switch = (config.merge_if_blocks or
-        merge_if_blocks_to_switch)
-    constfold = config.constfold or constfold
-    heap2stack = config.heap2stack or heap2stack
-    clever_malloc_removal = config.clever_malloc_removal or clever_malloc_removal
+def backend_optimizations(translator, graphs=None, **kwds):
+    # sensible keywords are
+    # raisingop2direct_call, inline_threshold, mallocs
+    # merge_if_blocks, constfold, heap2stack
+    # clever_malloc_removal
+
+    config = translator.config.translation.backendopt.copy()
+    config.set(**kwds)
 
     if graphs is None:
         graphs = translator.graphs
@@ -38,7 +27,7 @@
         print "before optimizations:"
         print_statistics(translator.graphs[0], translator, "per-graph.txt")
 
-    if raisingop2direct_call_all:
+    if config.raisingop2direct_call:
         raisingop2direct_call(translator, graphs)
 
     # remove obvious no-ops
@@ -52,11 +41,11 @@
         print "after no-op removal:"
         print_statistics(translator.graphs[0], translator)
 
-    if not clever_malloc_removal:
+    if not config.clever_malloc_removal:
         # inline functions in each other
-        if inline_threshold:
+        if config.inline_threshold:
             callgraph = inline.inlinable_static_callers(graphs)
-            inline.auto_inlining(translator, inline_threshold,
+            inline.auto_inlining(translator, config.inline_threshold,
                                  callgraph=callgraph)
             for graph in graphs:
                 removenoops.remove_superfluous_keep_alive(graph)
@@ -67,7 +56,7 @@
             print_statistics(translator.graphs[0], translator)
 
         # vaporize mallocs
-        if mallocs:
+        if config.mallocs:
             tot = 0
             for graph in graphs:
                 count = remove_simple_mallocs(graph)
@@ -90,15 +79,15 @@
             print "after clever inlining and malloc removal"
             print_statistics(translator.graphs[0], translator)
 
-    if constfold:
+    if config.constfold:
         for graph in graphs:
             constant_fold_graph(graph)
 
-    if heap2stack:
+    if config.heap2stack:
         assert graphs is translator.graphs  # XXX for now
         malloc_to_stack(translator)
 
-    if merge_if_blocks_to_switch:
+    if config.merge_if_blocks:
         for graph in graphs:
             merge_if_blocks(graph)
 

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  1 13:43:37 2006
@@ -139,7 +139,7 @@
         c = [i for i in range(n2)]
         return 33 + big() + g(10)
 
-    t  = translateopt(idempotent, [int, int], raisingop2direct_call_all=True,
+    t  = translateopt(idempotent, [int, int], raisingop2direct_call=True,
                       constfold=False)
     digest1 = md5digest(t)
 
@@ -148,7 +148,7 @@
 
     #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_all=True,
+    backend_optimizations(t, raisingop2direct_call=True,
                           inline_threshold=0, constfold=False)
     digest3 = md5digest(t)
     assert digest1 == digest3
@@ -184,7 +184,7 @@
         for i in r:
             res = res * 51 + i
         return res
-    t = translateopt(fn, [int, int, int], merge_if_blocks_to_switch=True)
+    t = translateopt(fn, [int, int, int], merge_if_blocks=True)
     interp = LLInterpreter(t.rtyper)
     for args in [2, 7, 0], [7, 2, 0], [10, 50, 7], [50, -10, -3]:
         assert interp.eval_graph(graphof(t, fn), args) == intmask(fn(*args))

Modified: pypy/dist/pypy/translator/backendopt/test/test_merge_if_blocks.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_merge_if_blocks.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_merge_if_blocks.py	Wed Nov  1 13:43:37 2006
@@ -154,7 +154,7 @@
     a.build_types(fn, [])
     rtyper = t.buildrtyper()
     rtyper.specialize()
-    backend_optimizations(t, merge_if_blocks_to_switch=True)
+    backend_optimizations(t, merge_if_blocks=True)
     graph = tgraphof(t, fn)
     blocknum = len(list(graph.iterblocks()))
     merge_if_blocks(graph)
@@ -174,7 +174,7 @@
     a.build_types(fn, [int])
     rtyper = t.buildrtyper()
     rtyper.specialize()
-    backend_optimizations(t, merge_if_blocks_to_switch=True)
+    backend_optimizations(t, merge_if_blocks=True)
     graph = tgraphof(t, fn)
     assert len(graph.startblock.exits) == 2
     interp = LLInterpreter(rtyper)

Modified: pypy/dist/pypy/translator/backendopt/test/test_removenoops.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_removenoops.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_removenoops.py	Wed Nov  1 13:43:37 2006
@@ -21,7 +21,7 @@
     if all_opts:
         backend_optimizations(t, inline_threshold=inline_threshold,
                               constfold=False,
-                              raisingop2direct_call_all=False)
+                              raisingop2direct_call=False)
     graph = graphof(t, fn)
     if conftest.option.view:
         t.view()

Modified: pypy/dist/pypy/translator/c/test/test_backendoptimized.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_backendoptimized.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_backendoptimized.py	Wed Nov  1 13:43:37 2006
@@ -10,7 +10,7 @@
     def process(self, t):
         _TestTypedTestCase.process(self, t)
         self.t = t
-        backend_optimizations(t, merge_if_blocks_to_switch=False)
+        backend_optimizations(t, merge_if_blocks=False)
         if conftest.option.view:
             t.view()
 
@@ -89,7 +89,7 @@
         def process(self, t):
             _TestTypedTestCase.process(self, t)
             self.t = t
-            backend_optimizations(t, merge_if_blocks_to_switch=True)
+            backend_optimizations(t, merge_if_blocks=True)
 
     def test_int_switch(self):
         def f(x):
@@ -186,7 +186,7 @@
         def process(self, t):
             _TestTypedTestCase.process(self, t)
             self.t = t
-            backend_optimizations(t, raisingop2direct_call_all=True)
+            backend_optimizations(t, raisingop2direct_call=True)
 
     def test_int_floordiv_zer(self):
         def f(x):

Modified: pypy/dist/pypy/translator/driver.py
==============================================================================
--- pypy/dist/pypy/translator/driver.py	(original)
+++ pypy/dist/pypy/translator/driver.py	Wed Nov  1 13:43:37 2006
@@ -277,10 +277,10 @@
     def task_backendopt_ootype(self):
         from pypy.translator.backendopt.all import backend_optimizations
         backend_optimizations(self.translator,
-                              raisingop2direct_call_all=False,
+                              raisingop2direct_call=False,
                               inline_threshold=0,
                               mallocs=False,
-                              merge_if_blocks_to_switch=False,
+                              merge_if_blocks=False,
                               propagate=False,
                               constfold=True,
                               heap2stack=False,

Modified: pypy/dist/pypy/translator/llvm/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm/genllvm.py	Wed Nov  1 13:43:37 2006
@@ -335,13 +335,13 @@
 
     # use backend optimizations?
     if optimize:
-        backend_optimizations(translator, raisingop2direct_call_all=True)
+        backend_optimizations(translator, raisingop2direct_call=True)
     else:
         backend_optimizations(translator,
-                              raisingop2direct_call_all=True,
+                              raisingop2direct_call=True,
                               inline_threshold=0,
                               mallocs=False,
-                              merge_if_blocks_to_switch=False,
+                              merge_if_blocks=False,
                               constfold=False)
 
     # note: this is without stackless and policy transforms



More information about the Pypy-commit mailing list