loopy/schedule/device_mapping.py
def compute_live_temporaries(kernel, schedule):
    """
    Compute live-in and live-out sets for temporary variables.
    """
    live_in = [set() for i in range(len(schedule) + 1)]
    live_out = [set() for i in range(len(schedule))]

    id_to_insn = kernel.id_to_insn
    block_bounds = get_block_boundaries(schedule)

    # {{{ Liveness analysis implementation

    def compute_subrange_liveness(start_idx, end_idx):
        idx = end_idx
        while start_idx <= idx:
            sched_item = schedule[idx]
            if isinstance(sched_item, LeaveLoop):
                start = block_bounds[idx]
                live_in[idx] = live_out[idx] = live_in[idx + 1]
                compute_subrange_liveness(start + 1, idx - 1)
                prev_live_in = live_in[start].copy()
                live_in[start] = live_out[start] = live_in[start + 1]
                # Propagate live values through the loop.
                if live_in[start] != prev_live_in:
                    live_out[idx] |= live_in[start]
                    live_in[idx] = live_out[idx]
                    compute_subrange_liveness(start + 1, idx - 1)
                idx = start - 1

            elif isinstance(sched_item, ReturnFromKernel):
                start = block_bounds[idx]
                live_in[idx] = live_out[idx] = live_in[idx + 1]
                compute_subrange_liveness(start + 1, idx - 1)
                live_in[start] = live_out[start] = live_in[start + 1]
                idx = start - 1

            elif isinstance(sched_item, RunInstruction):
                live_out[idx] = live_in[idx + 1]
                insn = id_to_insn[sched_item.insn_id]
                defs = filter_scalar_temporaries(kernel,
                    get_def_set(insn, include_subscripts=False))
                uses = filter_temporaries(kernel,
                    get_use_set(insn, include_subscripts=False))
                live_in[idx] = (live_out[idx] - defs) | uses
                idx -= 1

            elif isinstance(sched_item, Barrier):
                live_in[idx] = live_out[idx] = live_in[idx + 1]
                idx -= 1
            else:
                raise LoopyError("unexepcted type of schedule item: %s"
                        % type(sched_item).__name__)

    # }}}

    # Compute live variables
    compute_subrange_liveness(0, len(schedule) - 1)
    live_in = live_in[:-1]

    if 0:
        print(kernel)
        print("Live-in values:")
        for i, li in enumerate(live_in):
            print("{}: {}".format(i, ", ".join(li)))
        print("Live-out values:")
        for i, lo in enumerate(live_out):
            print("{}: {}".format(i, ", ".join(lo)))

    # Strip off subscripts.
    live_in = [filter_out_subscripts(li) for li in live_in]
    live_out = [filter_out_subscripts(lo) for lo in live_out]

    return live_in, live_out

    Compute live-in and live-out sets for temporary variables.
    
Compute live-in and live-out sets for temporary variables.
Compute live - in and live - out sets for temporary variables .
def compute_live_temporaries(kernel, schedule):
    live_in = [set() for i in range(len(schedule) + 1)]
    live_out = [set() for i in range(len(schedule))]
    id_to_insn = kernel.id_to_insn
    block_bounds = get_block_boundaries(schedule)
    def compute_subrange_liveness(start_idx, end_idx):
        idx = end_idx
        while start_idx <= idx:
            sched_item = schedule[idx]
            if isinstance(sched_item, LeaveLoop):
                start = block_bounds[idx]
                live_in[idx] = live_out[idx] = live_in[idx + 1]
                compute_subrange_liveness(start + 1, idx - 1)
                prev_live_in = live_in[start].copy()
                live_in[start] = live_out[start] = live_in[start + 1]
                if live_in[start] != prev_live_in:
                    live_out[idx] |= live_in[start]
                    live_in[idx] = live_out[idx]
                    compute_subrange_liveness(start + 1, idx - 1)
                idx = start - 1
            elif isinstance(sched_item, ReturnFromKernel):
                start = block_bounds[idx]
                live_in[idx] = live_out[idx] = live_in[idx + 1]
                compute_subrange_liveness(start + 1, idx - 1)
                live_in[start] = live_out[start] = live_in[start + 1]
                idx = start - 1
            elif isinstance(sched_item, RunInstruction):
                live_out[idx] = live_in[idx + 1]
                insn = id_to_insn[sched_item.insn_id]
                defs = filter_scalar_temporaries(kernel,
                    get_def_set(insn, include_subscripts=False))
                uses = filter_temporaries(kernel,
                    get_use_set(insn, include_subscripts=False))
                live_in[idx] = (live_out[idx] - defs) | uses
                idx -= 1
            elif isinstance(sched_item, Barrier):
                live_in[idx] = live_out[idx] = live_in[idx + 1]
                idx -= 1
            else:
                raise LoopyError("unexepcted type of schedule item: %s"
                        % type(sched_item).__name__)
    compute_subrange_liveness(0, len(schedule) - 1)
    live_in = live_in[:-1]
    if 0:
        print(kernel)
        print("Live-in values:")
        for i, li in enumerate(live_in):
            print("{}: {}".format(i, ", ".join(li)))
        print("Live-out values:")
        for i, lo in enumerate(live_out):
            print("{}: {}".format(i, ", ".join(lo)))
    live_in = [filter_out_subscripts(li) for li in live_in]
    live_out = [filter_out_subscripts(lo) for lo in live_out]
    return live_in, live_out
