File: storesink.py

package info (click to toggle)
pypy 2.4.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 86,992 kB
  • ctags: 170,715
  • sloc: python: 1,030,417; ansic: 43,437; cpp: 5,241; asm: 5,169; sh: 458; makefile: 408; xml: 231; lisp: 45
file content (47 lines) | stat: -rw-r--r-- 1,507 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

from rpython.rtyper.lltypesystem.lloperation import llop
from rpython.translator.backendopt import removenoops

def has_side_effects(op):
    if op.opname == 'debug_assert':
        return False
    try:
        return getattr(llop, op.opname).sideeffects
    except AttributeError:
        return True

def storesink_graph(graph):

    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 block in graph.iterblocks():
        newops = []
        cache = {}
        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']:
                pass
            elif op.opname == 'setfield':
                clear_cache_for(cache, op.args[0].concretetype,
                                op.args[1].value)
            elif has_side_effects(op):
                cache = {}
            newops.append(op)
        if block.operations:
            block.operations = newops

    if added_some_same_as:
        removenoops.remove_same_as(graph)