# Path: cfgutils.py
# def foreach_inst(cfg, func, **kwargs):
#     def inst_handler(bblock):
#         for inst in bblock.items:
#             func(inst, **kwargs)
#     foreach_bblock_and_subblock(cfg, inst_handler)


from collections import defaultdict
from core import *
from cfgutils import foreach_inst
import xform_expr
import xform_cfg
            my_pos = cfg.pred(next_n).index(n)
            next_bb = cfg[next_n]["val"]
            for inst in next_bb:
                if not is_phi(inst):
                    break
                # +1 because first arg is SFUNC("phi")
                new_reg = rename_reg(inst.args[0].args[my_pos + 1])
                inst.args[0].args[my_pos + 1] = new_reg


def rename_ssa_vars_subscripts(cfg):
    rename_ssa_vars(cfg, False)


def rename_ssa_vars_addrs(cfg):
    rename_ssa_vars(cfg, True)


def verify_ssa(cfg):
    "Verify that structural properties of SSA hold."

    # Step 1: Verify that each var is assigned only once.

    all_defs = set()

    def check_single_assign(inst):
        for d in inst.defs():
            assert d not in all_defs
            all_defs.add(d)


# Path: cfgutils.py
# def foreach_inst(cfg, func, **kwargs):
#     def inst_handler(bblock):
#         for inst in bblock.items:
#             func(inst, **kwargs)
#     foreach_bblock_and_subblock(cfg, inst_handler)


# Path: xform_ssa.py
from collections import defaultdict
from core import *
from cfgutils import foreach_inst
import xform_expr
import xform_cfg

            my_pos = cfg.pred(next_n).index(n)
            next_bb = cfg[next_n]["val"]
            for inst in next_bb:
                if not is_phi(inst):
                    break
                # +1 because first arg is SFUNC("phi")
                new_reg = rename_reg(inst.args[0].args[my_pos + 1])
                inst.args[0].args[my_pos + 1] = new_reg


def rename_ssa_vars_subscripts(cfg):
    rename_ssa_vars(cfg, False)


def rename_ssa_vars_addrs(cfg):
    rename_ssa_vars(cfg, True)


def verify_ssa(cfg):
    "Verify that structural properties of SSA hold."

    # Step 1: Verify that each var is assigned only once.

    all_defs = set()

    def check_single_assign(inst):
        for d in inst.defs():
            assert d not in all_defs
            all_defs.add(d)


    foreach_inst(cfg, check_single_assign)