
    0;jir                       d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dl	mZm
Z
mZmZmZmZmZ d dlmZ d dlmZmZmZ d dlmZmZmZmZ d dlZd ad Z G d d	          Z e            Z[d
 Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(d Z)d Z*d Z+d Z,d Z-d Z.d Z/i Z0d Z1d Z2d Z3i Z4d Z5i Z6d Z7d Z8d  Z9d! Z:	 	 dnd"Z;dnd#Z<i Z=d$ Z>g Z?d% Z@e?A                    e@           d& ZBg ZCd' ZDd( ZEi ZFi ZGd) ZH	 	 dod*ZId+ ZJd, ZKd- ZLd. ZMi ZNd/ ZOi ZP	 dpd0ZQd1 ZRdpd2ZSdpd3ZTi ZUdqd5ZVi ZWdpd6ZXd7 ZYd8 ZZd9 Z[g d:Z\d; Z]i Z^dpd<Z_d= Z`d> Zad? Zbd@ Zc G dA dBed          ZedC ZfdD ZgdE ZhdpdFZii ZjdehfdGZkdH ZldI Zm	 	 drdJZndK ZodL ZpdM ZqdN ZrdO ZsdP ZtdQ ZudR ZvdS ZwdT ZxdU ZydV ZzdW Z{dX Z|dY Z}dZ Z~d[ Zd\ Zd] Zd^ Zd_ Zd` Zda Zdb ZdsdeZdf Zdg Zdh Zdi Zdj Zdk Zdl Zdm ZdS )t    N)
_Intrinsic)typestypingiranalysispostprocrewritesconfig)	signature)compute_live_mapcompute_use_defscompute_cfg_from_blocks)TypingErrorUnsupportedErrorNumbaPendingDeprecationWarningCompilerErrorc                 N    | dz   t          t                    z   }t          dz   a|S )N.   )str_unique_var_count)prefixvars     M/root/voice-cloning/.venv/lib/python3.11/site-packages/numba/core/ir_utils.pymk_unique_varr      s)    
3,.//
/C)A-J    c                   "    e Zd ZddZd Zd ZdS )	_MaxLabelr   c                     || _         d S N_value)selfvalues     r   __init__z_MaxLabel.__init__$   s    r   c                 0    | xj         dz  c_         | j         S )Nr   r!   )r#   s    r   nextz_MaxLabel.next'   s    q{r   c                 :    t          || j                  | _        d S r    )maxr"   )r#   newvals     r   updatez_MaxLabel.update+   s    &$+..r   N)r   )__name__
__module____qualname__r%   r'   r+    r   r   r   r   #   sF             / / / / /r   r   c                 D    d}	 | t          |          z   }||vr|S |dz  })zl Get a new var name with a given prefix and
        make sure it is unused in the given variable table.
    r   Tr   )r   )r   	var_tablecurr   s       r   get_unused_var_namer3   3   s<     Cs3xxiJq	r   c                  4    t                                           S r    )_the_max_labelr'   r/   r   r   
next_labelr6   ?   s       r   c	                 R  % g %d}	t           j        }
t          |t                    rt	          |          dk    r|d         }t          |%          }nt	          |          }	t          j        t          d                    }r2t           j	        
                    t           j        |	          |j        <   %fd|D             }t          j                            |          }t          j        ||          }%                    |           |}t           j	        
                    t           j        |	          }
t!          |d          r|                    | ||||||
%          S t          j        t          d                    }r,t           j                            t(                    |j        <   t          j        dt(                    }t          j        ||          }t          j                            |d          }t          j        t          d	                    }r"t/          t(          j        |           |j        <   t          j        ||          }t3          |          }t          j        t          d
                    }r't           j                            |          |j        <   t          |t           j        t           j        f          r7|j        dk    r,t          j        |          }t          j        ||          }n?|dk    rd}t          j                            ||          }t          j        ||          }t          j                             |||gd          }|rn|j                 !                    | |
t           j                            |          gi           }|j"        dk    r|#                    d          n||_$        |||<   |j"        dk    rj|#                    d          }t          j        t          d                    }r|#                    d          |j        <   t          j        ||          }t          j                            |d          }t          j        t          d                    } r"t/          t(          j%        |           | j        <   t          j        ||           }!t          j                             | |gd          }"|r&| j                 !                    | |gi           ||"<   t          j        |"|          }#%&                    |||||!|#g           n/t          j        ||          }$%&                    ||||$g           %S )zgenerate an array allocation with np.empty() and return list of nodes.
    size_var can be an int variable or tuple of int variables.
    lhs_typ is the type of the array being allocated.
    r   r   z
