Пример #1
0
    def remove_obvious_noops():
        for graph in graphs:
            removenoops.remove_same_as(graph)
            simplify.eliminate_empty_blocks(graph)
            simplify.transform_dead_op_vars(graph, translator)
            removenoops.remove_duplicate_casts(graph, translator)

        if config.print_statistics:
            print "after no-op removal:"
            print_statistics(translator.graphs[0], translator)
Пример #2
0
    def remove_obvious_noops():
        for graph in graphs:
            removenoops.remove_same_as(graph)
            simplify.eliminate_empty_blocks(graph)
            simplify.transform_dead_op_vars(graph, translator)
            removenoops.remove_duplicate_casts(graph, translator)

        if config.print_statistics:
            print "after no-op removal:"
            print_statistics(translator.graphs[0], translator)
Пример #3
0
def clever_inlining_and_malloc_removal(
    translator, graphs=None, threshold=BIG_THRESHOLD, heuristic=inline.inlining_heuristic
):
    if graphs is None:
        graphs = translator.graphs
    count = 0
    while 1:
        newcount = inline_and_remove(translator, graphs, threshold=threshold, heuristic=heuristic)
        if not newcount:
            break
        count += newcount
    for graph in graphs:
        removenoops.remove_duplicate_casts(graph, translator)
    return count
Пример #4
0
def auto_inline_graphs(translator, graphs, threshold, call_count_pred=None,
                       heuristic=inlining_heuristic,
                       inline_graph_from_anywhere=False):
    if inline_graph_from_anywhere:
        # it's ok to inline calls to any graph, with the exception of
        # graphs that would be already exception-transformed
        ok_to_call = set([graph for graph in translator.graphs
                                if not hasattr(graph, 'exceptiontransformed')])
    else:
        ok_to_call = None
    callgraph = inlinable_static_callers(graphs, ok_to_call=ok_to_call)
    count = auto_inlining(translator, threshold, callgraph=callgraph,
                          heuristic=heuristic,
                          call_count_pred=call_count_pred)
    log.inlining('inlined %d callsites.' % (count,))
    for graph in graphs:
        removenoops.remove_duplicate_casts(graph, translator)
Пример #5
0
def auto_inline_graphs(translator, graphs, threshold, call_count_pred=None,
                       heuristic=inlining_heuristic,
                       inline_graph_from_anywhere=False):
    if inline_graph_from_anywhere:
        # it's ok to inline calls to any graph, with the exception of
        # graphs that would be already exception-transformed
        ok_to_call = set([graph for graph in translator.graphs
                                if not hasattr(graph, 'exceptiontransformed')])
    else:
        ok_to_call = None
    callgraph = inlinable_static_callers(graphs, ok_to_call=ok_to_call)
    count = auto_inlining(translator, threshold, callgraph=callgraph,
                          heuristic=heuristic,
                          call_count_pred=call_count_pred)
    log.inlining('inlined %d callsites.' % (count,))
    for graph in graphs:
        removenoops.remove_duplicate_casts(graph, translator)
Пример #6
0
def test_remove_duplicate_casts():
    class A(object):
        def __init__(self, x, y):
            self.x = x
            self.y = y

        def getsum(self):
            return self.x + self.y

    class B(A):
        def __init__(self, x, y, z):
            A.__init__(self, x, y)
            self.z = z

        def getsum(self):
            return self.x + self.y + self.z

    def f(x, switch):
        a = A(x, x + 1)
        b = B(x, x + 1, x + 2)
        if switch:
            c = A(x, x + 1)
        else:
            c = B(x, x + 1, x + 2)
        return a.x + a.y + b.x + b.y + b.z + c.getsum()

    assert f(10, True) == 75
    graph, t = get_graph(f, [int, bool], all_opts=False)
    num_cast_pointer = len(getops(graph)["cast_pointer"])
    changed = remove_duplicate_casts(graph, t)
    assert changed
    ops = getops(graph)
    assert len(ops["cast_pointer"]) < num_cast_pointer
    print len(ops["cast_pointer"]), num_cast_pointer
    graph_getsum = graphof(t, B.getsum.im_func)
    num_cast_pointer = len(getops(graph_getsum)["cast_pointer"])
    changed = remove_duplicate_casts(graph_getsum, t)
    assert changed
    if option.view:
        t.view()
    check_graph(graph, [10, True], 75, t)
    ops = getops(graph_getsum)
    assert len(ops["cast_pointer"]) < num_cast_pointer
    print len(ops["cast_pointer"]), num_cast_pointer
Пример #7
0
def test_remove_duplicate_casts():
    class A(object):
        def __init__(self, x, y):
            self.x = x
            self.y = y

        def getsum(self):
            return self.x + self.y

    class B(A):
        def __init__(self, x, y, z):
            A.__init__(self, x, y)
            self.z = z

        def getsum(self):
            return self.x + self.y + self.z

    def f(x, switch):
        a = A(x, x + 1)
        b = B(x, x + 1, x + 2)
        if switch:
            c = A(x, x + 1)
        else:
            c = B(x, x + 1, x + 2)
        return a.x + a.y + b.x + b.y + b.z + c.getsum()

    assert f(10, True) == 75
    graph, t = get_graph(f, [int, bool], all_opts=False)
    num_cast_pointer = len(getops(graph)['cast_pointer'])
    changed = remove_duplicate_casts(graph, t)
    assert changed
    ops = getops(graph)
    assert len(ops['cast_pointer']) < num_cast_pointer
    print len(ops['cast_pointer']), num_cast_pointer
    graph_getsum = graphof(t, B.getsum.im_func)
    num_cast_pointer = len(getops(graph_getsum)['cast_pointer'])
    changed = remove_duplicate_casts(graph_getsum, t)
    assert changed
    if option.view:
        t.view()
    check_graph(graph, [10, True], 75, t)
    ops = getops(graph_getsum)
    assert len(ops['cast_pointer']) < num_cast_pointer
    print len(ops['cast_pointer']), num_cast_pointer