[pypy-svn] r20369 - in pypy/branch/somepbc-refactoring/pypy/translator/backendopt: . test

pedronis at codespeak.net pedronis at codespeak.net
Mon Nov 28 19:52:28 CET 2005


Author: pedronis
Date: Mon Nov 28 19:52:25 2005
New Revision: 20369

Modified:
   pypy/branch/somepbc-refactoring/pypy/translator/backendopt/inline.py
   pypy/branch/somepbc-refactoring/pypy/translator/backendopt/removenoops.py
   pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_all.py
   pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_inline.py
   pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_malloc.py
   pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_propagate.py
   pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_removenoops.py
   pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_ssa.py
   pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_tailrecursion.py
Log:
(arre, pedronis)

fixed backendopt tests



Modified: pypy/branch/somepbc-refactoring/pypy/translator/backendopt/inline.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/backendopt/inline.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/backendopt/inline.py	Mon Nov 28 19:52:25 2005
@@ -6,6 +6,7 @@
 from pypy.objspace.flow.model import SpaceOperation, last_exception
 from pypy.objspace.flow.model import traverse, mkentrymap, checkgraph
 from pypy.annotation import model as annmodel
+from pypy.rpython.typesystem import LowLevelTypeSystem
 from pypy.rpython.lltypesystem.lltype import Bool, typeOf, Void
 from pypy.rpython import rmodel
 from pypy.tool.algo import sparsemat
@@ -199,9 +200,8 @@
                         index = afterblock.inputargs.index(arg)
                         linkargs.append(passon_vars[block][index - 1])
                 return linkargs
-            exc_match = Constant(rmodel.getfunctionptr(
-                translator,
-                translator.rtyper.getexceptiondata().ll_exception_match))
+            exc_match = Constant(LowLevelTypeSystem.instance.getcallable(
+                translator.rtyper.getexceptiondata().ll_exception_match_graph))
             exc_match.concretetype = typeOf(exc_match.value)
             #try to match the exceptions for simple cases
             for link in entrymap[graph_to_inline.exceptblock]:

Modified: pypy/branch/somepbc-refactoring/pypy/translator/backendopt/removenoops.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/backendopt/removenoops.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/backendopt/removenoops.py	Mon Nov 28 19:52:25 2005
@@ -50,19 +50,16 @@
 
 
 def remove_void(translator):
-    for func, graph in translator.flowgraphs.iteritems():
+    for graph in translator.graphs:
         args = [arg for arg in graph.startblock.inputargs
                     if arg.concretetype is not Void]
         graph.startblock.inputargs = args
-    def visit(block): 
-        if isinstance(block, Block):
+        for block in graph.iterblocks():
             for op in block.operations:
                 if op.opname == 'direct_call':
                     args = [arg for arg in op.args
                                 if arg.concretetype is not Void]
                     op.args = args
-    for func, graph in translator.flowgraphs.iteritems():
-        traverse(visit, graph)
  
 ##def rename_extfunc_calls(translator):
 ##    from pypy.rpython.extfunctable import table as extfunctable

Modified: pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_all.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_all.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_all.py	Mon Nov 28 19:52:25 2005
@@ -1,7 +1,7 @@
 import py
 from pypy.translator.backendopt.all import backend_optimizations
 from pypy.translator.backendopt.test.test_malloc import check_malloc_removed
-from pypy.translator.translator import Translator
+from pypy.translator.translator import Translator, graphof
 from pypy.objspace.flow.model import Constant
 from pypy.annotation import model as annmodel
 from pypy.rpython.llinterp import LLInterpreter
@@ -45,11 +45,11 @@
     t.specialize()
     backend_optimizations(t, inline_threshold=100, mallocs=True)
 
-    graph = t.getflowgraph()
-    check_malloc_removed(graph)
+    big_graph = graphof(t, big)
+    check_malloc_removed(big_graph)
 
-    interp = LLInterpreter(t.flowgraphs, t.rtyper)
-    res = interp.eval_function(big, [])
+    interp = LLInterpreter(t.rtyper)
+    res = interp.eval_graph(big_graph, [])
     assert res == 83
 
 
@@ -66,11 +66,11 @@
     t.backend_optimizations(inline_threshold=1, mallocs=True)
     # this also checks that the BASE_INLINE_THRESHOLD is enough for 'for' loops
 
-    graph = t.getflowgraph()
-    check_malloc_removed(graph)
+    f_graph = graph = graphof(t, f)
+    check_malloc_removed(f_graph)
 