$tuple_varc           	      6    g | ]}t          |          S r/   )convert_size_to_var).0slocoutscopetypemaps     r   
<listcomp>zmk_alloc.<locals>.<listcomp>X   s9     , , , -QSII , , ,r   __allocate__	$np_g_varnpemptyz$empty_attr_attrz$np_typ_var boolbool_r/   FClayoutz$empty_c_varasfortranarrayz$asfortran_array_attr)'r   intp
isinstancetuplelenr9   r   Varr   
containersUniTuplenameExprbuild_tupleAssignappendhasattrrA   miscModulenumpyGlobalgetattrget_np_ufunc_typrD   r   	functionsNumberClass
NPDatetimeNPTimedeltaunitConstcallget_call_typerK   copy_return_typerL   extend)&	typingctxr?   	calltypeslhssize_vardtyper>   r<   lhs_typndimssize_typ	tuple_var	new_sizes
tuple_calltuple_assigng_np_varg_npg_np_assignempty_attr_callattr_varattr_assign	dtype_strtyp_vartypename_consttyp_var_assignnp_typ_getattr
alloc_callcacempty_c_typempty_c_varempty_c_assignasfortranarray_attr_callafa_attr_varafa_attr_assignasfortranarray_callasfortranarray_assignalloc_assignr=   s&    `    ``                             @r   mk_allocr   C   s}    CEzH(E"" Dx==A{H*8WeS#NNHH MMEumL&A&A3GGI '*/*:*C*CJ+' +'	', , , , , , ,"*, , ,I,,Y<<J9ZC@@LJJ|$$$ H'00UCCHw'' 
##
 
 	
 ve];77==H :!&!2!25!9!99T5#&&D)D(C00Kgooh==Ove]+=>>DDH J!1%+y!I!I)OXs;;KE

IfUM-88#>>G C % ; ;E B B 	55+U->?@@ 	A
bXi55NY~wDDNNfI9cBB>7C@@h7(;REEJ 	$hm$22%/"="=e"D"DErK K  '~44 $LLL444!( 	 !$	*~ll#l..fUM.$A$A3GG 	A(/C(@(@GK$%:{C@@ $&7??8=Ms#S#S ve]3J%K%KSQQ 	[)9%:NPY)Z)ZGL%&)$<lCPP gll<+CPP 	.-4\5F-G-U-UK=".. ..I)* !#	*=sC H H

Knn#%:< 	= 	= 	= 	= yS#66

KnlKLLLJr   c                 Z   t          | t                    ryt          j        |t	          d          |          }|rt
          j        ||j        <   t          j        t          j	        | |          ||          }|
                    |           |S t          | t          j                  sJ | S )Nz$alloc_size)rN   intr   rQ   r   r   rM   rT   rW   re   rX   )rn   r?   r>   r<   nodesnew_sizesize_assigns          r   r9   r9      s    (C   6%}!=!=sCC 	0%*ZGHM"i3 7 73GG[!!!h'''''Or   c                 l    	 |                     |           S # t          $ r t          d| d          w xY w)zZget type of the incoming function

    Resolve using the context for target-awareness
    ztype for func z
 not found)resolve_value_typer   RuntimeError)funcrk   s     r   r_   r_      sN    
A++D111 A A A+T<@@@As    3c                    t          j        |t          d          |          }t          t                    | |j        <   t          j        dt          |          }t          j        |||          }	t          | |||||          \  }
}t           j	        
                    ||d|          }| |j                                     t          j                    t          j        gt!          |          z  i           ||<   t          j        |t          d          |          }t          j                            t          j                  | |j        <   t          j        |||          }t           j	                            ||          }t(          j        r%t-          t          j        t          j                  }n$t-          t          j        t          j                  }|||<   t          j        |t          d          |          }t          j                            t          j                  | |j        <   t          j        |||          }t          j        |t          d          |          }t          j                            t          j                  | |j        <   t          j        |||          }t          j        d|          }t          j        ||          }|
|	||||gz   |_        |S )zpmake a block that initializes loop range and iteration variables.
    target label in jump needs to be set.
    z$range_g_varranger/   z$range_c_varz	$iter_var$phi)r   rQ   r   get_global_func_typr   rT   r]   rW   _mk_range_argsrU   rf   rg   r   Contextr   rM   rP   	iterators	RangeTypegetiterr
   USE_LEGACY_TYPE_SYSTEMr   range_iter64_typerange_state64_typerange_iter_typerange_state_typeRangeIteratorTypeJumpBlockbody)r?   startstopsteprl   r>   r<   g_range_varg_rangeg_range_assign	arg_nodesargs
range_callrange_call_varrange_call_assign	iter_callcalltype_sigiter_variter_call_assignphi_var
phi_assignjump_headerrange_blocks                          r   mk_range_blockr      sV   
 &n = =sCCK 3E : :GKi,,GYwS99N$WeT4LLOItk4S99J#K$45CC5:,T2B8 8Ij VE=#@#@#FFN#(?#<#<UZ#H#HGN 	*ncBB44I$ P !8%:RSS !68NOO'Iive];77==H"_>>uzJJGHMyHc::fUM&11377G!O==ejIIGGL8Wc22J'"c""K(5#&&K N4E$4j+$O OKr   c                 P   g }t          |t          j                  r|}nt          |t                    sJ t          j        |t	          d          |          }| rt
          j        | |j        <   t          j        t          j	        ||          ||          }|
                    |           |dk    r|dk    r||gfS t          |t          j                  r|}	nt          |t                    sJ t          j        |t	          d          |          }	| rt
          j        | |	j        <   t          j        t          j	        ||          |	|          }
|
                    |
           |dk    r||	|gfS t          |t          j                  r|}nt          |t                    sJ t          j        |t	          d          |          }| rt
          j        | |j        <   t          j        t          j	        ||          ||          }|
                    |           ||	||gfS )Nz$range_stopr   r   z$range_startz$range_step)rN   r   rQ   r   r   r   rM   rT   rW   re   rX   )r?   r   r   r   r>   r<   r   
g_stop_varstop_assigng_start_varstart_assign
g_step_varstep_assigns                r   r   r      s
   E$ "

$$$$$$VE=#?#?EE
 	2',zGJO$is 3 3ZEE[!!!zzdaiizl""%   #%%%%%%fUM.$A$A3GG 	3(-
GK$%y%!5!5{CHH\"""qyy{J///$ "

$$$$$$VE=#?#?EE
 	2',zGJO$is 3 3ZEE[!!!;
J777r   c                     t           j        j        j        D ]\  }}|| k    r|c S t	          d                    |                     )z2get type variable for func() from builtin registryzfunc type not found {})r   	templatesbuiltin_registryglobalsr   format)r   kvs      r   r   r     sR    "3;  A99HHH 
/66t<<
=
==r   c                    t          j        |t          d          |          }t          j                            t          j        t          j                  | |j        <   t           j	        
                    ||          }t          j        rt          j        }nt          j        }t          t          j                            t          j        t          j                  |          ||<   t          j        |||          }t          j        |t          d          |          }	t          j        | |	j        <   t           j	                            ||          }
t          j        |
|	|          }t          j        |t          d          |          }t          j        | |j        <   t           j	                            ||          }t          j        |||          }t          j        |t          d          |          }t          j        | |j        <   t          j        |	||          }t          j        |dd|          }t          j        ||          }|||||g|_        |S )zqmake a block that is a loop header updating iteration variables.
    target labels in branch need to be set.
    z$iternext_varz$pair_first_varz$pair_second_varr   r   )r   rQ   r   r   rR   PairrM   booleanrT   rU   iternextr
   r   r   r   r   rW   
pair_firstpair_secondBranchr   r   )r?   r   rl   r>   r<   iternext_variternext_callr   iternext_assignpair_first_varpair_first_callpair_first_assignpair_second_varpair_second_callpair_second_assign	phi_b_varphi_b_assignbranchheader_blocks                      r   mk_loop_headerr   $  s   
 6%!?!?EEL!&!1!6!6
EM"# "#GLG$$Wc22M$ 01/(JM	 	 		   Im
 i|SAAOVE=1B#C#CSIIN#(:GN g((s;;O	/>3GGfUM2D$E$EsKKO$)MGO !w**<==#3_cJJumF33S99I#jGIN9^Y<<LYB44F8E3''L(*;+\6CLr   c                     i }| D ]K}|                     dd                               dd                               dd          }||vsJ |||<   L|S )zXreturns a dictionary for conversion of variable names to legal
    parameter names.
    ___$r   )replace)varnamesvar_mapr   new_names       r   legalize_namesr   M  sl     G    ;;sD))11#s;;CCCMMw&&&&Nr   c                 2    d }i }t          | ||           |S )z<create a mapping from variable names to their ir.Var objectsc                     | || j         <   | S r    rT   )r   namevars     r   get_name_var_visitz.get_name_var_table.<locals>.get_name_var_visit[  s    
r   )
visit_vars)blocksr   r   s      r   get_name_var_tabler   Y  s0       Gv)7333Nr   c                 |    i }|                                 D ]\  }}||k    r|||<   d }t          | ||           dS )zCreplace variables (ir.Var to ir.Var) from dictionary (name -> name)c                     t          | t          j                  sJ | j        |v r4t          j        | j        || j                 | j                  } | j        |v 4| S r    )rN   r   rQ   rT   r>   r<   )r   namedicts     r   replace_namez'replace_var_names.<locals>.replace_namek  sY    #rv&&&&&h(""&HSX$6@@C h(""
r   N)itemsr   )r   r   new_namedictlrr   s         r   replace_var_namesr   c  sb     L      166LO  
 v|\22222r   c                 H   t          | t          j                  sJ | j        |                                v rj|| j                 j        | j        k    sJ || j                 }t          j        |j        |j        |j                  } | j        |                                v j| S r    )rN   r   rQ   rT   keysr>   r<   )r   vardictnew_vars      r   replace_var_callbackr   s  s    c26"""""
(gllnn
$
$sx %1111#(#fW]GL'+>> (gllnn
$
$ Jr   c                     i }|                                 D ]\  }}||j        k    r|||<   t          | t          |           dS )zEreplace variables (ir.Var to ir.Var) from dictionary (name -> ir.Var)N)r   rT   r   r   )r   r   new_vardictr   r   s        r   replace_varsr  |  sR     K  1;;KNv+[99999r   c                 2    t          | t          |           d S r    )visit_vars_stmtr   )stmtr   s     r   replace_vars_stmtr    s    D.88888r   c                 .    t          | t          |          S r    )visit_vars_innerr   )noder   s     r   replace_vars_innerr
    s    D"6@@@r   c                 j    |                                  D ]}|j        D ]}t          |||           dS )zWgo over statements of block bodies and replace variable names with
    dictionary.
    N)valuesr   r  )r   callbackcbdatablockr  s        r   r   r     sK      4 4J 	4 	4DD(F3333	4
Fr   c                 @   t                                           D ]%\  }}t          | |          r ||             d S &t          | t          j                  r8t          | j                  | _        t          | j                  | _        nt          | t          j                  rt          | j	                  | _	        nSt          | t          j
                  rt          | j                  | _        nt          | t          j                  rt          | j                  | _        nt          | t          j                  rt          | j                  | _        nt          | t          j                  rt          | j                  | _        nwt          | t          j                  r?t          j        d | j        | j                  }t          |          }|j	        | _        nt          | t          j                  r8t          | j                  | _        t          | j                  | _        nt          | t          j                  rSt          | j                  | _        t          | j                  | _        t          | j                  | _        n_t          | t          j                  r8t          | j                  | _        t          | j                  | _        nt          | t          j                  rRt          | j                  | _        t          | j                  | _        t          | j                  | _        nt          | t          j                  rRt          | j                  | _        t          | j                  | _        t          | j                  | _        n5t          | t          j                  rfd| j        D             | _        n	 d S )Nc                 2    g | ]}t          |          S r/   r  )r:   xr  r  s     r   r@   z#visit_vars_stmt.<locals>.<listcomp>  s&    NNNq%a6::NNNr   )visit_vars_extensionsr   rN   r   rW   r  targetr$   ArgrT   ReturnRaise	exceptionr   condr   DelrQ   r<   DelAttrattrSetAttrDelItemindexStaticSetItem	index_varSetItemPrintr   )r  r  r  tfr   s    ``   r   r  r    sw   %++--  1dA 	AdHf%%%FF	 $	"" )&t{HfEE%dj(FCC

	D"&	!	! &$TY&AA			D")	$	$ $%dj(FCC

	D"(	#	# ")$.(FKK	D")	$	$  $TY&AA			D"'	"	" &t{HfEE	D"&	!	!  fT4:tx00sHf55X

	D"*	%	% &t{HfEE$TY&AA			D"*	%	% &t{HfEE$TY&AA	%dj(FCC

	D"*	%	% &t{HfEE%dj(FCC

	D"*	+	+ &t{HfEE)$.(FKK%dj(FCC

	D"*	%	% &t{HfEE%dj(FCC
%dj(FCC

	D"(	#	# NNNNNDINNN		 	
Fr   c                     t          | t          j                  r |           S t          | t                    rfd| D             S t          | t                    rt	          fd| D                       S t          | t          j                  rA| j                                        D ]&}t          | j        |                   | j        |<   'n5t          | t          j	                  rt          | j
                  | _
        | S )Nc                 2    g | ]}t          |          S r/   r  r:   nr  r  s     r   r@   z$visit_vars_inner.<locals>.<listcomp>  s&    DDD! Hf55DDDr   c                 2    g | ]}t          |          S r/   r  r)  s     r   r@   z$visit_vars_inner.<locals>.<listcomp>  s&    JJJ&q(F;;JJJr   )rN   r   rQ   listrO   rU   _kwsr   r  Yieldr$   )r	  r  r  args    `` r   r  r    s   $ Dxf%%%	D$		 DDDDDDtDDDD	D%	 	  DJJJJJTJJJKKK	D"'	"	" 	D 9>>## 	P 	PC-dinhOODIcNN	P	D"(	#	# D%dj(FCC
Kr   c                 6   i }|                                  D ] \  }}d}|j        rR|j        d         }|j        D ]=}t                                           D ]!\  }}t          ||          r |||          }	">t          |t          j                  r*t	          j        |j        |z   |j                  |j        d<   t          |t          j                  r9t	          j        |j	        |j
        |z   |j        |z   |j                  |j        d<   ||||z   <   |S )z>add an offset to all block labels and jump/branch targets
    Nr   )r   r   add_offset_to_labels_extensionsrN   r   r   r  r<   r   r  truebrfalsebr)
r   offset
new_blocksr   bterminstTr&  f_maxs
             r   add_offset_to_labelsr;    s,    J # #16 	06":D 0 0;AACC 0 0DAq!$** 0 !$0 dBG$$ 	Av!5tx@@AF2JdBI&& 	D49dkF.B#'<&#8$(D DAF2J!"
1v:r   c                    d}|                                  D ]o\  }}d }|j        rY|j        d         }|j        D ]D}t                                           D ](\  }}t          ||          r ||          }||k    r|})E||k    r|}p|S )Nr   r   )r   r   find_max_label_extensionsrN   )	r   	max_labelr   r6  r7  r8  r9  r&  r:  s	            r   find_max_labelr?     s    I  16 	.6":D . .5;;== . .DAq!$** . !$ 9,,(-I	.
 y==Ir   c                 B   t          | t          |           dz             } i }t          |           }t                      }d}|D ]}|||<   |dz  }|D ]}| |         }d}|j        r|j        d         }t          |t          j                  r-t          j        ||j                 |j	                  |j        d<   t          |t          j
                  r?t          j
        |j        ||j                 ||j                 |j	                  |j        d<   ||||         <   |S )zFmakes the labels in range(0, len(blocks)), useful to compare CFGs
    r   r   Nr   )r;  r?  find_topo_orderdictr   rN   r   r   r  r<   r   r  r2  r3  )	r   r5  
topo_orderl_mapidxr  t_noder6  r7  s	            r   flatten_labelsrG    s)    "&.*@*@1*DEEFJ ((JFFE
C  aq & &6N6 	6":DdBG$$ 	?t{!3TX>>AF2JdBI&& 	B49eDK.@#(#6B BAF2J$%
5=!!r   c                     |                                  D ]D}g }|j        D ]1}t          |t          j                  s|                    |           2||_        EdS )zremove ir.Del nodesN)r  r   rN   r   r  rX   r   r  new_bodyr  s       r   remove_delsrK  .  sd      J 	& 	&DdBF++ &%%%


Fr   c                     |                                  D ]d}g }|j        D ]Q}t          |t          j                  r t          |j        t          j                  r<|                    |           R||_        edS )zremove ir.Arg nodesN)r  r   rN   r   rW   r$   r  rX   rI  s       r   remove_argsrM  9  s~      J 	" 	"D$	** z$*bf/M/M OOD!!!!


Fr   c                     d}t          | j        | j        | |||          r d}t          | j        | j        | |||           |r*t          j        |           }|                                 dS dS )zS Performs dead code elimination and leaves the IR in a valid state on
    exit
    FTN)remove_deadr   	arg_namesr   PostProcessorrun)func_irr?   	alias_maparg_aliasesdo_post_proc	post_procs         r   dead_code_eliminationrX  E  s    
 Lw~w'8'7 +/ /  w~w'8'7 +/ /   *733	 r   c                    t          |           }t          |           }t          || |j        |j                  }t          |           \  }	}
||t          | |||          \  }}t          j        dk    rjt          d|           t          d|           t          d|           t          d|           t          d|j                   t          d|j                   t          |                                          }d	}|                                 D ]\  }}d
 |j                                        D             }t          j        dk    rt          d||           |                    |          D ]7\  }}t          j        dk    rt          d|||                    |||         z  }8|t!          |||	|||||          z  }|S )zdead code elimination using liveness and CFG info.
    Returns True if something has been removed, or False if nothing is removed.
    Nr   zargs:z
alias map:zarg_aliases:z	live_map:zusemap:zdefmap:Fc                     h | ]	}|j         
S r/   r   r:   r   s     r   	<setcomp>zremove_dead.<locals>.<setcomp>l  s    >>>A>>>r      zremove_dead processing blockzsucc live_map)r   r   r   usemapdefmapget_call_tablefind_potential_aliasesr
   DEBUG_ARRAY_OPTprintsetr   r   
terminator	list_vars
successorsremove_dead_block)r   r   rS  r?   rT  rU  cfgusedefslive_map
call_tabler   	alias_setremovedlabelr  livesout_blk_datas                     r   rO  rO  T  s    "&
)
)Cv&&GVW^W^LLH"6**MJK/!7g8?"A "A	;""gtlI&&&nk***k8$$$i(((i(((INN$$%%IG M Mu>>!1!;!;!=!=>>>!Q&&0%???!nnU33 	' 	'NGU%**ow0ABBBXg&&EE$UE:{%.	7GM M 	M Nr   c           
         d}| j         g}	t          | j        dd                   D ]}
t          j        dk    rt          d|
           t                      }||z  }|D ]}|||         z  }||z  |z  }t          |
          t          v rOt          t          |
                   } ||
||||||          }
|
"t          j        dk    rt          d           d}t          |
t          j                  r|
j        }|
j        }|j        |vr4t          |||          r#t          j        dk    rt          d           d}t          |t          j                  r3|j        |j        k    r#t          j        dk    rt          d           d}et          |
t          j                  r,|
j        |vr#t          j        dk    rt          d           d}t          |
t          j                  r1|
j        j        }||vr!t          j        dk    rt          d           t          |
          t&          j        v r8t&          j        t          |
                   } ||
          \  }}||z  }||z  }n|d |
                                D             z  }t          |
t          j                  rt          |
j        t          j                  rGd	 |
j                                        D             }|j        |vr|                    |j                   n|                    |j                   |	                    |
           |	                                 |	| _        |S )
zremove dead code using liveness info.
    Mutable arguments (e.g. arrays) that are not definitely assigned are live
    after return of function.
    FNr   r]  rh  zStatement was removed.Tc                     h | ]	}|j         
S r/   r   r[  s     r   r\  z$remove_dead_block.<locals>.<setcomp>  s    777af777r   c                     h | ]	}|j         
S r/   r   r[  s     r   r\  z$remove_dead_block.<locals>.<setcomp>  s    GGG1GGGr   )re  reversedr   r
   rb  rc  rd  typeremove_dead_extensionsrN   r   rW   r  r$   rT   has_no_side_effectrQ   r  r#  r   ir_extension_usedefsrf  rU   removerX   reverse)r  rp  rl  rU  rT  rm  rS  r?   rn  rJ  r  alias_livesinit_alias_livesr   lives_n_aliasesr&  rm   rhsrT   def_funcusesdefsrhs_varss                          r   rh  rh    sp    G  !HCRC)) D D!Q&&%t,,,ee 9,! 	( 	(A9Q<'KK+-; ::///&tDzz2A1T5/;	7 D|)Q..2333 dBI&& 	+C*Cxu$$);**6 *6$)Q..2333#rv&& 38sx+?+?)Q..2333 dBF## 	z&&)Q..2333dBJ'' 	;#D?**)Q..2333::6664T$ZZ@H!$JD$TMETMEE77dnn&6&67777E$	** +dj"'22 +GG
0D0D0F0FGGGHxx//SX...LL***EJNr   c                 j    t          |          dk    r|dd          dt          gk    r
|d         dvS dS )N   r   randomr   >   seedshuffleF)rP   r\   )r  rp  	call_lists      r   remove_dead_random_callr    s?    
9~~y}50AAA|#6665r   c                    ddl m}m} ddlm} t          | t          j                  rd| j        dk    rX| j	        j
        }||vs||         g k    rdS ||         }|dt          gk    s|t          gk    s|dt          gk    sx|dt          gk    sk|d	t          gk    s^||j        gk    sR||gk    sK|d
t          gk    s>|dt          gk    s1||j        gk    s%|dt           gk    s|t"          gk    s|t$          gk    rdS t          |d         t&                    r$|d         j        dk    s|d         j        dk    rdS ddlm} ddlm}	 t          |d         |          r|d         j        }
|
|	k    rdS t4          D ]} || ||          r dS dS t          | t          j                  r| j        dk    r| j        j
        |vS t          | t          j                  rdS t          | t          j                  r| j        dk    rdS dS )za Returns True if this expression has no side effects that
        would prevent re-ordering.
    r   )array_analysisparfor)prangerf   FrD   stencillogro   r  pndindexceilTempty_inferredunsafe_empty_inferred)CPUDispatcher)dot_3_mv_check_argsinplace_binopr   )numba.parforsr  r  numba.misc.specialr  rN   r   rU   opr   rT   r\   slicenumba
wrap_indexinternal_prangemathr)   r   r   _namenumba.core.registryr  numba.np.linalgr  py_funcremove_call_handlersrm   r.  )r  rp  rl  r  r  r  	func_namer  r  r  r  r&  s               r   ry  ry    s    54444444))))))#rw  CFf$4$4HM	J&&*Y*?2*E*E5y)	'5)))%  )U+++%'''5))).3444&!!(E****e,,,&0111&$''##41z22 	|!%555|!%<<<4555555777777ilM22 	l*G---t% 	 	AqeY'' ttu#rw )CFo$=$=w|5((#rx   u#rw CFl$:$:u4r   c                    t          | t          j                  r| j        dk    r| j        j        }||vs||         g k    rdS ||         }|t          gk    s?|dt          gk    s2|dt          gk    s%|dt          gk    s|t          gk    s|t          gk    rdS t          D ]} || ||          r dS dS | j        dk    s| j        dk    rdS t          | t          j                  rdS dS )	z Returns True if every time this expression is evaluated it
        returns the same result.  This is not the case for things
        like calls to numpy.random.
    rf   Fr  rD   r  Tr   r   )rN   r   rU   r  r   rT   r  r\   r  r)   r   is_pure_extensionsr.  )r  rp  rl  r  r  r&  s         r   is_purer    s#   
 #rw 6VI
**j.Cr.I.Iu"9-IeW$$eU^++gu---fd^++cU""cU""t'    1S%++  44 5Vy  CFj$8$85#rx   u4r   c                     | dk    r|dv rdS dS )Nr\   )rD   TFr/   )module_namer  s     r   is_const_callr  -  s"    g	!!45r   c                 b    | |vr| S t          t          ||                              }|d         S )Nr   )sortedr,  )r   rT  	v_aliasess      r   get_canonical_aliasr  7  s5    	tIaL))**IQ<r   c           
         |i }|t          fd|D                       }t          |j                  |_        g d}|                                 D ]}|j        D ]}t          |          t          v r*t          t          |                   }	 |	|||||           t          |t          j
                  r\|j        }
|j        j        }t          |          rt          |
t          j                  r"||
j        k    rt!          ||
j        ||           t          |
t          j                  r0|
j        dk    s	|
j        dv rt!          ||
j        j        ||           t          |
t          j                  r'|
j        dk    rt!          ||
j        j        ||           t          |
t          j                  r0|
j        dk    r%|
j        dv rt!          ||
j        j        ||           t          |
t          j                  r>|
j        dk    r3|
j        d	vr*|
j        j        |v rt!          ||
j        j        ||           t          |
t          j                  r|
j        d
k    rt+          t,          ||
          }|+|\  }}|t.          v r t.          |         } |||
j        ||           |dk    r&||v r"t!          ||
j        d         j        ||           t          |t          j                  r||v rt!          ||j        ||           t3          j        |          }|D ]9}||         D ]}||xx         ||         z  cc<   ||         D ]}||         ||<   :||fS )zCfind all array aliases and argument aliases to avoid remove as deadNc              3   <   K   | ]}t          |          |V  d S r    )is_immutable_type)r:   ar?   s     r   	<genexpr>z)find_potential_aliases.<locals>.<genexpr>D  s3      OO1B1g1N1NO!OOOOOOr   )ravel	transposereshapecastgetitemstatic_getitemr  r^   )r9  ctypesflat)shaperf   r\   r   )rd  build_definitionsr   _definitionsr  r   rw  alias_analysis_extensionsrN   r   rW   r$   r  rT   r  rQ   
_add_aliasrU   r  rm   r  guardfind_callnamealias_func_extensionsr   rh   deepcopy)r   r   r?   rS  rT  rU  np_alias_funcsblinstrr&  exprrm   fdeffnamefmod
alias_funcold_alias_mapr   ws     `                r   ra  ra  >  s    	OOOOTOOOOO -W^<<G666Nmmoo ,K ,KW +	K +	KEE{{777-d5kk:%wKHHH%++ 'K{l'$S'22 dBF++ GTYsDIy+FFFtRW-- M47f3D3DG<<<sDJOYLLLdBG,, KO1K1KsDHM9kJJJtRW-- M$'Y2F2F I)@@@sDJOYLLLtRW-- M$'Y2F2F IY66 JO{::sDJOYLLLdBG,, KF1B1B wGGD
 | "&KE4444%:4%@
"
3	9kJJJw5N+B+B"3	!(99kRRR!$// KE^4K4K"3	9kJJJW+	K\ M),,M ( (q! 	) 	)AaLLLIaL(LLLLq! 	( 	(A$Q<IaLL	( k!!r   c                     ||v r|                     |            n`||vrt                      ||<   | |vrt                      || <   ||                              |            ||                               |           d S r    )addrd  )rm   r  rT  rU  s       r   r  r    s    
ki UUIcNi UUIcN#3#3
Fr   c                     || |vrdS ||          }t          |t          j        t          j        j        t          j        j        f          rdS |t          j        k    rdS dS )NFT)rN   r   Numberscalars_NPDatetimeBaser   r   string)r   r?   typs      r   r  r    sg    #W,,u
#,C#em&C13 4 4 t
ELt5r   c                 b   t          |           }|                                }t          | ||          }|\  }}}}}	d}
t          j        |	          }|
|k    r|                                 D ]}||k    r	d |                    |          D             }|	|d                                                  ||<   |D ]}||xx         |	|         z  cc<   ||         ||         ||         z
  z  |	|<   |}
t          j        |	          }|
|k    t          j        dk    rt          d|	           ||	fS )zcompute copy propagation information for each block using fixed-point
     iteration on data flow equations:
     in_b = intersect(predec(B))
     out_b = gen_b | (in_b - kill_b)
    Nc                     g | ]\  }}|S r/   r/   )r:   i_ds      r   r@   z"copy_propagate.<locals>.<listcomp>  s    >>>UQq>>>r   r   r   zcopy propagate out_copies:)
r   entry_pointinit_copy_propagate_datarh   r  r   predecessorsr
   rb  rc  )r   r?   ri  entryc_data
gen_copies
all_copieskill_copies	in_copies
out_copies	old_point	new_pointro  predecsps                  r   copy_propagater    sr    "&
)
)COOE &feW==FCI@Z[)ZIj))I
y
 
 [[]] 	L 	LE~~>>c&6&6u&=&=>>>G)'!*5::<<Ie 2 2%   JqM1     ",E!2$-e$4{57I$I"KJu	M*--	 y
 
  ""*J777j  r   c                    t          | |          \  }}t                      |                                D ]\  }}||         z  i }|                                D ]\  }}	t                      ||<   D ]m\  }
}|
||         v s
|||         v r||                             |
|f           d |	D             }|
|f|	vr%|
|v s||v r||                             |
|f           nfd|                                 D             }t                      ||<   i }|                                 D ]}||         ||         ||         z
  z  ||<    ||         ||<   ||||fS )zHget initial condition of copy propagation data flow for each block.
    c                     h | ]\  }}|S r/   r/   )r:   rm   r  s      r   r\  z+init_copy_propagate_data.<locals>.<setcomp>  s    444S444r   c                 :    i | ]}|                                 S r/   )rh   )r:   r   r  s     r   
<dictcomp>z,init_copy_propagate_data.<locals>.<dictcomp>  s%    ===!JOO%%===r   )get_block_copiesrd  r   r  r   )r   r  r?   r  
extra_killr   r;   r  ro  gen_setrm   r  assignedr  r  r  s                  @r   r  r    s   
 .fg>>J
J  "" $ $1jm#

K$**,, 
3 
3w UUE" 	3 	3HCj'''3*U2C+C+CE"&&Sz222 54G444Hc
'))C8OOE"&&Sz222	3 >===v{{}}===IuuIeJ H H'. )% 0;u3E EG
5"5)Ju
KJGGr   c                    i }i }|                                  D ]Y\  }}i }t                      ||<   |j        D ]}t                                           D ]\  }}	t	          ||          rv |	||          \  }
}|
D ]
\  }}|||<   i }|                                 D ]1\  }}||vr	||vr|||<   ||v r||                             |           2|}||xx         |z  cc<   t	          |t          j                  rN|j        j	        }t	          |j
        t          j                  r+|j
        j	        }||         ||         k    r||k    r|||<   t	          |j
        t          j                  r|j
        j        dk    r|j
        j        j	        }||         }t	          |t          j                  s{|t          j        k    sk||                             |           i }|                                 D ]7\  }}||k    r||k    r|||<   ||k    r||                             |           8|}||                             |           t          |                                           }|||<   [||fS )z2get copies generated and killed by each block
    r  )r   rd  r   copy_propagate_extensionsrN   r  r   rW   r  rT   r$   rQ   rU   r  rm   r   r  r  )r   r?   block_copiesr  ro  r  assign_dictr  r9  r&  r  kill_setrm   r  new_assign_dictr   r   in1_varin1_typ	block_cpss                       r   r  r    s    LJ 2( 2(uEE
5J ,	+ ,	+D17799 2 21dA&& 2()$(8(8%GX$+ / /S+.C((&(O + 1 1 3 3 5 51H,,(1B1B12OA.==&u-11!444"1Ku%%%1%%%$	** +k&dj"&11 
!*/C s|ws|33s

+.C( dj g' ' 6+/:=O+K+K"jn1G%g.G&w== 
6&%,66"5)--g666*,$/$5$5$7$7 9 9DAq G||W56 2 G|| *5 1 5 5a 8 8 8&55!%%c***))++,,	'U##r   c           
      z   |g }|                                  D ]\  }}fd||         D             }|j        D ]}	t          |	          t          v r+t          t          |	                   }
 |
|	||||           nEt	          |	t
          j                  rt          |	j        |          |	_        nt          |	|           t          |	||           t                                           D ]\  }}
t	          |	|          rt |
|	|          \  }}|D ]\  }}|v r|         ||<   |                                                                 D ]'\  }}||v s	|j        |v r|                    |           (t	          |	t
          j                  rt	          |	j        t
          j                  r|	j        j        }|	j        j        }||k    r||         ||         k    r|v r|         ||<   n|                    |d           g }|                                 D ]%\  }}|j        |k    r|                    |           &|D ]}|                    |d           t	          |	t
          j                  rt	          |	j        t
          j                  sy|	j        j        }|                    |d           g }|                                 D ]%\  }}|j        |k    r|                    |           &|D ]}|                    |d           |                    |                                            !|S )zEapply copy propagation to IR: replace variables when copies availableNc                 (    i | ]\  }}||         S r/   r/   )r:   r   r   name_var_tables      r   r  z(apply_copy_propagate.<locals>.<dictcomp>5  s$    FFFTQA~a(FFFr   )r   r   rw  apply_copy_propagate_extensionsrN   r   rW   r
  r$   r  fix_setitem_typer  rh   rT   poprQ   r  rX   rj   )r   r  r   r?   rl   save_copiesro  r  var_dictr  r&  r9  r  r  rm   r  r   r   lhs_killr   r   s     `                  r   apply_copy_propagater  +  sv     5- 5-uFFFFYu5EFFFJ 1	* 1	*DDzz<<<3DJJ?$.Y5 5 5 5 D"),, 2/
HEE

!$111T7I66617799 , ,1dA&& ,()$(8(8%GX$+ @ @S.00,:3,?HSM ( 5 5 7 7 , ,1==AFh,>,>$LLOOO$	** .z$*bf/M/M .k&jo#:: s|ws|33~8M8M(6s(; S$///!H ( 0 0 / /16S==$OOA...% . . Q----4++ 
*0:4:rv0N0N
*k&S$'''$NN,, + +DAqv}} ***! * *ALLD))))8>>++,,,,r   c                    t          | t          j        t          j        f          sdS || j        j                 }||          j        d         }t          |t          j        j	                  rt          |t          j        j	                  sdS |j
        dk    rX|j
        dk    rM|                    |j
                  }|||          j        d         ||          j        d         f||          _        dS )zCopy propagation can replace setitem target variable, which can be array
    with 'A' layout. The replaced variable can be 'C' or 'F', so we update
    setitem call type reflect this (from matrix power test)
    Nr   ArJ   r   r]  )rN   r   r#  r!  r  rT   r   r   npytypesArrayrK   rh   )r  r?   rl   t_typs_typ	new_s_typs         r   r  r  m  s    
 dRZ)9:;; DK$%EdO #EN " " )3N *" *"
 	|su|s22JJelJ33	dO #dO # %	$ Fr   c                    t           j        dk    rw| j        }|dk    r|n|| _        | j        j        }t          d|d|                    dd                     |                                  t          d           || _        dS dS )zqDebug print function IR, with an optional blocks argument
    that may differ from the IR's original blocks.
    r   NzIR z: P   -z(----------------------------------------)r
   rb  r   func_idfunc_qualnamerc  centerdump)rS  titler   	ir_blocksrT   s        r   dprint_func_irr    s     ""N	&,nn&,eeeTT*222s;;<<<h" #"r   c                    |t          |           }g }t                      }t                      }|                                g}t          |          dk    r|d         }||vr||vr|                    |           |j        |         }| |         j        d         }t          |t          j	                  r|j
        |j        g}|D ]&}	||	f|j        vr|	|vr|                    |	           'n[|                                }||vr*|                    |           |                    |           ||v r|                    |           t          |          dk    |                                 |S )zfind topological order of blocks such that true branches are visited
    first (e.g. for_break test in test_dataflow). This is written as an iterative
    implementation of post order traversal to avoid recursion limit issues.
    Nr   r   )r   rd  r  rP   r  _succsr   rN   r   r   r2  r3  _back_edgesrX   r  r{  r|  )
r   ri  
post_orderseenvisitedstackr	  succs	last_instdests
             r   rA  rA    s   
 {%f--J55DeeG__E
e**q..Ryw4t#3#3HHTNNNJt$Et)"-I)RY// >")9+<= + +$<s664''T***+ 99;;D7""!!$'''D!!!t|| D!!!3 e**q..6 r   Tc                    |i }|i }|rt          |           }n!t          |                                           }t          |          D ]}t          | |         j                  D ]|}t          |t          j                  r"|j        j	        }|j
        }t          |t          j                  r|j        dk    rg ||j        j	        <   t          |t          j                  ry|j        dk    rn||v r/||                             |j                   |||j
        j	        <   ||v r7||         }	||	                             |j                   |	||j
        j	        <   t          |t          j                  rP||v r ||                             |j
                   ||v r(||         }	||	                             |j
                   t          |t          j                  rP||v r ||                             |j
                   ||v r(||         }	||	                             |j
                   t          |t          j                  rZ||v r*||                             |j	                   |||j	        <   ||v r(||         }	||	                             |j	                   t&                                          D ]"\  }
}t          ||
          r ||||           #~||fS )zAreturns a dictionary of call variables and their references.
    Nrf   r^   )rA  r,  r   rv  r   rN   r   rW   r  rT   r$   rU   r  r   rX   r  r]   FreeVarrQ   call_table_extensionsr   )r   rl  reverse_call_tabletopological_orderingorderro  r8  rm   r  call_varr9  r&  s               r   r`  r`    s   
 
