def inline_malloc_removal_phase(config, translator, graphs, inline_threshold, inline_heuristic, call_count_pred=None): type_system = translator.rtyper.type_system.name # 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) 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, type_system) if config.print_statistics: print "after malloc removal:" print_statistics(translator.graphs[0], translator)
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 pypy.translator.backendopt import malloc, inline inline.auto_inlining(t, 20) malloc.remove_mallocs(t, t.graphs) from pypy.translator import simplify simplify.join_blocks(graph)
def finish_helpers(self, **kwds): GCTransformer.finish_helpers(self, **kwds) from pypy.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)