示例#1
0
    def create_exception_handling(self, graph, always_exc_clear=False):
        """After an exception in a direct_call (or indirect_call), that is not caught
        by an explicit
        except statement, we need to reraise the exception. So after this
        direct_call we need to test if an exception had occurred. If so, we return
        from the current graph with a special value (False/-1/-1.0/null).
        Because of the added exitswitch we need an additional block.
        """
        if hasattr(graph, 'exceptiontransformed'):
            assert self.same_obj(self.exc_data_ptr, graph.exceptiontransformed)
            return
        else:
            self.raise_analyzer.analyze_direct_call(graph)
            graph.exceptiontransformed = self.exc_data_ptr

        self.always_exc_clear = always_exc_clear
        join_blocks(graph)
        # collect the blocks before changing them
        n_need_exc_matching_blocks = 0
        n_gen_exc_checks           = 0
        for block in list(graph.iterblocks()):
            self.replace_stack_unwind(block)
            self.replace_fetch_restore_operations(block)
            need_exc_matching, gen_exc_checks = self.transform_block(graph, block)
            n_need_exc_matching_blocks += need_exc_matching
            n_gen_exc_checks           += gen_exc_checks
        self.transform_except_block(graph, graph.exceptblock)
        cleanup_graph(graph)
        removenoops.remove_superfluous_keep_alive(graph)
        return n_need_exc_matching_blocks, n_gen_exc_checks
示例#2
0
    def create_exception_handling(self, graph, always_exc_clear=False):
        """After an exception in a direct_call (or indirect_call), that is not caught
        by an explicit
        except statement, we need to reraise the exception. So after this
        direct_call we need to test if an exception had occurred. If so, we return
        from the current graph with a special value (False/-1/-1.0/null).
        Because of the added exitswitch we need an additional block.
        """
        if hasattr(graph, 'exceptiontransformed'):
            assert self.same_obj(self.exc_data_ptr, graph.exceptiontransformed)
            return
        else:
            self.raise_analyzer.analyze_direct_call(graph)
            graph.exceptiontransformed = self.exc_data_ptr

        self.always_exc_clear = always_exc_clear
        join_blocks(graph)
        # collect the blocks before changing them
        n_need_exc_matching_blocks = 0
        n_gen_exc_checks = 0
        for block in list(graph.iterblocks()):
            self.replace_stack_unwind(block)
            self.replace_fetch_restore_operations(block)
            need_exc_matching, gen_exc_checks = self.transform_block(
                graph, block)
            n_need_exc_matching_blocks += need_exc_matching
            n_gen_exc_checks += gen_exc_checks
        self.transform_except_block(graph, graph.exceptblock)
        cleanup_graph(graph)
        removenoops.remove_superfluous_keep_alive(graph)
        return n_need_exc_matching_blocks, n_gen_exc_checks
示例#3
0
def auto_inline_graphs(translator, graphs, threshold, call_count_pred=None,
                       heuristic=inlining_heuristic):
        callgraph = inlinable_static_callers(graphs)
        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_superfluous_keep_alive(graph)
            removenoops.remove_duplicate_casts(graph, translator)
示例#4
0
文件: inline.py 项目: chyyuu/pygirl
def auto_inline_graphs(translator, graphs, threshold, call_count_pred=None,
                       heuristic=inlining_heuristic):
        callgraph = inlinable_static_callers(graphs)
        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_superfluous_keep_alive(graph)
            removenoops.remove_duplicate_casts(graph, translator)
def test_remove_keepalive():
    S = lltype.GcStruct("s", ("f", lltype.Signed))
    def f():
        s1 = lltype.malloc(S)
        llop.keepalive(lltype.Void, s1)
        s2 = lltype.malloc(S)
        llop.keepalive(lltype.Void, s1)
        llop.keepalive(lltype.Void, s2)
        return lltype.cast_ptr_to_int(s1) + lltype.cast_ptr_to_int(s2)
    graph, t = get_graph(f, [])
    remove_superfluous_keep_alive(graph)
    ops = getops(graph)
    assert len(ops['keepalive']) == 2
示例#6
0
def test_remove_keepalive():
    S = lltype.GcStruct("s", ("f", lltype.Signed))

    def f():
        s1 = lltype.malloc(S)
        llop.keepalive(lltype.Void, s1)
        s2 = lltype.malloc(S)
        llop.keepalive(lltype.Void, s1)
        llop.keepalive(lltype.Void, s2)
        return lltype.cast_ptr_to_int(s1) + lltype.cast_ptr_to_int(s2)

    graph, t = get_graph(f, [])
    remove_superfluous_keep_alive(graph)
    ops = getops(graph)
    assert len(ops['keepalive']) == 2
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_superfluous_keep_alive(graph)
        removenoops.remove_duplicate_casts(graph, translator)
    return count
示例#8
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_superfluous_keep_alive(graph)
        removenoops.remove_duplicate_casts(graph, translator)
    return count