! $''V[[]]##% $< $<VE]/00 #	< #	<D$	** >k&jc27++ 3&0@0@02Jsx}-c27++ F)0C0Cj(("3..sx888=@*39>:000#5c#:"8,33CH====E*39>:c29-- ?j(("3..sy999000#5c#:"8,33CI>>>c2:.. ?j(("3..sy999000#5c#:"8,33CI>>>c26** >j(("3..sx8887:*384000#5c#:"8,33CH===-3355 < <1dA&& <AdJ(:;;;<C#	<H )))r   c                    |i }|                                  D ]}|j        D ]}t          |t          j                  r|j        j        }|j        }t          |t          j                  r|j	        dk    r
|j
        ||<   t          |t          j                  r$t          |j        t                    r
|j        ||<   t          
                                D ]!\  }}t          ||          r |||           "،|S )z>returns a dictionary of tuple variables and their values.
    NrV   )r  r   rN   r   rW   r  rT   r$   rU   r  r   re   rO   tuple_table_extensions)r   tuple_tabler  r8  rm   r  r9  r&  s           r   get_tuple_tabler-    s     ) )J 
	) 
	)D$	** 1k&jc27++ 1-0G0G'*yK$c28,, 1CIu1M1M 1'*yK$.4466 ) )1dA&& )AdK((()
	) r   c                     t                      }t          | t          j        t          j        t          j        f          r|                    | j        j                   |S r    )	rd  rN   r   rW   r#  r!  r  r  rT   )r  writess     r   get_stmt_writesr0    sG    UUF$BJ0@ABB %

