示例#1
0
def test_replace_exitswitch_by_constant_bug():
    class X:
        pass
    def constant9():
        x = X()
        x.n = 3
        x.n = 9
        return x.n
    def fn():
        n = constant9()
        if n == 1: return 5
        elif n == 2: return 6
        elif n == 3: return 8
        elif n == 4: return -123
        elif n == 5: return 12973
        else: return n
    
    t = TranslationContext()
    a = t.buildannotator()
    a.build_types(fn, [])
    rtyper = t.buildrtyper()
    rtyper.specialize()
    graph = t.graphs[0]
    remove_same_as(graph)
    merge_if_blocks_once(graph)
    from rpython.translator.backendopt import malloc, inline
    inline.auto_inlining(t, 20)
    malloc.remove_mallocs(t, t.graphs)
    from rpython.translator import simplify
    simplify.join_blocks(graph)
示例#2
0
文件: all.py 项目: abhinavthomas/pypy
def inline_malloc_removal_phase(config, translator, graphs, inline_threshold,
                                inline_heuristic,
                                call_count_pred=None,
                                inline_graph_from_anywhere=False):
    # inline functions in each other
    if inline_threshold:
        log.inlining("phase with threshold factor: %s" % inline_threshold)
        log.inlining("heuristic: %s.%s" % (inline_heuristic.__module__,
                                           inline_heuristic.__name__))

        inline.auto_inline_graphs(translator, graphs, inline_threshold,
                                  heuristic=inline_heuristic,
                                  call_count_pred=call_count_pred,
                         inline_graph_from_anywhere=inline_graph_from_anywhere)

        if config.print_statistics:
            print "after inlining:"
            print_statistics(translator.graphs[0], translator)

    # vaporize mallocs
    if config.mallocs:
        log.malloc("starting malloc removal")
        remove_mallocs(translator, graphs)

        if config.print_statistics:
            print "after malloc removal:"
            print_statistics(translator.graphs[0], translator)
示例#3
0
def test_replace_exitswitch_by_constant_bug():
    class X:
        pass

    def constant9():
        x = X()
        x.n = 3
        x.n = 9
        return x.n

    def fn():
        n = constant9()
        if n == 1: return 5
        elif n == 2: return 6
        elif n == 3: return 8
        elif n == 4: return -123
        elif n == 5: return 12973
        else: return n

    t = TranslationContext()
    a = t.buildannotator()
    a.build_types(fn, [])
    rtyper = t.buildrtyper()
    rtyper.specialize()
    graph = t.graphs[0]
    remove_same_as(graph)
    merge_if_blocks_once(graph)
    from rpython.translator.backendopt import malloc, inline
    inline.auto_inlining(t, 20)
    malloc.remove_mallocs(t, t.graphs)
    from rpython.translator import simplify
    simplify.join_blocks(graph)
示例#4
0
def inline_malloc_removal_phase(config, translator, graphs, inline_threshold,
                                inline_heuristic,
                                call_count_pred=None,
                                inline_graph_from_anywhere=False):
    # inline functions in each other
    if inline_threshold:
        log.inlining("phase with threshold factor: %s" % inline_threshold)
        log.inlining("heuristic: %s.%s" % (inline_heuristic.__module__,
                                           inline_heuristic.__name__))

        inline.auto_inline_graphs(translator, graphs, inline_threshold,
                                  heuristic=inline_heuristic,
                                  call_count_pred=call_count_pred,
                         inline_graph_from_anywhere=inline_graph_from_anywhere)

        if config.print_statistics:
            print "after inlining:"
            print_statistics(translator.graphs[0], translator)

    # vaporize mallocs
    if config.mallocs:
        log.malloc("starting malloc removal")
        remove_mallocs(translator, graphs)

        if config.print_statistics:
            print "after malloc removal:"
            print_statistics(translator.graphs[0], translator)
示例#5
0
 def finish_helpers(self, **kwds):
     GCTransformer.finish_helpers(self, **kwds)
     from rpython.translator.backendopt.malloc import remove_mallocs
     seen = {}
     graphs = []
     for fptr in self.static_deallocator_funcptrs.itervalues():
         graph = fptr._obj.graph
         if graph in seen:
             continue
         seen[graph] = True
         graphs.append(graph)
     remove_mallocs(self.translator, graphs)
示例#6
0
 def finish_helpers(self, **kwds):
     GCTransformer.finish_helpers(self, **kwds)
     from rpython.translator.backendopt.malloc import remove_mallocs
     seen = {}
     graphs = []
     for fptr in self.static_deallocator_funcptrs.itervalues():
         graph = fptr._obj.graph
         if graph in seen:
             continue
         seen[graph] = True
         graphs.append(graph)
     remove_mallocs(self.translator, graphs)