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)
def remove_mallocs(translator, graphs=None): if graphs is None: graphs = translator.graphs tot = 0 for graph in graphs: count = remove_simple_mallocs(graph, verbose=translator.config.translation.verbose) if count: # remove typical leftovers from malloc removal removenoops.remove_same_as(graph) simplify.eliminate_empty_blocks(graph) simplify.transform_dead_op_vars(graph, translator) tot += count log.malloc("removed %d simple mallocs in total" % tot) return tot
def remove_simple_mallocs(self, graph): """Iteratively remove (inline) the mallocs that can be simplified away.""" tot = 0 while True: count = self.remove_mallocs_once(graph) if count: if self.verbose: log.malloc('%d simple mallocs removed in %r' % (count, graph.name)) else: log.dot() tot += count else: break return tot