-    interp = LLInterpreter(t.flowgraphs, t.rtyper)
-    res = interp.eval_function(f, [11])
+    interp = LLInterpreter(t.rtyper)
+    res = interp.eval_graph(f_graph, [11])
     assert res == 55
 
 
@@ -83,11 +83,11 @@
     t.specialize()
     t.backend_optimizations(inline_threshold=10, mallocs=True)
 
-    graph = t.getflowgraph()
-    check_malloc_removed(graph)
+    f_graph = graphof(t, f)
+    check_malloc_removed(f_graph)
 
-    interp = LLInterpreter(t.flowgraphs, t.rtyper)
-    res = interp.eval_function(f, [11, 22])
+    interp = LLInterpreter(t.rtyper)
+    res = interp.eval_graph(f_graph, [11, 22])
     assert res == 33
 
 def test_premature_death():
@@ -115,14 +115,14 @@
     t.specialize()
     t.backend_optimizations(inline_threshold=1, mallocs=True)
 
-    graph = t.getflowgraph()
+    entry_point_graph = graphof(t, entry_point)
 
     from pypy.rpython.module.support import to_rstr
 
     argv = t.rtyper.getrepr(inputtypes[0]).convert_const(['./pypy-c'])
 
-    interp = LLInterpreter(t.flowgraphs, t.rtyper)
-    interp.eval_function(entry_point, [argv])
+    interp = LLInterpreter(t.rtyper)
+    interp.eval_graph(entry_point_graph, [argv])
 
     
 

Modified: pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_inline.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_inline.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_inline.py	Mon Nov 28 19:52:25 2005
@@ -1,3 +1,4 @@
+# XXX clean up these tests to use more uniform helpers
 import py
 import os
 from pypy.objspace.flow.model import traverse, Block, Link, Variable, Constant
@@ -6,7 +7,7 @@
 from pypy.translator.backendopt.inline import auto_inlining
 from pypy.translator.backendopt.inline import collect_called_functions
 from pypy.translator.backendopt.inline import measure_median_execution_cost
-from pypy.translator.translator import Translator
+from pypy.translator.translator import Translator, TranslationContext, graphof
 from pypy.rpython.llinterp import LLInterpreter
 from pypy.rpython.rarithmetic import ovfcheck
 from pypy.translator.test.snippet import is_perfect_number
@@ -31,7 +32,7 @@
 
 def sanity_check(t):
     # look for missing '.concretetype'
-    for graph in t.flowgraphs.values():
+    for graph in t.graphs:
         checkgraph(graph)
         traverse(no_missing_concretetype, graph)
 
@@ -42,10 +43,14 @@
     t.specialize()
     # inline!
     sanity_check(t)    # also check before inlining (so we don't blame it)
-    inline_function(t, func, t.flowgraphs[in_func])
+    in_func_graph = graphof(t, in_func)
+    func_graph = graphof(t, func)
+    inline_function(t, func, in_func_graph)
     sanity_check(t)
-    interp = LLInterpreter(t.flowgraphs, t.rtyper)
-    return interp
+    interp = LLInterpreter(t.rtyper)
+    def eval_func(args):
+        return interp.eval_graph(in_func_graph, args)
+    return eval_func
 
 
 def test_inline_simple():
@@ -56,10 +61,10 @@
             return x * y
         else:
             return -x * y
-    interp = check_inline(g, f, [int, int])
-    result = interp.eval_function(f, [-1, 5])
+    eval_func = check_inline(g, f, [int, int])
+    result = eval_func([-1, 5])
     assert result == f(-1, 5)
-    result = interp.eval_function(f, [2, 12])
+    result = eval_func([2, 12])
     assert result == f(2, 12)
 
 def test_inline_big():
@@ -69,8 +74,8 @@
             if is_perfect_number(i):
                 result.append(i)
         return result
-    interp = check_inline(is_perfect_number, f, [int])
-    result = interp.eval_function(f, [10])
+    eval_func = check_inline(is_perfect_number, f, [int])
+    result = eval_func([10])
     assert result.length == len(f(10))
 
 def test_inline_raising():
@@ -95,14 +100,15 @@
     a.simplify()
     t.specialize()
     sanity_check(t)    # also check before inlining (so we don't blame it)
-    inline_function(t, f, t.flowgraphs[g])
+    inline_function(t, f, graphof(t, g))
     sanity_check(t)
-    interp = LLInterpreter(t.flowgraphs, t.rtyper)
-    result = interp.eval_function(h, [0])
+    interp = LLInterpreter(t.rtyper)
+    h_graph = graphof(t, h)
+    result = interp.eval_graph(h_graph, [0])
     assert result == 0