4;#$$$Mr   c                 6   t          |           }d}|                                 D ],\  }}t          |j        d         t          j                  r|}-|dk    r*|                    |           |                    |           i }t          |d          }|D ]}|	                                ||<   | 
                                D ]}|j        }t          |t          j                  r-t	          j        ||j                 |j                  |j        d<   t          |t          j                  r?t	          j        |j        ||j                 ||j                 |j                  |j        d<   i }	|                                 D ]\  }
}||
         }||	|<   |	S )zrename labels of function body blocks according to topological sort.
    The set of labels of these blocks will remain unchanged.
    r   T)r|  )rA  r   rN   r   r   r  r{  rX   r  r  r  re  r   r  r<   r   r  r2  r3  )r   rC  return_labelr   r6  	label_map
all_labelsro  r7  r5  r   	new_labels               r   rename_labelsr6    s    !((J L  1afRj"),, 	Lr,''','''I
D111J , ,%>>++	%]]__ 
- 
-| dBG$$ 	C4;!7BBAF2JdBI&& 	-49#,T[#9#,T\#:#'8- -AF2J J " "1aL	 !
9r   c                 &    t                     } fd}t          t          |                                                     }t	                      }|D ]} |         j        d         }|                    |          }d}|D ]Q\  }	}
 |	         }t          |j        d         t          j	                  rt          j
        |          |j        d<   Od}R|r|                    |           |D ]} |= t                      t                     S )z@transform chains of blocks that have no loop into a single blockc                     |          }t          |j                  dk    o$t          |j        d         t          j                  S )Nr   r   )rP   r   rN   r   r   )ro  r  r   s     r   find_single_branchz(simplify_CFG.<locals>.find_single_branchO  s6    u5:!#L
5:a=")(L(LLr   r   Tr   F)r   r,  filterr   rd  r   r  rN   r   r   rh   r  merge_adjacent_blocksr6  )r   ri  r9  single_branch_blocksmarked_for_delro  r8  r  delete_blockr  qr  s   `           r   simplify_CFGr@  K  s7    "&
)
)CM M M M M  '96;;== I IJJUUN% & &e}!!$''.." 	% 	%FQ1IE%*R."'22 %!%4
2$ 	&u%%%  5MM&!!!   r   )minr)   sumprodmeanr   stdcumsumcumprodargmaxargminargsortnonzeror  c           	         | j         }i }t          |          }|D ]}||         }g }	|j        D ]}
t          |
t          j                  rYt          |
j        t          j                  r9|
j        j	        }|
j        }|j
        dk    rP|j        t          v rAt          |j        j	                 t          j        j                  r|
