[pypy-commit] pypy shadowstack-perf-2: Drop in-block sequences of gc_pop_roots/gc_save_root

arigo pypy.commits at gmail.com
Sun May 15 06:10:46 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: shadowstack-perf-2
Changeset: r84454:73acdd2e2ad0
Date: 2016-05-15 12:11 +0200
http://bitbucket.org/pypy/pypy/changeset/73acdd2e2ad0/

Log:	Drop in-block sequences of gc_pop_roots/gc_save_root

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
@@ -367,14 +367,25 @@
     """gc_pop_roots => series of gc_restore_root; this is done after
     move_pushes_earlier() because that one doesn't work correctly if
     a completely-empty gc_pop_roots is removed.
+
+    Also notice in-block code sequences like gc_pop_roots(v) followed
+    by a gc_save_root(v), and drop the gc_save_root.
     """
+    drop = {}
     for block in graph.iterblocks():
         any_change = False
         newops = []
         for op in block.operations:
             if op.opname == 'gc_pop_roots':
-                newops += expand_one_pop_roots(regalloc, op.args)
+                expanded = list(expand_one_pop_roots(regalloc, op.args))
+                drop = {}
+                for op1 in expanded:
+                    drop[op1.args[1]] = op1.args[0].value
+                newops += expanded
                 any_change = True
+            elif (op.opname == 'gc_save_root' and
+                      drop.get(op.args[1]) == op.args[0].value):
+                any_change = True    # kill the operation
             else:
                 newops.append(op)
         if any_change:
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
@@ -362,3 +362,25 @@
         'int_sub': 1,
         'direct_call': 2,
         }
+
+def test_remove_intrablock_push_roots():
+    def g(a):
+        pass
+    def f(a, b):
+        llop.gc_push_roots(lltype.Void, b)
+        g(a)
+        llop.gc_pop_roots(lltype.Void, b)
+        llop.gc_push_roots(lltype.Void, b)
+        g(a)
+        llop.gc_pop_roots(lltype.Void, b)
+        return b
+
+    graph = make_graph(f, [int, llmemory.GCREF])
+    regalloc = allocate_registers(graph)
+    expand_push_roots(graph, regalloc)
+    expand_pop_roots(graph, regalloc)
+    assert graphmodel.summary(graph) == {
+        'gc_save_root': 1,
+        'gc_restore_root': 2,
+        'direct_call': 2,
+        }


More information about the pypy-commit mailing list