-    result = interp.eval_function(h, [1])
+    result = interp.eval_graph(h_graph, [1])
     assert result == 1
-    result = interp.eval_function(h, [2])
+    result = interp.eval_graph(h_graph, [2])
     assert result == 2    
 
 def test_inline_several_times():
@@ -114,10 +120,10 @@
         else:
             a = f(x) + 1
         return a + f(x)
-    interp = check_inline(f, g, [int])
-    result = interp.eval_function(g, [0])
+    eval_func = check_inline(f, g, [int])
+    result = eval_func([0])
     assert result == g(0)
-    result = interp.eval_function(g, [42])
+    result = eval_func([42])
     assert result == g(42)
 
 def test_inline_exceptions():
@@ -134,12 +140,12 @@
         except KeyError:
             return x+2
         return 1
-    interp = check_inline(f, g, [int])
-    result = interp.eval_function(g, [0])
+    eval_func = check_inline(f, g, [int])
+    result = eval_func([0])
     assert result == 2
-    result = interp.eval_function(g, [1])
+    result = eval_func([1])
     assert result == 3
-    result = interp.eval_function(g, [42])
+    result = eval_func([42])
     assert result == 1
 
 def test_inline_var_exception():
@@ -164,14 +170,15 @@
     a.simplify()
     t.specialize()
     auto_inlining(t, threshold=10)
-    for graph in t.flowgraphs.values():
+    for graph in t.graphs:
         traverse(no_missing_concretetype, graph)
-    interp = LLInterpreter(t.flowgraphs, t.rtyper)
-    result = interp.eval_function(g, [0])
+    interp = LLInterpreter(t.rtyper)
+    g_graph = graphof(t, g)
+    result = interp.eval_graph(g_graph, [0])
     assert result == 2
-    result = interp.eval_function(g, [1])
+    result = interp.eval_graph(g_graph, [1])
     assert result == 3
-    result = interp.eval_function(g, [42])
+    result = interp.eval_graph(g_graph, [42])
     assert result == 1
 
 def test_inline_nonraising_into_catching():
@@ -182,8 +189,8 @@
             return f(x)
         except KeyError:
             return 42
-    interp = check_inline(f, g, [int])
-    result = interp.eval_function(g, [7654])
+    eval_func = check_inline(f, g, [int])
+    result = eval_func([7654])
     assert result == 7655
 
 def DONOTtest_call_call():
@@ -224,16 +231,16 @@
     a = t.annotate([int])
     a.simplify()
     t.specialize()
-    for graph in t.flowgraphs.values():
+    for graph in t.graphs:
         if graph.name.startswith('ll_rangenext'):
             break
     else:
         assert 0, "cannot find ll_rangenext_*() function"
     sanity_check(t)    # also check before inlining (so we don't blame it)
-    inline_function(t, graph, t.flowgraphs[f])
+    inline_function(t, graph, graphof(t, f))
     sanity_check(t)
-    interp = LLInterpreter(t.flowgraphs, t.rtyper)
-    result = interp.eval_function(f, [10])
+    interp = LLInterpreter(t.rtyper)
+    result = interp.eval_graph(graphof(t, f), [10])
     assert result == 45
 
 def test_inline_constructor():
@@ -245,8 +252,8 @@
     def f(i):
         a = A(117, i)
         return a.area()
-    interp = check_inline(A.__init__.im_func, f, [int])
-    result = interp.eval_function(f, [120])
+    eval_func = check_inline(A.__init__.im_func, f, [int])
+    result = eval_func([120])
     assert result == 30
 
 def test_cannot_inline_recursive_function():
@@ -281,11 +288,12 @@
     a.simplify()
     t.specialize()
     auto_inlining(t, threshold=10)
-    assert len(collect_called_functions(t.getflowgraph(f))) == 0
-    interp = LLInterpreter(t.flowgraphs, t.rtyper)
-    result = interp.eval_function(f, [10])
+    f_graph = graphof(t, f)
+    assert len(collect_called_functions(f_graph)) == 0
+    interp = LLInterpreter(t.rtyper)
+    result = interp.eval_graph(f_graph, [10])
     assert result == 45
-    result = interp.eval_function(f, [15])
+    result = interp.eval_graph(f_graph, [15])
     assert result == -1
 
 def test_inline_exception_catching():
@@ -300,8 +308,8 @@
             return False
     def f():
         return f2()