j        }|j        }|||<   |j        }|j        }t	          j        |t'          d          |          }t          j                            t,                    |j	        <   t	          j        dt,          |          }t	          j        |||          }||_        |	                    |           |g| j        |j	        <   t5          t,          |j                  }t7          ||          }                    |           ||<   |j
        dk    r|j        j	        |v r||j        j	                 }|                    |          }|j        d t?          |j                           }fd|j         D             }|j        j	                 !                    ||j	                 gtE          |          z   |          ||<   |g|j        z   |_        |	                    |
           |	|_        d S )Nr^   rB   rC   rf   c                 2    i | ]\  }}||j                  S r/   r   )r:   rT   r   r?   s      r   r  z+canonicalize_array_math.<locals>.<dictcomp>  s%    KKKadGAFOKKKr   )#r   rA  r   rN   r   rW   r$   rU   r  rT   r  r  arr_mathr   r
  r  r>   r<   rQ   r   rZ   r[   r\   r]   rX   r  r^   r_   r  r   r   rP   kwsrg   r,  )rS  r?   rl   rk   r   saved_arr_argrC  ro  r  rJ  r  rm   r  arrr>   r<   rw   rx   ry   r   func_typold_sigargtypskwtypss    `                      r   canonicalize_array_mathrV  l  s    ^FM ((J + +uJ '	" '	"D$	** $0z$*bg/N/N $0k&jFi''CH,@,@&#CIN3U^5IK K -A *C)C),M#&IE'C!ve];-G-GMMH-2Z->->u-E-EGHM*9T5#66D"$)D(C"@"@K (CIOOK000;?&G(7"5#(33D/i@@HKK$$$#+GCL6V##(F(F'6C'mmC00G &l>CMM>:GKKKK37KKKF%,SX]%;%I%I!GCH$5#6g#F&P &PIcN #usx/CHOOD!!!!


Fr   c                    |t                      }|                                 D ]}|j        D ]}t          |t          j                  r+|                    |j        j        |j	        j        f           t          |t          j
                  r+|                    |j        j        |j        j        f           t          |t          j                  r|j        j        }|j        }t          |t          j                  r6|j        dk    r+|                    |j        j        |j	        j        f           t          |t          j                  rP|j        dk    rE|j	        }|t!          |          r|j        j        }|                    |j        j        |f           t"                                          D ]!\  }}t          ||          r |||           "|S )z8returns a set of arrays accessed and their indices.
    Nr  r  )rd  r  r   rN   r   r#  r  r  rT   r   r!  r"  rW   r$   rU   r  is_slice_indexarray_accesses_extensionsr   )	r   accessesr  r8  rm   r  r   r9  r&  s	            r   get_array_accessesr[    s    55 & &J 	& 	&D$
++ Bdk.
@AAA$ 011 Fdk.0CDEEE$	** 
:k&jc27++ C)0C0CLL#).#).!ABBBc27++ ::J0J0JIE}u(=(=} # 2LL#).%!899917799 & &1dA&& &AdH%%%&!	&& Or   c                     t          | t                    rdS t          | t                    r| D ]}t          |t                    r dS dS )z0see if index is a slice index or has slice in itTF)rN   r  rO   )r   r  s     r   rX  rX    s]    % t%  	 	A!U## tt5r   c                    t          |           }t                      }t          |                                           D ]}||v r| |         }t          |                    |                    }	 t          |          dk    rn|d         d         }||v rnt          |                    |                    }t          |                    |                    }t          |          dk    s|d         d         |k    rnQ| |         }|j                                         |xj        |j        z  c_        | |= |	                    |           |}d S )NTr   r   )
r   rd  r,  r   rg  rP   r  r   r  r  )	r   ri  rn  ro  r  r   r6   preds
next_blocks	            r   r;  r;    sP   
!&
)
)CeeGfkkmm$$  GuS^^E**++	5zzQq!JW$$))*5566E
3344E5zzQ%(1+"6"6
+J JNNJJ*/)JJz"KK
###E+	 r   c                 V   |si S i }i }|D ]\  }}|                     d          ss|j                             d          rY|j        |vrPt          d                    |                    }|||j        <   |||<   |                    |j                  }|||<   t          | |           |S )zS
    restores variable names of user variables after applying copy propagation
    r   z${})
startswithrT   r   r   r  r   )	r   r  r?   rename_dictvar_rename_mapr  r6  r   r  s	            r   restore_copy_var_namesrd    s      	KN 
$ 
$A S!! 	$af&7&7&<&< 	$45F+4M4M$U\\!__55H"*K'(N8$++af%%C #GHfk***r   c                    t          | j        |          \  }}t          | j                  }t          | j        ||||          }t	          | j        ||          }d|vri |d<   |d                             |           t          j        dk    rt          | d           t          | j        | j
        | |           t          | j                  | _        t          j        dk    rt          | d           d S d S )Nrc  r   zafter copy propzafter simplify)r  r   r   r  rd  r+   r
   rb  r  rO  rP  r@  )	rS  r?   rl   metadatain_cpsr   r   r  rc  s	            r   simplifyrh    s   w~w77IFA'77N& K ,GNKQQNx'')+H%&%%n555""w 1222 17GDDD!'.11GN""w 011111 #"r   c                       e Zd ZdS )GuardExceptionN)r,   r-   r.   r/   r   r   rj  rj    s        Dr   rj  c                     | st           dS )z?
    Raise GuardException if the given condition is False.
    Nrj  )r  s    r   requirerm  !  s       r   c                 6    	  | |i |S # t           $ r Y dS w xY w)z
    Run a function with given set of arguments, and guard against
    any GuardException raised by the function by returning None,
    or the expected return results if no such exception was raised.
    Nrl  )r   r   kwargss      r   r  r  (  s>    tT$V$$$   tts   
 
c                 J    	  | j         |fi |S # t          $ r t          w xY w)zm
    Same as func_ir.get_definition(name), but raise GuardException if
    exception KeyError is caught.
    )get_definitionKeyErrorrj  )rS  rT   ro  s      r   rq  rq  3  sC    
%w%d55f555   s    "c                    |t          j        t                    }|                                 D ]}|j        D ]}t          |t          j                  rG|j        j	        }|
                    |g           }|g k    r|||<   |                    |j                   t          |          t          v r&t          t          |                   } |||           |S )zBuild the definitions table of the given blocks by scanning
    through all blocks and instructions, useful when the definitions
    table is out-of-sync.
    Will return a new definition table if one is not passed.
    )collectionsdefaultdictr,  r  r   rN   r   rW   r  rT   getrX   r$   rw  build_defs_extensions)r   definitionsr  r8  rT   
definitionr&  s          r   r  r  =  s     !-d33 
% 
%J 		% 		%D$	** .{'(__T266
##(2K%!!$*---Dzz222)$t**5$$$$		% r   c                    t          t          |t          j                  o
|j        dk               |j        } || |          }g }d}	 t          |t          j        t          j        f          rg d}d}	|D ].}
t          |j	        |
          rt          |j	        |
          }	 n/|	rt          |	t                    st          |                    |	           |j	        }t          |t                    r|j        }t          |d          r|j        }|du}|o|dk    p|                    d          }|r5t          t$          |	          r |t          t$          |	          k    r|dgz  }nt          t$          j        |	          r&|t          t$          j        |	          k    r|ddgz  }nG|r|                    |           n/|j        j        }|d	k    rd
}|dk    r|                    |           nt          |t          j                  ru|j        dk    rj|j	        }|                    |j                   |r:|j        |v r1||j                 }t          |t0          j                  s
|d         |fS  || |          }n-|$d                    t7          |                    |fS t          i|d         d                    t7          |dd                             fS )az  Try to find a call expression's function and module names and return
    them as strings for unbounded calls. If the call is a bounded call, return
    the self object instead of module name. Raise GuardException if failed.

    Providing typemap can make the call matching more accurate in corner cases
    such as bounded call on an object which is inside another object.
    rf   NT)rT   r  r,   r-   r\   znumpy.r  builtin_function_or_methodbuiltinmoduler^   r   r   r   )rm  rN   r   rU   r  r   r]   r$  rY   r$   r^   r   rj  rX   r   _defnr-   ra  r\   r  	__class__r,   r  rT   r   r[   joinrv  )rS  r  r?   definition_findercallee
callee_defattrsobjr   r$   keydef_valmod_namemod_not_nonenumpy_toplevel
class_namer  s                    r   r  r  V  s)    JtRW%%;$'V*;<<<YF""7F33JE
C=!j29bj"9:: <	! 100DE  :+S11 #J$4c::EE  %
5# 6 6 %$$LL &G ':.. (!-w-- -"-  (t3". #E#+w#6 $D&.&9&9(&C&C  # +wue'<'< +#wue'<'<<<gY&EEelE22 +#wu|U'C'CCCh00EE! +LL***$.7
!===!*J))LL,,,
BG,, 	!)1K1K"CLL))) )38w..ch'!#u|44 ) 8S=(**7C88JJ xx00#55  {=!| 8SXXhuQRRy112222r   c                    t          t          |t          j                             t	          | |          }t          t          |t          j                             g d}t          |j        |v            |j        |j        fS )zCheck if a variable is constructed via build_tuple or
    build_list or build_set, and return the sequence and the
    operator, or raise GuardException otherwise.
    Note: only build_tuple is immutable, so use with care.
    )rV   
build_list	build_set)rm  rN   r   rQ   rq  rU   r  r   )rS  r   var_def	build_opss       r   find_build_sequencer    sv     JsBF##$$$Wc**GJw(())):::IGJ)#$$$='*$$r   c                     t          t          |t          j                             t	          | |          }t          t          |t          j        t          j        t          j        f                     |j        S )zvCheck if a variable is defined as constant, and return
    the constant value, or raise GuardException otherwise.
    )	rm  rN   r   rQ   rq  re   r]   r$  r$   )rS  r   r  s      r   
find_constr    sZ     JsBF##$$$Wc**GJw29bj ABBCCC=r   c                 n   ddl m} t          | d          r| j        }n:t          | d          r| j        }n"t          d                    |                     t          ||          }	t          |	j	                   t          |	j	        t                                                    |	_	        t          |	j	                                                  }
t                              |
           t!          |	j	                  }i }|                                D ]\  }}t%          |          ||<   t'          |	j	        |           |rn|                    |||	|d          \  }}}}d |D             }|D ]}|                    |           |                    |           |                    |           |	S )a  
    Compile a function or a make_function node to Numba IR.

    Rename variables and
    labels to avoid conflict if inlined somewhere else. Perform type inference
    if typingctx and other typing inputs are available and update typemap and
    calltypes.
    r   )typed_passescode__code__zfunction type not recognized {}Nc                 <    g | ]}|                     d           |S )arg.)ra  )r:   vnames     r   r@   z'compile_to_numba_ir.<locals>.<listcomp>  s+    NNNuU5E5Ef5M5MNUNNNr   )
numba.corer  rY   r  r  NotImplementedErrorr   get_ir_of_coderK  r   r;  r5   r'   r)   r   r+   r   r   r   r   type_inference_stager  )mk_funcglblsrk   	targetctxarg_typsr?   rl   r  r  f_irr>  r1   new_var_dictrT   r   	f_typemapf_return_typef_calltypesr   rP  r  s                        r   compile_to_numba_irr    s    ('''''w U|	*	%	% U!"C"J"J7"S"STTT%&&D 't{N4G4G4I4IJJDKDK$$&&''I)$$$ #4;//IL__&& 1 1	c*400Tdk<000  &3?3T3T9dHd4< 4<0	=+q ON	NNN	 	 	AMM!y!!!%%%Kr   c           
          | j                             dd                              dd          }d| d| d| d| d| 
}i }t          |||            |d	                     }| |_        | j         |_        |S )
a   
    Creates a function from a code object. Args:
    * fcode - the code object
    * func_env - string for the freevar placeholders
    * func_arg - string for the function args (e.g. "a, b, c, d=None")
    * func_clo - string for the closure args
    * glbls - the function globals
    <r   >zdef closure():
z
	def (z):
		return (z
)
	return closure)co_namer   execr  r,   )	fcodefunc_envfunc_argfunc_clor  sanitized_co_name	func_textr<   r&  s	            r   _create_function_from_code_objr    s     --c377??SII1H 1 1+1 1.61 1 (1 1 /1 1I CE3IAAJAJHr   c                    t          |j                  }d                    d t          |          D                       }d                    d t          |          D                       }d                    d t          |j                  D                       }t          |||||           }ddlm                     |          } G fdd	t                    } ||          j
        }	t          j                            d
|	           i }
ddl}|j        j                            ||j        j                            d          |
          }|                                 ddlm} ddlm}  |            } |            }|                    |	           |                    |	           t5          j        |          }|                    d           |S )zG
    Compile a code object to get its IR, ir.Del nodes are emitted
    
c                     g | ]}d |z  S )z	c_%d = Noner/   r:   r  s     r   r@   z"get_ir_of_code.<locals>.<listcomp>  s    DDD!/A-DDDr   ,c                     g | ]}d |z  S zc_%dr/   r  s     r   r@   z"get_ir_of_code.<locals>.<listcomp>      :::!:::r   c                     g | ]}d |z  S )zx_%dr/   r  s     r   r@   z"get_ir_of_code.<locals>.<listcomp>  s    FFF!FFFr   r   compilerc                       e Zd Z fdZdS )%get_ir_of_code.<locals>.DummyPipelinec                                                      | _        d | j        _        d | j        _        d | j        _        || j        _        d | j        _        d | j        _        d | j        _        d S r    )		StateDictstaterk   r  r   rS  r?   return_typerl   )r#   r  r  s     r   r%   z.get_ir_of_code.<locals>.DummyPipeline.__init__  sa    !++--DJ#'DJ #'DJ "DJO!%DJ!%DJ%)DJ"#'DJ   r   N)r,   r-   r.   r%   r  s   r   DummyPipeliner    s.        	( 	( 	( 	( 	( 	( 	(r   r  zbefore-inferenceNF)ReconstructSSA)PreLowerStripPhisT)rP   co_freevarsr  r   co_argcountr  r  r  run_frontendobjectr  r	   rewrite_registryapplynumba.core.inline_closurecallcoreinline_closurecallInlineClosureCallPasscpuParallelOptionsrR  numba.core.untyped_passesr  numba.core.typed_passesr  run_passr   rQ  )r  r  nfreer  r  r  r&  r   r  r  swappedr  inline_passr  r  reconstruct_ssaphistriprW  r  s                     @r   r  r    s    !""EyyDDuU||DDDEEHxx::U5\\:::;;HxxFFU53D-E-EFFFGGH&uh(',	. 	.A $#####			q	!	!B	( 	( 	( 	( 	( 	( 	( 	( 	( 	( M"#E##$6>>>G((((*/EE
EJN**5117< <KOO 988888999999$n&&O  ""HU###e&r**IMM$Ir   c                     | j         D ]i}t          |t          j                  rMt          |j        t          j                  r.|j        j        }|t          |          k     sJ ||         |_        jdS )z,
    Replace ir.Arg(...) with variables
    N)r   rN   r   rW   r$   r  r   rP   )r  r   r  rE  s       r   replace_arg_nodesr  6  sl     
 # #dBI&& 	#:dj"&+I+I 	#*"CT????cDJ
Fr   c                 r   |                                  D ] }|j        s|j        }t          |t          j                  r|j                                         |j                                        }t          |t          j                  r/t          |j        t          j	                  r|j        j
        dk    s
J d            |j                            t	          j        |j        j        ||j                             |j                            t	          j        ||j                             "dS )zN
    Return return statement by assigning directly to target, and a jump.
    r  zinvalid return castN)r  r   re  rN   r   r  r  rW   r$   rU   r  rX   r<   r   )r   r  r2  r  r  	cast_stmts         r   replace_returnsr  B  s     ? ?z 	dBI&& 	?JNN
((Iy")44 Iy88IO&&0003H001 Jbi	(=vtxPPQQQJbglDH==>>>? ?r   c                    |d         j         }|d         j        }t          j        |t	          d          |          }	t
          j                            t                    |	j	        <   t          j
        dt          |          }
t          j        |
|	|          }t          j                            |	| |          }t          j        |t	          d          |          }t          ||          }||j	        <   t          j        |||          }t          j                            ||d|          }fd|D             }|                    ||i           }|||<   t          j        |||          }|||gS )Nr   rB   rC   z$np_attr_attrr/   c                 *    g | ]}|j                  S r/   r   )r:   r  r?   s     r   r@   zgen_np_call.<locals>.<listcomp>f  s    ///Q///r   )r>   r<   r   rQ   r   r   rZ   r[   r\   rT   r]   rW   rU   r^   r_   rf   rg   )func_as_strr   rm   r   rk   r?   rl   r>   r<   rw   rx   ry   np_attr_callr{   func_var_typr|   np_call	arg_typesrR  	np_assigns        `              r   gen_np_callr  U  sK   GME
q'+C ve];77==H"Z..u55GHM9T5#&&D)D(C00K7??8[#>>Lve]?;;SAAH#D)44L)GHM)L(C88Kgll8T2s33G////$///I)))YCCH!Ig	'3,,Ii00r   c                 Z    t          | d           |j        D ]}t          d|           d S )N:z    )rc  r   )ro  r  r  s      r   
dump_blockr  l  s@    	%
  fd r   c                 Z    |                                  D ]\  }}t          ||           d S r    )r   r  )r   ro  r  s      r   dump_blocksr  q  s:     ! !u5%    ! !r   c                 j    t          | t          j                  ot          | dd          o| j        dv S )z3true if expr is unary or binary operator or getitemr  F)unarybinopr  r  r  )rN   r   rU   r^   r  )r  s    r   is_operator_or_getitemr  u  s=    tRW%% \dE**\[[]r   c                 >    t          |           pt          |           S )z8stmt is getitem assignment or setitem (and static cases))
