Author: Carl Friedrich Bolz <[email protected]>
Branch: better-storesink
Changeset: r88504:986d2adef586
Date: 2016-11-20 22:59 +0100
http://bitbucket.org/pypy/pypy/changeset/986d2adef586/

Log:    remove the previous storesink (it's fully replaced by the new CSE
        pass)

diff --git a/rpython/translator/backendopt/storesink.py 
b/rpython/translator/backendopt/storesink.py
deleted file mode 100644
--- a/rpython/translator/backendopt/storesink.py
+++ /dev/null
@@ -1,97 +0,0 @@
-
-from rpython.rtyper.lltypesystem.lloperation import llop
-from rpython.flowspace.model import mkentrymap, Variable
-from rpython.translator.backendopt import removenoops
-from rpython.translator import simplify
-
-def has_side_effects(op):
-    if op.opname == 'debug_assert' or op.opname == 'jit_force_virtualizable':
-        return False
-    try:
-        return getattr(llop, op.opname).sideeffects
-    except AttributeError:
-        return True
-
-
-def storesink_graph(graph):
-    """ remove superfluous getfields. use a super-local method: all non-join
-    blocks inherit the heap information from their (single) predecessor
-    """
-    added_some_same_as = False
-    entrymap = mkentrymap(graph)
-
-    # all merge blocks are starting points
-    todo = [(block, None, None) for (block, prev_blocks) in 
entrymap.iteritems()
-                if len(prev_blocks) > 1 or block is graph.startblock]
-
-    visited = 0
-
-    while todo:
-        block, cache, inputlink = todo.pop()
-        visited += 1
-        if cache is None:
-            cache = {}
-
-        if block.operations:
-            changed_block = _storesink_block(block, cache, inputlink)
-            added_some_same_as = changed_block or added_some_same_as
-        for link in block.exits:
-            if len(entrymap[link.target]) == 1:
-                new_cache = _translate_cache(cache, link)
-                todo.append((link.target, new_cache, link))
-
-    assert visited == len(entrymap)
-    if added_some_same_as:
-        removenoops.remove_same_as(graph)
-        simplify.transform_dead_op_vars(graph)
-
-def _translate_cache(cache, link):
-    if link.target.operations == (): # exit or except block:
-        return {}
-    block = link.target
-    local_versions = {var1: var2 for var1, var2 in zip(link.args, 
block.inputargs)}
-    def _translate_arg(arg):
-        if isinstance(arg, Variable):
-            res = local_versions.get(arg, None)
-            if res is None:
-                res = Variable(arg)
-                res.concretetype = arg.concretetype
-                link.args.append(arg)
-                block.inputargs.append(res)
-                local_versions[arg] = res
-            return res
-        else:
-            return arg
-    new_cache = {}
-    for (var, field), res in cache.iteritems():
-        if var in local_versions or not isinstance(var, Variable):
-            new_cache[_translate_arg(var), field] = _translate_arg(res)
-    return new_cache
-
-def _storesink_block(block, cache, inputlink):
-    def clear_cache_for(cache, concretetype, fieldname):
-        for k in cache.keys():
-            if k[0].concretetype == concretetype and k[1] == fieldname:
-                del cache[k]
-
-    added_some_same_as = False
-    for op in block.operations:
-        if op.opname == 'getfield':
-            tup = (op.args[0], op.args[1].value)
-            res = cache.get(tup, None)
-            if res is not None:
-                op.opname = 'same_as'
-                op.args = [res]
-                added_some_same_as = True
-            else:
-                cache[tup] = op.result
-        elif op.opname in ('setarrayitem', 'setinteriorfield', "malloc", 
"malloc_varsize"):
-            pass
-        elif op.opname == 'setfield':
-            target = op.args[0]
-            field = op.args[1].value
-            clear_cache_for(cache, target.concretetype, field)
-            cache[target, field] = op.args[2]
-        elif has_side_effects(op):
-            cache.clear()
-    return added_some_same_as
diff --git a/rpython/translator/backendopt/test/test_storesink.py 
b/rpython/translator/backendopt/test/test_storesink.py
deleted file mode 100644
--- a/rpython/translator/backendopt/test/test_storesink.py
+++ /dev/null
@@ -1,167 +0,0 @@
-
-import py
-from rpython.translator.translator import TranslationContext, graphof
-from rpython.translator.backendopt.storesink import storesink_graph
-from rpython.translator.backendopt import removenoops
-from rpython.flowspace.model import checkgraph
-from rpython.conftest import option
-
-class TestStoreSink(object):
-    def translate(self, func, argtypes):
-        t = TranslationContext()
-        t.buildannotator().build_types(func, argtypes)
-        t.buildrtyper().specialize()
-        return t
-
-    def check(self, f, argtypes, no_getfields=0):
-        t = self.translate(f, argtypes)
-        getfields = 0
-        graph = graphof(t, f)
-        removenoops.remove_same_as(graph)
-        checkgraph(graph)
-        storesink_graph(graph)
-        checkgraph(graph)
-        if option.view:
-            t.view()
-        for block in graph.iterblocks():
-            for op in block.operations:
-                if op.opname == 'getfield':
-                    getfields += 1
-        if no_getfields != getfields:
-            py.test.fail("Expected %d, got %d getfields" %
-                         (no_getfields, getfields))
-
-    def test_infrastructure(self):
-        class A(object):
-            pass
-
-        def f(i):
-            a = A()
-            a.x = i
-            return a.x
-
-        self.check(f, [int], 0)
-
-    def test_simple(self):
-        class A(object):
-            pass
-
-        def f(i):
-            a = A()
-            a.x = i
-            return a.x + a.x
-
-        self.check(f, [int], 0)
-
-    def test_irrelevant_setfield(self):
-        class A(object):
-            pass
-
-        def f(i):
-            a = A()
-            a.x = i
-            one = a.x
-            a.y = 3
-            two = a.x
-            return one + two
-
-        self.check(f, [int], 0)
-
-    def test_relevant_setfield(self):
-        class A(object):
-            pass
-
-        def f(i):
-            a = A()
-            b = A()
-            a.x = i
-            b.x = i + 1
-            one = a.x
-            b.x = i
-            two = a.x
-            return one + two
-
-        self.check(f, [int], 2)
-
-    def test_different_concretetype(self):
-        class A(object):
-            pass
-
-        class B(object):
-            pass
-
-        def f(i):
-            a = A()
-            b = B()
-            a.x = i
-            one = a.x
-            b.x = i + 1
-            two = a.x
-            return one + two
-
-        self.check(f, [int], 0)
-
-    def test_subclass(self):
-        class A(object):
-            pass
-
-        class B(A):
-            pass
-
-        def f(i):
-            a = A()
-            b = B()
-            a.x = i
-            one = a.x
-            b.x = i + 1
-            two = a.x
-            return one + two
-
-        self.check(f, [int], 1)
-
-    def test_bug_1(self):
-        class A(object):
-            pass
-
-        def f(i):
-            a = A()
-            a.cond = i > 0
-            n = a.cond
-            if a.cond:
-                return True
-            return n
-
-        self.check(f, [int], 0)
-
-
-    def test_cfg_splits(self):
-        class A(object):
-            pass
-
-        def f(i):
-            a = A()
-            j = i
-            for i in range(i):
-                a.x = i
-                if i:
-                    j = a.x + a.x
-                else:
-                    j = a.x * 5
-            return j
-
-        self.check(f, [int], 0)
-
-    def test_malloc_does_not_invalidate(self):
-        class A(object):
-            pass
-        class B(object):
-            pass
-
-        def f(i):
-            a = A()
-            a.x = i
-            b = B()
-            return a.x
-
-        self.check(f, [int], 0)
-
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to