-    interp = check_inline(f2, f, [])
-    result = interp.eval_function(f, [])
+    eval_func = check_inline(f2, f, [])
+    result = eval_func([])
     assert result is True
 
 def test_inline_catching_different_exception():
@@ -316,8 +324,8 @@
             return f2(n)
         except ValueError:
             return -1
-    interp = check_inline(f2, f, [int])
-    result = interp.eval_function(f, [54])
+    eval_func = check_inline(f2, f, [int])
+    result = eval_func([54])
     assert result == 55
 
 def test_auto_inline_os_path_isdir():
@@ -329,8 +337,8 @@
     a.simplify()
     t.specialize()
     auto_inlining(t)
-    interp = LLInterpreter(t.flowgraphs, t.rtyper)
-    result = interp.eval_function(f, [])
+    interp = LLInterpreter(t.rtyper)
+    result = interp.eval_graph(graphof(t, f), [])
     assert result is True
 
 def test_inline_raiseonly():
@@ -341,8 +349,8 @@
             return f2(x)
         except KeyError:
             return 42
-    interp = check_inline(f2, f, [int])
-    result = interp.eval_function(f, [98371])
+    eval_func = check_inline(f2, f, [int])
+    result = eval_func([98371])
     assert result == 42
 
 def test_measure_median_execution_cost():
@@ -362,6 +370,7 @@
             x += 1
         x += 1
         return x
-    t = Translator(f)
-    res = measure_median_execution_cost(t.getflowgraph())
+    t = TranslationContext()
+    graph = t.buildflowgraph(f)
+    res = measure_median_execution_cost(graph)
     assert res == 19

Modified: pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_malloc.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_malloc.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_malloc.py	Mon Nov 28 19:52:25 2005
@@ -1,6 +1,6 @@
 from pypy.translator.backendopt.malloc import remove_simple_mallocs
 from pypy.translator.backendopt.inline import inline_function
-from pypy.translator.translator import Translator
+from pypy.translator.translator import Translator, graphof
 from pypy.objspace.flow.model import checkgraph, flatten, Block
 from pypy.rpython.llinterp import LLInterpreter
 
@@ -21,12 +21,12 @@
     t = Translator(fn)
     t.annotate(signature)
     t.specialize()
-    graph = t.getflowgraph()
+    graph = graphof(t, fn)
     remove_simple_mallocs(graph)
     if must_be_removed:
         check_malloc_removed(graph)
-    interp = LLInterpreter(t.flowgraphs, t.rtyper)
-    res = interp.eval_function(fn, args)
+    interp = LLInterpreter(t.rtyper)
+    res = interp.eval_graph(graph, args)
     assert res == expected_result
 
 

Modified: pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_propagate.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_propagate.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_propagate.py	Mon Nov 28 19:52:25 2005
@@ -1,4 +1,4 @@
-from pypy.translator.translator import Translator
+from pypy.translator.translator import Translator, graphof
 from pypy.translator.backendopt.propagate import *
 from pypy.rpython.llinterp import LLInterpreter
 
@@ -8,12 +8,12 @@
     t.annotate(signature)
     t.specialize()
     t.backend_optimizations(ssa_form=False, propagate=False) 
-    graph = t.getflowgraph()
+    graph = graphof(t, fn)
     return graph, t
 
 def check_graph(graph, args, expected_result, t):
-    interp = LLInterpreter(t.flowgraphs, t.rtyper)
-    res = interp.eval_function(None, args, graph=graph)
+    interp = LLInterpreter(t.rtyper)
+    res = interp.eval_graph(graph, args)
     assert res == expected_result
 
 def check_get_graph(fn, signature, args, expected_result):

Modified: pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_removenoops.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_removenoops.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_removenoops.py	Mon Nov 28 19:52:25 2005
@@ -1,6 +1,6 @@
 from pypy.translator.backendopt.removenoops import remove_void, remove_same_as
 from pypy.translator.backendopt.inline import inline_function
-from pypy.translator.translator import Translator
+from pypy.translator.translator import Translator, graphof
 from pypy.translator.test.snippet import simple_method
 from pypy.objspace.flow.model import checkgraph, flatten, Block
 from pypy.rpython.lltypesystem.lltype import Void
@@ -21,19 +21,18 @@
     def f(i):
         return [1,2,3,i][i]
     t = annotate_and_remove_void(f, [int])
-    for func, graph in t.flowgraphs.iteritems():
+    for graph in t.graphs:
         assert checkgraph(graph) is None
         for arg in graph.startblock.inputargs:
             assert arg.concretetype is not Void