is_getitem
is_setitemr  s    r   is_get_setitemr  {  s    d/z$///r   c                     t          | t          j                  o,t          | j        t          j                  o| j        j        dv S )z6true if stmt is a getitem or static_getitem assignmentr  )rN   r   rW   r$   rU   r  r  s    r   r  r    s?    tRY'' ?4:rw//?
!>>@r   c                 N    t          | t          j        t          j        f          S )z/true if stmt is a SetItem or StaticSetItem node)rN   r   r#  r!  r  s    r   r  r    s    dRZ)9:;;;r   c                     t          |           r(| j        j        dk    r| j        j        S | j        j        S t          |           r(t          | t          j                  r| j        S | j        S dS )z?get index variable for getitem/setitem nodes (and static cases)r  N)	r  r$   r  r   r"  r  rN   r   r#  r  s    r   index_var_of_get_setitemr    sp    $ (:=I%%:##:''$ "dBJ'' 	":>!4r   c                 2   t          |           r,| j        j        dk    r|| j        _        d S || j        _        d S t          |           r,t          | t          j                  r	|| _        d S || _        d S t          d
                    |                     )Nr  z0getitem or setitem node expected but received {})r  r$   r  r   r"  r  rN   r   r#  
ValueErrorr   )r  	new_indexs     r   set_index_var_of_get_setitemr    s    $ :=I%%(DJ#,DJ   	D		 dBJ'' 	'"DJJJ&DNNNKRR    	r   c                 0   t          | t                    sdS | j        }t          |          dk    s|d         t          k    rdS t          | d          sdS t          | dd          }t          |t                    sdS t          d |D                       S )z check if c is a namedtuple classFr   r   _make_fieldsNc              3   @   K   | ]}t          |t                    V  d S r    )rN   r   )r:   r&  s     r   r  z&is_namedtuple_class.<locals>.<genexpr>  s,      22az!S!!222222r   )rN   rw  	__bases__rP   rO   rY   r^   all)cbasesfieldss      r   is_namedtuple_classr    s    a uKE
5zzQ%(e++u1g uQ	4((Ffe$$ u226222222r   c                    | j         | j        }t          j        ||          }                    |          }|                     t          j        |||                     fd|D             }t          j                            ||d|          }	                    |          }
|                     t          j        |
|	|                     t          |          D ]g\  }}
                    |          }t          j                            |
