def allocate_registers(graph): interesting_vars = find_interesting_variables(graph) if not interesting_vars: return None regalloc = perform_register_allocation(graph, interesting_vars.__contains__) assert regalloc.graph is graph regalloc.find_num_colors() return regalloc
def test_loop_1(): def f(a, b): while a > 0: b += a a -= 1 return b t, rtyper, graph = gengraph(f, [int, int], viewbefore=False) regalloc = perform_register_allocation(graph, is_int) num_renamings = check_valid(graph, regalloc, is_int) assert num_renamings == 0
def test_loop_2(): def f(a, b): while a > 0: b += a if b < 10: a, b = b, a a -= 1 return b t, rtyper, graph = gengraph(f, [int, int], viewbefore=False) regalloc = perform_register_allocation(graph, is_int) check_valid(graph, regalloc, is_int)
def perform_register_allocation(graph, kind): checkkind = lambda v: getkind(v.concretetype) == kind return regalloc.perform_register_allocation(graph, checkkind, ListOfKind)