(self, blocks)
return blocks
This function does something
This function does something
This function does something
def _run_dist_pass(self, blocks):
        """This function does something"""
        topo_order = find_topo_order(blocks)
        namevar_table = get_name_var_table(blocks)
        work_list = list((l, blocks[l]) for l in reversed(topo_order))
        while work_list:
            label, block = work_list.pop()
            new_body = []
            replaced = False
            for i, inst in enumerate(block.body):
                out_nodes = None
                if type(inst) in distributed_run_extensions:
                    f = distributed_run_extensions[type(inst)]
                    out_nodes = f(inst, self._dist_analysis.array_dists,
                                  self.state.typemap, self.state.calltypes, self.state.typingctx,
                                  self.state.targetctx, self)
                elif isinstance(inst, Parfor):
                    out_nodes = self._run_parfor(inst, namevar_table)
                    # run dist pass recursively
                    p_blocks = wrap_parfor_blocks(inst)
                    # build_definitions(p_blocks, self.state.func_ir._definitions)
                    self._run_dist_pass(p_blocks)
                    unwrap_parfor_blocks(inst)
                elif isinstance(inst, ir.Assign):
                    lhs = inst.target.name
                    rhs = inst.value
                    if isinstance(rhs, ir.Expr):
                        out_nodes = self._run_expr(inst, namevar_table)
                    elif isinstance(rhs, ir.Var) and (self._is_1D_arr(rhs.name)
                                                      and not is_array_container(self.state.typemap, rhs.name)):
                        self._array_starts[lhs] = self._array_starts[rhs.name]
                        self._array_counts[lhs] = self._array_counts[rhs.name]
                        self._array_sizes[lhs] = self._array_sizes[rhs.name]
                    elif isinstance(rhs, ir.Arg):
                        out_nodes = self._run_arg(inst)
                elif isinstance(inst, (ir.StaticSetItem, ir.SetItem)):
                    if isinstance(inst, ir.SetItem):
                        index = inst.index
                    else:
                        index = inst.index_var
                    out_nodes = self._run_getsetitem(inst.target,
                                                     index, inst, inst)
                elif isinstance(inst, ir.Return):
                    out_nodes = self._gen_barrier() + [inst]

                if out_nodes is None:
                    new_body.append(inst)
                elif isinstance(out_nodes, list):
                    new_body += out_nodes
                elif isinstance(out_nodes, ReplaceFunc):
                    rp_func = out_nodes
                    if rp_func.pre_nodes is not None:
                        new_body.extend(rp_func.pre_nodes)
                    # inline_closure_call expects a call assignment
                    dummy_call = ir.Expr.call(
                        ir.Var(block.scope, "dummy", inst.loc),
                        rp_func.args, (), inst.loc)
                    if isinstance(inst, ir.Assign):
                        # replace inst.value to a call with target args
                        # as expected by inline_closure_call
                        inst.value = dummy_call
                    else:
                        # replace inst with dummy assignment
                        # for cases like SetItem
                        loc = block.loc
                        dummy_var = ir.Var(
                            block.scope, mk_unique_var("r_dummy"), loc)
                        block.body[i] = ir.Assign(dummy_call, dummy_var, loc)
                    block.body = new_body + block.body[i:]
                    # TODO: use Parfor loop blocks when replacing funcs in
                    # parfor loop body
                    update_globals(rp_func.func, rp_func.glbls)
                    inline_closure_call(self.state.func_ir, rp_func.glbls,
                                        block, len(new_body), rp_func.func, self.state.typingctx,
                                        rp_func.arg_types,
                                        self.state.typemap, self.state.calltypes, work_list)
                    replaced = True
                    break
                else:
                    assert False, "invalid dist pass out nodes"

            if not replaced:
                blocks[label].body = new_body

        return blocks
def _run_dist_pass ( self , blocks ) : topo_order = find_topo_order ( blocks ) namevar_table = get_name_var_table ( blocks ) work_list = list ( ( l , blocks [ l ] ) for l in reversed ( topo_order ) ) while work_list : label , block = work_list . pop ( ) new_body = [ ] replaced = False for i , inst in enumerate ( block . body ) : out_nodes = None if type ( inst ) in distributed_run_extensions : f = distributed_run_extensions [ type ( inst ) ] out_nodes = f ( inst , self . _dist_analysis . array_dists , self . state . typemap , self . state . calltypes , self . state . typingctx , self . state . targetctx , self ) elif isinstance ( inst , Parfor ) : out_nodes = self . _run_parfor ( inst , namevar_table ) # run dist pass recursively p_blocks = wrap_parfor_blocks ( inst ) # build_definitions(p_blocks, self.state.func_ir._definitions) self . _run_dist_pass ( p_blocks ) unwrap_parfor_blocks ( inst ) elif isinstance ( inst , ir . Assign ) : lhs = inst . target . name rhs = inst . value if isinstance ( rhs , ir . Expr ) : out_nodes = self . _run_expr ( inst , namevar_table ) elif isinstance ( rhs , ir . Var ) and ( self . _is_1D_arr ( rhs . name ) and not is_array_container ( self . state . typemap , rhs . name ) ) : self . _array_starts [ lhs ] = self . _array_starts [ rhs . name ] self . _array_counts [ lhs ] = self . _array_counts [ rhs . name ] self . _array_sizes [ lhs ] = self . _array_sizes [ rhs . name ] elif isinstance ( rhs , ir . Arg ) : out_nodes = self . _run_arg ( inst ) elif isinstance ( inst , ( ir . StaticSetItem , ir . SetItem ) ) : if isinstance ( inst , ir . SetItem ) : index = inst . index else : index = inst . index_var out_nodes = self . _run_getsetitem ( inst . target , index , inst , inst ) elif isinstance ( inst , ir . Return ) : out_nodes = self . _gen_barrier ( ) + [ inst ] if out_nodes is None : new_body . append ( inst ) elif isinstance ( out_nodes , list ) : new_body += out_nodes elif isinstance ( out_nodes , ReplaceFunc ) : rp_func = out_nodes if rp_func . pre_nodes is not None : new_body . extend ( rp_func . pre_nodes ) # inline_closure_call expects a call assignment dummy_call = ir . Expr . call ( ir . Var ( block . scope , "dummy" , inst . loc ) , rp_func . args , ( ) , inst . loc ) if isinstance ( inst , ir . Assign ) : # replace inst.value to a call with target args # as expected by inline_closure_call inst . value = dummy_call else : # replace inst with dummy assignment # for cases like SetItem loc = block . loc dummy_var = ir . Var ( block . scope , mk_unique_var ( "r_dummy" ) , loc ) block . body [ i ] = ir . Assign ( dummy_call , dummy_var , loc ) block . body = new_body + block . body [ i : ] # TODO: use Parfor loop blocks when replacing funcs in # parfor loop body update_globals ( rp_func . func , rp_func . glbls ) inline_closure_call ( self . state . func_ir , rp_func . glbls , block , len ( new_body ) , rp_func . func , self . state . typingctx , rp_func . arg_types , self . state . typemap , self . state . calltypes , work_list ) replaced = True break else : assert False , "invalid dist pass out nodes" if not replaced : blocks [ label ] . body = new_body return blocks