-    interp = LLInterpreter(t.flowgraphs, t.rtyper)
-    assert interp.eval_function(f, [0]) == 1 
+    interp = LLInterpreter(t.rtyper)
+    assert interp.eval_graph(graphof(t, f), [0]) == 1 
 
 def test_remove_void_in_struct():
     t = annotate_and_remove_void(simple_method, [int])
     #t.view()
-    log(t.flowgraphs.iteritems())
-    for func, graph in t.flowgraphs.iteritems():
-        log('func : ' + str(func))
+    for graph in t.graphs:
+        log('func : ' + graph.name)
         log('graph: ' + str(graph))
         assert checkgraph(graph) is None
         #for fieldname in self.struct._names:    #XXX helper (in lltype?) should remove these voids
@@ -56,15 +55,15 @@
     a = t.annotate([])
     t.specialize()
     # now we make the 'if True' appear
-    inline_function(t, nothing, t.flowgraphs[f])
+    f_graph = graphof(t, f)
+    inline_function(t, nothing, f_graph)
     # here, the graph looks like  v21=same_as(True);  exitswitch: v21
-    remove_same_as(t.flowgraphs[f])
+    remove_same_as(f_graph)
     t.checkgraphs()
     # only one path should be left
-    for node in flatten(t.flowgraphs[f]):
-        if isinstance(node, Block):
-            assert len(node.exits) <= 1
+    for block in f_graph.iterblocks():
+        assert len(block.exits) <= 1
 
-    interp = LLInterpreter(t.flowgraphs, t.rtyper)
-    result = interp.eval_function(f, [])
+    interp = LLInterpreter(t.rtyper)
+    result = interp.eval_graph(f_graph, [])
     assert result == 42

Modified: pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_ssa.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_ssa.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_ssa.py	Mon Nov 28 19:52:25 2005
@@ -1,5 +1,5 @@
 from pypy.translator.backendopt.ssa import *
-from pypy.translator.translator import Translator
+from pypy.translator.translator import TranslationContext
 from pypy.objspace.flow.model import flatten, Block
 
 
@@ -11,12 +11,11 @@
             else:
                 yy = yy + xx
         return yy
-    t = Translator(snippet_fn)
-    graph = t.getflowgraph()
+    t = TranslationContext()
+    graph = t.buildflowgraph(snippet_fn)
     operations = []
-    for block in flatten(graph):
-        if isinstance(block, Block):
-            operations += block.operations
+    for block in graph.iterblocks():
+        operations += block.operations
 
     variable_families = DataFlowFamilyBuilder(graph).get_variable_families()
 
@@ -42,11 +41,11 @@
         v7 = passed_over                   # v7 = inputarg
         return v7+v1                       # v8 = add(v7, v1)
 
-    t = Translator(snippet_fn)
-    SSI_to_SSA(t.getflowgraph())
+    t = TranslationContext()
+    graph = t.buildflowgraph(snippet_fn)
+    SSI_to_SSA(graph)
     allvars = []
-    for block in flatten(t.getflowgraph()):
-        if isinstance(block, Block):
+    for block in graph.iterblocks():
             allvars += [v.name for v in block.getvariables()]
     # see comments above for where the 8 remaining variables are expected to be
     assert len(dict.fromkeys(allvars)) == 8

Modified: pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_tailrecursion.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_tailrecursion.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/backendopt/test/test_tailrecursion.py	Mon Nov 28 19:52:25 2005
@@ -1,6 +1,6 @@
 from pypy.objspace.flow.model import traverse, Block, Link, Variable, Constant
 from pypy.translator.backendopt.tailrecursion import remove_tail_calls_to_self
-from pypy.translator.translator import Translator
+from pypy.translator.translator import Translator, graphof
 from pypy.rpython.llinterp import LLInterpreter
 from pypy.translator.test.snippet import is_perfect_number
 
@@ -14,7 +14,8 @@
     t = Translator(gcd)
     a = t.annotate([int, int])
     t.specialize()
-    remove_tail_calls_to_self(t, t.flowgraphs[gcd])
-    lli = LLInterpreter(t.flowgraphs, t.rtyper)
-    res = lli.eval_function(gcd, (15, 25))
+    gcd_graph = graphof(t, gcd)
+    remove_tail_calls_to_self(t, gcd_graph )
+    lli = LLInterpreter(t.rtyper)
+    res = lli.eval_graph(gcd_graph, (15, 25))
     assert res == 5



More information about the Pypy-commit mailing list