def compute_live_temporaries ( kernel , schedule ) : live_in = [ set ( ) for i in range ( len ( schedule ) + 1 ) ] live_out = [ set ( ) for i in range ( len ( schedule ) ) ] id_to_insn = kernel . id_to_insn block_bounds = get_block_boundaries ( schedule ) def compute_subrange_liveness ( start_idx , end_idx ) : idx = end_idx while start_idx <= idx : sched_item = schedule [ idx ] if isinstance ( sched_item , LeaveLoop ) : start = block_bounds [ idx ] live_in [ idx ] = live_out [ idx ] = live_in [ idx + 1 ] compute_subrange_liveness ( start + 1 , idx - 1 ) prev_live_in = live_in [ start ] . copy ( ) live_in [ start ] = live_out [ start ] = live_in [ start + 1 ] if live_in [ start ] != prev_live_in : live_out [ idx ] |= live_in [ start ] live_in [ idx ] = live_out [ idx ] compute_subrange_liveness ( start + 1 , idx - 1 ) idx = start - 1 elif isinstance ( sched_item , ReturnFromKernel ) : start = block_bounds [ idx ] live_in [ idx ] = live_out [ idx ] = live_in [ idx + 1 ] compute_subrange_liveness ( start + 1 , idx - 1 ) live_in [ start ] = live_out [ start ] = live_in [ start + 1 ] idx = start - 1 elif isinstance ( sched_item , RunInstruction ) : live_out [ idx ] = live_in [ idx + 1 ] insn = id_to_insn [ sched_item . insn_id ] defs = filter_scalar_temporaries ( kernel , get_def_set ( insn , include_subscripts = False ) ) uses = filter_temporaries ( kernel , get_use_set ( insn , include_subscripts = False ) ) live_in [ idx ] = ( live_out [ idx ] - defs ) | uses idx -= 1 elif isinstance ( sched_item , Barrier ) : live_in [ idx ] = live_out [ idx ] = live_in [ idx + 1 ] idx -= 1 else : raise LoopyError ( "unexepcted type of schedule item: %s" % type ( sched_item ) . __name__ ) compute_subrange_liveness ( 0 , len ( schedule ) - 1 ) live_in = live_in [ : - 1 ] if 0 : print ( kernel ) print ( "Live-in values:" ) for i , li in enumerate ( live_in ) : print ( "{}: {}" . format ( i , ", " . join ( li ) ) ) print ( "Live-out values:" ) for i , lo in enumerate ( live_out ) : print ( "{}: {}" . format ( i , ", " . join ( lo ) ) ) live_in = [ filter_out_subscripts ( li ) for li in live_in ] live_out = [ filter_out_subscripts ( lo ) for lo in live_out ] return live_in , live_out
Compute live-in and live-out sets for temporary variables.
Compute live - in and live - out sets for temporary variables .
"""
    Compute live-in and live-out sets for temporary variables.
    """ # {{{ Liveness analysis implementation # Propagate live values through the loop. # }}} # Compute live variables # Strip off subscripts.
kernel
schedule