|d|          }|                     t          j        |||                     h|                     t          j        ||	                     | S )
zFill *newblock* to call *callee* with arguments listed in *inputs*.
    The returned values are unwrapped into variables in *outputs*.
    The block would then jump to *label_next*.
    r$   r<   r<   r  r$   r<   c                 :    g | ]}                     |          S r/   	get_exactr:   rT   r>   s     r   r@   z(fill_block_with_call.<locals>.<listcomp>  s%    555dEOOD!!555r   r/   )r   r   rO  r<   N)r$   r   r"  r<   r  r<   )r>   r<   r   re   	make_temprX   rW   rU   rf   	enumerater  r  r   )newblockr  
label_nextinputsoutputsr<   fnfnvarr   callexprcallresr  r=   r  r  r>   s                  @r   fill_block_with_callr     sh   
 NE
,C	C	(	(	(BOOO$$EOOBIU"#>>>???5555f555Dw||Trs|CCHoo#o&&GOOBIWH#FFFGGGG$$ J J3%%'((wa37S ) B B	wCHHHIIIIOOBG:3777888Or   c                 Z   | j         }| j        fdt          |          D             }t          ||          D ]F\  }}t	          j        ||          }|                     t	          j        ||                     G|                     t	          j        |                     | S )z
    Fill a new block *block* that unwraps arguments using names in *inputs* and
    then jumps to *label_next*.

    Expected to use with *fill_block_with_call()*
    c                 D    g | ]\  }}t          j        ||           S ))rT   r   r<   )r   r  )r:   r  r   r<   s      r   r@   z(fill_callee_prologue.<locals>.<listcomp>  s>     + + +1 F,,, + + +r   )r>   rT   r<   r  r  )	r>   r<   r  zipr   rQ   rX   rW   r   )	r  r  r  r>   r   anameavaltmpr<   s	           @r   fill_callee_prologuer'    s     KE
)C+ + + +!&))+ + +D64(( A Atf5u#666RYc3???@@@@	LL
444555Lr   c                 T   | j         | j        }fd|D             }t          j                            ||          }                    |          }|                     t          j        |||                     |                     t          j        ||                     | S )z
    Fill a new block *block* to prepare the return values.
    This block is the last block of the function.

    Expected to use with *fill_block_with_call()*
    c                 <    g | ]}                     |           S )r   r  r  s     r   r@   z(fill_callee_epilogue.<locals>.<listcomp>  s'    ;;;4EOOO&&;;;r   )r   r<   r  r  r  )	r>   r<   r   rU   rV   r  rX   rW   r  )r  r  r<   valstupexprtupr>   s         @r   fill_callee_epiloguer-    s     KE
)C;;;;7;;;Dg!!#!66G
//c/
"
"C	LL#W#>>>???	LL#...///Lr   c                 X   t          | |          }t          |t          j        t          j        f          r|j        S t          |t          j                  rM|j        dk    rBt          | |j                  }	 t          ||j
                  }|S # t          $ r t          w xY wt          )zhCheck if a variable is a global value, and return the value,
    or raise GuardException otherwise.
    r^   )rq  rN   r   r]   r$  r$   rU   r  find_outer_valuer^   r  AttributeErrorrj  )rS  r   dfnprev_valvals        r   r/  r/    s     #
&
&C#	2:.// y#rw !CFi$7$7#GSY77	!(CH--CJ 	! 	! 	!  	! s   9B B"c                    g }| j         D ]f}||v r`t          ||         t          j        j                  r;||         j        dk    r*d                    |          }t          || j                  g| j	        
                                D ]}|                    t          j                  D ]q}t          |j        t          j                  rt|j        j        dk    rd|j        }t#          |dd          }|#t#          |dd          d}	d}
n|j        }	d	|	z  }
nd
}	d}
d|	d|
d}t          ||j        j                  t          |j        t          j        t          j        f          r|j        }t#          |dd          }|d}t          |t*          j                  r|t.          j        t.          j        hv }|st#          |dd          dk    }|r|                    |j                   t          |j        t          j                  r>|j        j        dk    r-|j        j        dk    r|j        j        j        }t          ||         t          j                  r|                     |          }t?          t@          | |          }|rg|d         dk    r[t#          tB          |d                   }tC          j"        |tB          j#                  stC          j"        |tB          j$                  rN|%                    d          rdnd                    |          }tM          d                    |          |j                  t          |j        t          j                  rq||j'        j                 }d}t#          |dd          s&t          |t          j(        t          j)        f          r&tM          |||j        j        |fz  |j                  t          |j        t          j*                  r| j+        sd}t          ||j                  stY          |          dk    r3d}d-                    d  |D                       }t          ||z            dS )!a&  
    Helper function to walk IR and raise if it finds op codes
    that are unsupported. Could be extended to cover IR sequences
    as well as op codes. Intended use is to call it as a pipeline
    stage just prior to lowering to prevent LoweringErrors for known
    unsupported features.
    i  a'  Tuple '{}' length must be smaller than 1000.
Large tuples lead to the generation of a prohibitively large LLVM IR which causes excessive memory pressure and large compile times.
As an alternative, the use of a 'list' is recommended in place of a 'tuple' as lists do not suffer from this problem.make_functionr  Nr  z$<creating a function from a closure>rE   z(%s) z<could not ascertain use case>zUNumba encountered the use of a language feature it does not support in this context: z (op code: make_function not supported). If the feature is explicitly supported it is likely that the result of the expression z'is being used in an unsupported manner.r$   Fr  gdb_internalr^   viewr   r\   r   r   z'{}' zZ'view' can only be called on NumPy dtypes, try wrapping the variable {}with 'np.<dtype>()'r  zThe use of a %s type, assigned to variable '%s' in globals, is not supported as globals are considered compile-time constants and there is no known way to compile a %s type as a constant.	reflectedz0The use of generator expressions is unsupported.av  Calling either numba.gdb() or numba.gdb_init() more than once in a function is unsupported (strange things happen!), use numba.gdb_breakpoint() to create additional breakpoints instead.

Relevant documentation is available here:
https://numba.readthedocs.io/en/stable/user/troubleshoot.html#using-numba-s-direct-gdb-bindings-in-nopython-mode

Conflicting calls found at:
 %sr  c                 6    g | ]}|                                 S r/   )	strformatr:   r  s     r   r@   z0raise_on_unsupported_feature.<locals>.<listcomp>  s     :::1:::r   ).rP  rN   r   rR   rS   countr   r   r<   r   r  
find_instsr   rW   r$   rU   r  r^   r  r]   r$  pytypesFunctionTyper  gdbgdb_initrX   r  rT   r  rq  r  r  r\   
issubdtypeintegerfloatingra  r   r  DictTypeListTyper.  is_generatorrP   r  )rS  r?   	gdb_callsarg_namemsgblkr  r3  r  user  foundr   dfcntyvardescrbufs                     r   raise_on_unsupported_featurerS    st    I % 5 5wgh')9)BCC 8"T))R
 SYRXYaRbRb  #3444~$$&& S: S:NN29-- R	: R	:D$*bg.. @:=O33*C #355D' #3	488D"HC#%DD"&,C#*S=DD>! !SS$$$(C +3
??? $*ry"*&=>> /jc7D11; c7#788 ?EIu~#>>E H#C"55GE /$$TX... $*bg.. 8:=I--$*/V2K2K**/C!'#,<< !  //44B}gr::B %bew..$UBqE22!,R?? % % 0U^ D D%$%(^^C%8%8QrrgnnS>Q>QH%Jx((dh8 8 8 8 $*bi00 UT[-.: BU33 UrENEN#CDDU%cR",E&E48TTTT $*bh// :8L :H&s9999eR	:j 9~~2 ii::	:::;;sSy))) r   c           	      p   |                                 D ]\  }}|j        r|                    d          r| j        }|                    d          d         }| j        j        }t          |t          j	                  rdnd}d}d|d|d	|d
|}	t          j        t          |	|                     d S )Nr  r   r   r,  rd  zrhttps://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-reflection-for-list-and-set-typeszR
Encountered the use of a type that is scheduled for deprecation: type 'reflected z' found for argument 'z' of function 'z'.

