Author: Armin Rigo <ar...@tunes.org> Branch: shadowstack-perf-2 Changeset: r84819:f76ae8307de9 Date: 2016-05-29 19:27 +0200 http://bitbucket.org/pypy/pypy/changeset/f76ae8307de9/
Log: add a test for _fix_graph_after_inlining diff --git a/rpython/memory/gctransform/shadowcolor.py b/rpython/memory/gctransform/shadowcolor.py --- a/rpython/memory/gctransform/shadowcolor.py +++ b/rpython/memory/gctransform/shadowcolor.py @@ -687,6 +687,7 @@ if op.opname == 'gc_push_roots': _fix_graph_after_inlining(graph, block, i) break + checkgraph(graph) def _fix_graph_after_inlining(graph, initial_block, initial_index): op = initial_block.operations.pop(initial_index) @@ -704,8 +705,8 @@ for i in range(start_index, len(block.operations)): op = block.operations[i] if op.opname == 'gc_push_roots': - raise Exception("%r: seems to have inlined another graph " - "which also uses GC roots" % (graph,)) + raise Exception("%r: seems to have inlined inside it another " + "graph which also uses GC roots" % (graph,)) if op.opname == 'gc_pop_roots': # end of the inlined graph, drop gc_pop_roots, keep the tail new_operations += block.operations[i + 1:] diff --git a/rpython/memory/gctransform/test/test_shadowcolor.py b/rpython/memory/gctransform/test/test_shadowcolor.py --- a/rpython/memory/gctransform/test/test_shadowcolor.py +++ b/rpython/memory/gctransform/test/test_shadowcolor.py @@ -4,7 +4,7 @@ from rpython.conftest import option from rpython.memory.gctransform.shadowcolor import * from rpython.flowspace import model as graphmodel -from rpython.translator.simplify import join_blocks +from rpython.translator.simplify import join_blocks, cleanup_graph from hypothesis import given, strategies @@ -669,3 +669,32 @@ add_leave_roots_frame(graph, regalloc) join_blocks(graph) postprocess_double_check(graph, force_frame=True) + +def test_fix_graph_after_inlining(): + # the graph of f looks like it inlined another graph, which itself + # would be "if x > 100: foobar()". The foobar() function is supposed + # to be the big slow-path. + def foobar(): + print 42 + def f(x): + llop.gc_push_roots(lltype.Void, x) + if x > 100: # slow-path + foobar() + llop.gc_pop_roots(lltype.Void, x) + return x + graph = make_graph(f, [int]) + postprocess_inlining(graph) + cleanup_graph(graph) + assert [op.opname for op in graph.startblock.operations] == [ + 'int_gt', 'same_as'] + [fastpath, slowpath] = graph.startblock.exits + assert fastpath.target is graph.returnblock + block2 = slowpath.target + [v] = block2.inputargs + assert block2.operations[0].opname == 'gc_push_roots' + assert block2.operations[0].args == [v] + assert block2.operations[1].opname == 'direct_call' # -> foobar + assert block2.operations[2].opname == 'gc_pop_roots' + assert block2.operations[2].args == [v] + assert len(block2.exits) == 1 + assert block2.exits[0].target is graph.returnblock _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit