Beispiel #1
0
def find_direct_dominated_preds(blocks, dominator, dom_frontier_node):
    preds = {successors(block[-1]): name for name, block in blocks.items()}
    succ = {name: successors(block[-1]) for name, block in blocks.items()}
    dom = get_dom(succ, list(blocks.keys())[0])

    results = set()
    for pred in preds[dom_frontier_node]:
        if pred in dom[dominator]:
            results.add(pred)
    return results
Beispiel #2
0
def to_ssa(bril):
    for func in bril['functions']:
        blocks = block_map(form_blocks(func['instrs']))
        add_terminators(blocks)
        succ = {
            name: block_successors(block)
            for name, block in blocks.items()
        }

        # dom maps each node to the nodes that dominate it
        dom = get_dom(succ, list(blocks.keys())[0])

        frontiers = get_frontiers(blocks, dom)
        insert_phi_nodes(blocks, frontiers)
Beispiel #3
0
def func_to_ssa(func):
    blocks = block_map(form_blocks(func['instrs']))
    add_entry(blocks)
    add_terminators(blocks)
    succ = {name: successors(block[-1]) for name, block in blocks.items()}
    dom = get_dom(succ, list(blocks.keys())[0])

    df = dom_fronts(dom, succ)
    defs = def_blocks(blocks)
    types = get_types(func)
    arg_names = {a['name'] for a in func['args']} if 'args' in func else set()

    phis = get_phis(blocks, df, defs)
    phi_args, phi_dests = ssa_rename(blocks, phis, succ, dom_tree(dom),
                                     arg_names)
    insert_phis(blocks, phi_args, phi_dests, types)

    func['instrs'] = reassemble(blocks)
Beispiel #4
0
def dom_frontier(blocks):
    succ = {name: successors(block[-1]) for name, block in blocks.items()}
    dom = get_dom(succ, list(blocks.keys())[0])
    return dom_fronts(dom, succ)