For more information visit r  )r   r8  ra  r<   splitr  r  rN   r   Listwarningswarnr   )
rS  r?   rT   rP  r<   r/  r  tynameurlrJ  s
             r   warn_deprecatedr[    s    MMOO L Lb< 	Lv&& Lkjjooa(5#-b%*#=#=H5$ !'UUUCC9 <ScJJJKKK!L Lr   c                      g  fd |          }|$|j         }D ]}t          ||d          }|s dS |S dS )ac  
    This returns the python function that is being getattr'd from a module in
    some IR, it resolves import chains/submodules recursively. Should it not be
    possible to find the python function being called None will be returned.

    func_ir - the FunctionIR object
    node - the IR node from which to start resolving (should be a `getattr`).
    c                 f   t          | dd          dk    rS                    d| j                   	                     | j                  } n# t
          $ r Y d S w xY w |           S t          | t          j        t          j	        f          r!t          | j        t          j                  r| S d S )Nr  Fr^   r   )r^   insertr  rq  r$   rr  rN   r   r]   r$  r>  
ModuleType)modrS  getattr_chainresolve_mods    r   rb  z-resolve_func_from_module.<locals>.resolve_mod  s    3e$$	11  CH---,,SY77   tt;s###bi455 	#)W%788 
ts   A 
AANF)r$   r^   )rS  r	  r`  defnr  ra  rb  s   `    @@r   resolve_func_from_modulerd    s     M       +d

C
y 	 	A4E**D  Ktr   c                     | j                                         D ]T}d |                    t          j                  D             }|r'd|d         z  }t          ||d         j                  UdS )z8
    Enforce there being no ir.Del nodes in the IR.
    c                     g | ]}|S r/   r/   r;  s     r   r@   z#enforce_no_dels.<locals>.<listcomp>  s    222a222r   zIllegal IR, del found at: %sr   r  N)r   r  r=  r   r  r   r<   )rS  rK  delsrJ  s       r   enforce_no_delsrh    s     ~$$&& 6 6223>>"&11222 	6047:Ca5555	66 6r   c                     | j                                         D ]K}d |                    d          D             }|r'd|d         z  }t          ||d         j                  LdS )z=
    Enforce there being no ir.Expr.phi nodes in the IR.
    c                     g | ]}|S r/   r/   r;  s     r   r@   z#enforce_no_phis.<locals>.<listcomp>  s    444a444r   phi)r  zIllegal IR, phi found at: %sr   r  N)r   r  
find_exprsr   r<   )rS  rK  phisrJ  s       r   enforce_no_phisrn    s     ~$$&& 6 6443>>U>33444 	6047:Ca5555	66 6r   c                 `    t          d |                                 D                       dk    S )zGCheck the given mapping of ir.Block for containing a single scope.
    c                     h | ]	}|j         
S r/   )r>   )r:   rK  s     r   r\  z(legalize_single_scope.<locals>.<setcomp>  s    555c	555r   r   )rP   r  )r   s    r   legalize_single_scoperq    s.     55V]]__55566!;;r   flagsnumba.core.compiler.Flagsc                     t          |            t          |            t          j        |           }|                    d|j                   dS )z4
    This checks that the IR presented is legal
    T)extend_lifetimesN)rn  rh  r   rQ  rR  dbg_extend_lifetimes)rS  rr  rW  s      r   check_and_legalize_irrw    sO     GG&w//IMM$)CMDDDDDr   c                    | j         }t          |j                  }g }|j        D ]}	                     |          }n)# t          $ r d|z  }t          || j                  w xY wt          |t          j	                  r|
                    |j                   wd|z  }t          || j                  d                    d t          |          D                       }d                    d t          |          D                       }	t          |j                  d}
|j        }                    | j                  }|dt          |t&                    rfd
|D             }t'          |          n"fd|j        D             }t'          |          t                    }
||
z
  d                    fdt                    D                       }|
r:fdt          |
          D             }|dz  }|d                    |          z  }j        j        j        }t1          ||||	|          S )z
    Converts a code object from a `make_function.code` attr in the IR into a
    python function, caller_ir is the FunctionIR of the caller and is used for
    the resolution of freevars.
    z\Cannot capture a constant value for variable '%s' as there are multiple definitions present.r  zbCannot capture the non-constant value associated with variable '%s' in a function that may escape.r  c                 "    g | ]\  }}d ||fz  S )z
	c_%d = %sr/   )r:   r  r  s      r   r@   z0convert_code_obj_to_function.<locals>.<listcomp>	  s%    QQQTQ-1a&0QQQr   r  c                     g | ]}d |z  S r  r/   r  s     r   r@   z0convert_code_obj_to_function.<locals>.<listcomp>	  r  r   r   Nc                 D    g | ]}                     |          j        S r/   rq  r$   r:   r  	caller_irs     r   r@   z0convert_code_obj_to_function.<locals>.<listcomp>	  s*    KKKq))!,,2KKKr   c                 D    g | ]}                     |          j        S r/   r|  r}  s     r   r@   z0convert_code_obj_to_function.<locals>.<listcomp>	  s:     0 0 0 ))!,,2 0 0 0r   c                 &    g | ]}d |         z  S )z%sr/   )r:   r  co_varnamess     r   r@   z0convert_code_obj_to_function.<locals>.<listcomp>	  s"    GGGQQ0GGGr   c                 <    g | ]}|z            d |         S )z = r/   )r:   r  r  kwarg_defaults_tupnargss     r   r@   z0convert_code_obj_to_function.<locals>.<listcomp>!	  sF     . . . "-QY!7!7!79KA9N9NO . . .r   z, )r  rP   r  rq  rr  r   r<   rN   r   re   rX   r$   r  r  r   r,  r  r  defaultsrO   r   r  r   __globals__r  )code_objr~  r  r  freevarsr  freevar_defrJ  r  r  n_kwargs	n_allargskwarg_defaultsdr  kw_constr  r  r  r  s    `               @@@r   convert_code_obj_to_functionr    s    ME!""E H 5 5	5#22155KK 	5 	5 	579:;Ccx|4444	5 k28,, 	5OOK-....BDEFCcx|4444yyQQYx=P=PQQQRRHxx::U5\\:::;;Hu())K H!I--h.?@@N!ne,, 	*KKKKNKKKA!&q0 0 0 0(.0 0 0A!&q)** ExxGGGG%,,GGGHHH (. . . . . ."8__. . .DDIIh''' ".E *%8X*/1 1 1s   A&A(c                 ^   i }|                                  D ]/}|j        }|j        D ]}|                                D ]}|||<   0|                                  D ]Q}|j        }|                                D ]3\  }}|j        |j        vr |j                            |j        |           4RdS )aa  Fixes the mapping of ir.Block to ensure all referenced ir.Var are
    defined in every scope used by the function. Such that looking up a variable
    from any scope in this function will not fail.

    Note: This is a workaround. Ideally, all the blocks should refer to the
    same ir.Scope, but that property is not maintained by all the passes.
    N)r  r>   r   rf  r   rT   	localvarsdefine)r   used_varrK  r>   r8  r   s         r   fixup_var_define_in_scoper  .	  s     H}} % %	H 	% 	%D~~'' % % $%	%
 }} 6 6	!)) 	6 	6ICxu..&&sx555		66 6r   c                     | j         }||u r| S |j        j                                        D ]0}|j        |j        vr |j                            |j        |           1|| _         | S )z5Transfer the ir.Block to use the given ir.Scope.
    )r>   r  _conr  rT   r  )r  r>   	old_scoper   s       r   transfer_scoper  H	  sr     IE"'..00 2 285?**O""38S111EKLr   c                 6    t          | t          j                  S r    )rN   r   	EnterWithr  s    r   is_setup_withr  X	  s    dBL)))r   c                 6    t          | t          j                  S r    )rN   r   
Terminatorr  s    r   is_terminatorr  \	  s    dBM***r   c                 6    t          | t          j                  S r    )rN   r   r  r  s    r   is_raiser  `	  s    dBH%%%r   c                 6    t          | t          j                  S r    )rN   r   r  r  s    r   	is_returnr  d	  s    dBI&&&r   c                 6    t          | t          j                  S r    )rN   r   PopBlockr  s    r   is_pop_blockr  h	  s    dBK(((r   )NNN)NNr    )NNT)NNNNN)rr  rs  )r\   r  r   r>  rt  rW  r  numba.core.extendingr   r  r   r   r   r   r	   r
   numba.core.typing.templatesr   numba.core.analysisr   r   r   numba.core.errorsr   r   r   r   rh   r   r   r   r5   r3   r6   r   r9   r_   r   r   r   r   r   r   r   r   r  r  r
  r  r   r  r  r1  r;  r=  r?  rG  rK  rM  rX  rO  rx  rh  r  r  rX   ry  r  r  r  r  r  r  ra  r  r  r  r  r  r  r  r  r  r  rA  r%  r`  r+  r-  r0  r6  r@  rN  rV  rY  r[  rX  r;  rd  rh  	Exceptionrj  rm  r  rq  r  rw  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r'  r-  r/  rS  r[  rd  rh  rn  rq  rw  r  r  r  r  r  r  r  r  r/   r   r   <module>r     s]               + + + + + + N N N N N N N N N N N N N N N N N N 1 1 1 1 1 15 5 5 5 5 5 5 5 5 5. . . . . . . . . . . .    	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	 	 	! ! !p p pf	 	 	A A A% % %P$8 $8 $8N> > >& & &R	 	 	  3 3 3   : : :9 9 9A A A    0 0 0f  ( #%   ,    "  :  	 	 	 <@&*   # # # #P  T T Tn    
   3 4 4 4. . .`    8        FJGKD" D" D" D"L
 
 
  "! "! "!J H  H  HJ  8$ 8$ 8$z #%  &*@ @ @ @D  2# # # #+ + + +`  4* 4* 4* 4*r     *  ) ) )X! ! !8     
2 2 2l     8    B  22 2 20	 	 	 	 	Y 	 	 	  	 	 	     .  )- K3 K3 K3 K3Z% % %   CG?C, , , ,\  .6 6 6p	 	 	? ? ?&1 1 1.  
! ! !] ] ]0 0 0
@ @ @< < <      3 3 3$  6  (  &  &x* x* x*vL L L*! ! !H6 6 66 6 6< < <E E E EA1 A1 A1H6 6 64   * * *+ + +& & &' ' ') ) ) ) )r   