Esempio n. 1
0
def find_malloc_removal_candidates(t, graphs):
    adi = AbstractDataFlowInterpreter(t)
    for graph in graphs:
        if graph.startblock not in adi.flown_blocks:
            adi.schedule_function(graph)
            adi.complete()
    malloc_graphs = malloc_like_graphs(adi)
    targetset = dict.fromkeys(graphs)
    caller_candidates = {}
    seen = {}
    for graph in adi.seen_graphs():
        creps = find_malloc_creps(graph, adi, t, malloc_graphs)
        if creps:
            find_calls_where_creps_go(creps, graph, adi, t, seen)
            if creps:
                if graph in targetset:
                    caller_candidates[graph] = True
    callgraph = []
    for called_graph, callers in seen.iteritems():
        for caller in callers:
            if caller in targetset and called_graph in targetset:
                callgraph.append((caller, called_graph))
            else:
                log.inlineandremove.WARNING("would like to inline into"
                                            " out of target set: %r" % caller)
    return callgraph, caller_candidates
Esempio n. 2
0
def find_malloc_removal_candidates(t, graphs):
    adi = AbstractDataFlowInterpreter(t)
    for graph in graphs:
        if graph.startblock not in adi.flown_blocks:
            adi.schedule_function(graph)
            adi.complete()
    malloc_graphs = malloc_like_graphs(adi)
    targetset = dict.fromkeys(graphs)
    caller_candidates = {}
    seen = {}
    for graph in adi.seen_graphs():
        creps = find_malloc_creps(graph, adi, t, malloc_graphs)
        if creps:
            find_calls_where_creps_go(creps, graph, adi, t, seen)
            if creps:
                if graph in targetset:
                    caller_candidates[graph] = True
    callgraph = []
    for called_graph, callers in seen.iteritems():
        for caller in callers:
            if caller in targetset and called_graph in targetset:
                callgraph.append((caller, called_graph))
            else:
                log.inlineandremove.WARNING("would like to inline into"
                                            " out of target set: %r"
                                            % caller)
    return callgraph, caller_candidates
Esempio n. 3
0
def test_find_malloc_like_graphs():
    class A(object):
        pass
    def f(x):
        a = A()
        a.x = x
        return a

    def g(a):
        return a

    def h(x):
        return f(x + 1)
    def main(x):
        return f(x).x + g(h(x)).x

    t, adi, graph = build_adi(main, [int])
    graphs = malloc_like_graphs(adi)
    assert set([g.name for g in graphs]) == set(["f", "h"])
Esempio n. 4
0
def test_find_malloc_like_graphs():
    class A(object):
        pass

    def f(x):
        a = A()
        a.x = x
        return a

    def g(a):
        return a

    def h(x):
        return f(x + 1)

    def main(x):
        return f(x).x + g(h(x)).x

    t, adi, graph = build_adi(main, [int])
    graphs = malloc_like_graphs(adi)
    assert set([g.name for g in graphs]) == set(["f", "h"])