+
    :in                         R t ^ RIt^ RIHt ^ RIHtHt ^RIHt ^ RI	H
t
HtHtHt ^ RIHt ]! RR4      t/ tR	 tR
 t]! RR4      tR tR tR tR tR t]! RR4      tR tR tR t/ tR tR# )z
Utils for IR analysis
N)reduce)
namedtupledefaultdict)CFGraph)typeserrorsirconsts)specialuse_defs_resultzusemap,defmapc           	        / p/ pV P                  4        EF,  w  r4\        4       ;W&   p\        4       ;W#&   pVP                   EF  p\        V4      \        9   d"   \        \        V4      ,          pV! WuV4       K9  \        V\        P                  4      '       Ed[   \        VP                  \        P                  4      '       d,   \        R VP                  P                  4        4       4      p	M\        VP                  \        P                  4      '       d"   \        VP                  P                  .4      p	Mz\        VP                  \        P                  \        P                  \        P                  \        P                   34      '       d   Rp	M\#        R\        VP                  4      4      hVP$                  P                  V	9  d&   VP'                  VP$                  P                  4       VP                  4        F1  p
V
P                  V9  g   K  VP'                  V
P                  4       K3  	  EK  	  EK/  	  \)        WR7      # )z"
Find variable use/def per block.
c              3   8   "   T F  qP                   x  K  	  R # 5iNname).0vars   & Q/var/www/html/photoedit/myenv/lib/python3.14/site-packages/numba/core/analysis.py	<genexpr>#compute_use_defs.<locals>.<genexpr>(   s     !M6Ls((6L   unreachable)usemapdefmap )itemssetbodytypeir_extension_usedefs
isinstancer   AssignvalueInst	list_varsVarr   ArgConstGlobalFreeVarAssertionErrortargetadd_use_defs_result)blocksvar_use_mapvar_def_mapoffsetir_blockuse_setdef_setstmtfuncrhs_setr   s   &          r   compute_use_defsr8      s   
 KK"LLN(+-g(+-gMMDDz11+DJ7TG,$		**djj"''22!!Mdjj6J6J6L!MMG

BFF33!4::??"34G

RVVRXXryy-/ZZ-9 : : G(TZZ8HII;;##72KK 0 01~~'887*KK) (' " +6 ;CC    c                   a aaa	a
 R o
V
3R lpV VV3R lpV V	V3R lp/ pVP                  4        F  p\        SV,          4      Wx&   K  	  \        \        4      o	V! VS	4       V! Wg4       V# )z
Find variables that must be alive at the ENTRY of each block.
We use a simple fix-point algorithm that iterates until the set of
live variables is unchanged for each block.
c                    \         ;QJ d"    . R V P                  4        4       F  NK  	  5# ! R V P                  4        4       4      # )zFHelper function to determine if a fix-point has been reached.
        c              3   8   "   T F  p\        V4      x  K  	  R # 5ir   )lenr   vs   & r   r   ?compute_live_map.<locals>.fix_point_progress.<locals>.<genexpr>E   s     2\SVV\r   )tuplevalues)dcts   &r   fix_point_progress,compute_live_map.<locals>.fix_point_progressB   s2     u2SZZ\2u2u2SZZ\222r9   c                P   < RpS! V4      pW#8w  d   V ! V4       TpS! V4      pK  R# )z4Helper function to run fix-point algorithm.
        Nr   )fnrC   	old_point	new_pointrD   s   &&  r   	fix_point#compute_live_map.<locals>.fix_pointG   s5     	&s+	$sG!I*3/I %r9   c                   < S Fb  pSV,          SV,          ,          pW;;,          V,          uu&   SP                  V4       F  w  r4W;;,          W,          ,          uu&   K!  	  Kd  	  R# )zGFind all variable definition reachable at the entry of a block
        N)
successors)rC   r1   used_or_definedout_blk_cfgr0   r/   s   &    r   	def_reach#compute_live_map.<locals>.def_reachQ   sR     "F)&1K4GGOK?*K!nnV4
+ 5	 "r9   c                   < V  FW  pW,          pSP                  V4       F7  w  r4VSV,          ,          pW;;,          VSV,          ,
          ,          uu&   K9  	  KY  	  R# )z/Find live variables.

Push var usage backward.
N)predecessors)	rC   r1   	live_varsinc_blk_data	reachablerQ   def_reach_mapr0   s	   &     r   liveness"compute_live_map.<locals>.liveness[   sR    
 FI"%"2"26":%g(>>		K,@ @@	 #; r9   )keysr   r   )rQ   r.   r/   r0   rJ   rR   r[   live_mapr1   rZ   rD   s   f&ff     @@r   compute_live_mapr_   <   sd    3
0,A H++-{623    $Mi'h!Or9   dead_maps_resultzinternal,escaping,combinedc                  aaa \        \        4      o\        \        4      o\        \        4      pVP                  4        EF
  w  rVSV,          W5,          ,          p\        V3R lV P	                  V4       4       4      p\        R VP
                  P                  4        4       4      p	\        \        P                  VP                  4       \        4       4      p
W,          p
Wz,
          pVSV&   W{,
          pVP                  4        F/  w  rWV,          ,          pSV;;,          W,
          ,          uu&   K1  	  V'       d   EK  WV&   EK  	  \        \        P                  SP                  4       \        4       4      p\        \        P                  SP                  4       \        4       4      p\        \        P                  SP                  4       \        4       4      p\        \        P                  VP                  4       \        4       4      pVV,          V,          pVV,
          pV'       d4   V P                  4       '       g   MRP                  V4      p\        V4      h\        VV3R lV 4       4      p\        SSVR7      # )z
Compute the end-of-live information for variables.
`live_map` contains a mapping of block offset to all the living
variables at the ENTRY of the block.
c              3   >   <"   T F  w  rVSV,          3x  K  	  R # 5ir   r   )r   rO   rX   r^   s   &  r   r   $compute_dead_maps.<locals>.<genexpr>   s%      !O7M^W #*8G+<!=7Ms   c              3   :   "   T F  pVP                   x  K  	  R # 5ir   r   r>   s   & r   r   rc      s      !K*IQ "#*Is   z#liveness info missing for vars: {0}c              3   V   <"   T F  pVSV,          SV,          ,          3x  K   	  R # 5ir   r   )r   kescaping_dead_mapinternal_dead_maps   & r   r   rc      s.      %# )!,/@/CCD#s   &))internalescapingcombined)r   r   r   dictrM   
terminatorr$   r   operatoror_rB   exit_pointsformatRuntimeError_dead_maps_result)rQ   r.   r^   r0   exit_dead_mapr1   r2   cur_live_setoutgoing_live_mapterminator_livesetcombined_livesetinternal_setescaping_live_setrO   new_live_setall_varsinternal_dead_varsescaping_dead_varsexit_dead_vars	dead_varsmissing_varsmsgrk   rg   rh   s   &&f&                   @@r   compute_dead_mapsr   v   s&    $C(#C($M"LLN  '+*==  !O7:~~f7M!O O ! !K*2*=*=*G*G*I!K K "(,,0A0H0H0J"%%) 	. $6$0&!(7%6%<%<%>!G'g*>>Lg&*;*JJ& &? ! $6&!; +@ hllHOO$5su=H.?.F.F.H #'.?.F.F.H #'HLL-*>*>*@#%HN#&88>IIi'L  7>>|LCs## %#% %H &7&7&.0 0r9   c                   a \        \        4      oV3R lpRpV! 4       pWV8w  di   V FW  pSV,          W',          ,          pWV,          ,          pV P                  V4       F  w  rSV	;;,          V,          uu&   K  	  KY  	  TpV! 4       pKn  S# )z
Compute the live variables at the beginning of each block
and at each yield point.
The ``var_def_map`` and ``var_dead_map`` indicates the variable defined
and deleted at each block, respectively.
c                  R   < \        \        \        S P                  4       4      4      # r   )rA   mapr=   rB   )block_entry_varss   r   rD   2compute_live_variables.<locals>.fix_point_progress   s    S.557899r9   N)r   r   rM   )rQ   r.   r0   var_dead_maprD   rH   rI   r1   availsuccrX   r   s   &&&&       @r   compute_live_variablesr      s     #3': I"$I 
  F$V,{/BBE&))E"~~f5 &%/&  6  	&(	r9   c                 <   \        4       pV  F  pVP                  V4       K  	  V P                  4        F9  w  r#VP                  pVP	                  4        F  pVP                  W%4       K  	  K;  	  VP                  \        V 4      4       VP                  4        V# r   )	r   add_noder   rm   get_targetsadd_edgeset_entry_pointminprocess)r.   rQ   rf   btermr+   s   &     r   compute_cfg_from_blocksr      s|    
)CQ  ||&&(FLL# ) 
 F$KKMJr9   c              #    "   \        4       pV P                  4       P                  4        Fo  p\        VP                  4      \        VP                  4      ,          \        VP
                  4      ,          pVP                  VP                  4       W,          pKq  	  V P                  4       P                  4        F#  pVP                  V9  g   K  \        W4      x  K%  	  R# 5i)zC
A generator that yields toplevel loops given a control-flow-graph
N)	r   loopsrB   r   entriesexitsdiscardheader_fix_loop_exit)rQ   blocks_in_looploopinsiderss   &   r   find_top_level_loopsr      s      UN		""$tyy>C$55DJJG%" %
 		""$;;n, ++ %s   CC%C%c                6   V P                  4       p\        \        P                  VP                   Uu. uF  q2V,          NK  	  upVP                  4      pV'       d7   VP
                  VP                  V,
          ,          pVP                  WER7      # V# u upi )z[
Fixes loop.exits for Py3.8+ bytecode CFG changes.
This is to handle `break` inside loops.
)r   r   )post_dominatorsr   rn   and_r   r   _replace)rQ   r   postdomsr   r   r   s   &&    r   r   r   
  s{     ""$H"jj)j!j)

E
 yy4::--}}5}44 	*s   B
	nullifiedz!condition, taken_br, rewrite_stmtc                H  aa+a,a-a.a/a0 ^ RI Ho/Ho0HpHp ^ o+V/V03R lpV-3R lo.V+V.3R lpV+V.3R lpV+V.3R lp ! R R\
        4      o,V,V3R	 lpS+^8  d5   \        R
P                  ^PR4      4       \        V P                  4       4       \        4       p	\        4       p
V P                  P                  4        F  w  rVP                   F  p\        V\        P                  4      '       g   K%  \        VP                   \        P"                  4      '       g   KQ  VP                   P$                  R8X  g   Kn  WVP                   &   WVP                   &   K  	  K  	  V! V 4      p. pV EF  w  o-pp. p\        V\        P"                  4      '       Ed   VP$                  R8X  d   TpVP&                  VP(                  3 F  pS,! 4       pS0! S/V V4      p\        V\        P*                  4      '       d   V! VP,                  4      pTpM$ V! V V4      pVf   \.        P0                  ! R4      p\        VS,4      '       d   K  VP3                  V4       K  	  \5        V4      ^8X  d:   V! S-VV.VO5!  w  ppV'       d    VP3                  \7        VVR4      4       EK2  EK5  EK8  S,! 4       p S/! V S-P8                  4      pV! V VP:                  ^ ,          4      pVf   \.        P0                  ! R4      p\        TS,4      '       d   EK  T! S-TT4      w  ppT'       g   EK  TP3                  \7        TTR4      4       EK  	  V Uu. uF  pVP<                  NK  	  ppV F  w  pppVV9   g   K  VP                   F  p\        V\        P                  4      '       g   K%  VP                   VJ g   K7  VVP-                  V4      ,          pVP>                  '       g   Kc  VP@                  p\        PB                  ! VVPD                  R7      Vn        V PF                  VPH                  PJ                  ,          pVP-                  V4      p VP                   VV &   K  	  EK   	  \M        V P                  4      p!V!PO                  4       p"V	P                  4        EFr  w  p#pVV"9   d   K  V!PQ                  V4       Uu. uF  pV^ ,          NK  	  p$p\S        V$4      \S        V#PT                  4      8w  g   K\  \5        V$4      ^8X  dD   V#PT                  P-                  V$^ ,          4      p%V#PV                  V%,          V
V#,          n        K  . p&. p'\Y        V#PV                  V#PT                  4       F1  w  p(p)V)V"9   d   K  V&P3                  V(4       V'P3                  V)4       K3  	  V#PV                  P[                  4        V#PV                  P]                  V&4       V#PT                  P[                  4        V#PT                  P]                  V'4       EKu  	  V" F  p*V P                  V* K  	  V'       d   \^        P`                  ! V 4      V n1        S+^8  d7   \        RP                  ^PR4      4       \        V P                  4       4       R# R#   T d     EL_i ; i  T d     ELi ; iu upi u upi )z
Removes dead branches based on constant inference from function args.
This directly mutates the IR.

func_ir is the IR
called_args are the actual arguments with which the function is called
)get_definitionguard
find_constGuardExceptionc                 2  < . pV P                   P                  4        F  pVP                  R,          p\        V\        P
                  4      '       g   K8  TpS	! SWP                  P                  4      pVf   K]  \        VRR4      R8X  g   Kq  S	! SWP                  4      pVf   K  \        V\        P                  4      '       g   K  VP                  \        J g   K  S	! SWP                  ^ ,          4      pVf   K  VP                  WGV34       K  	  V# )   Nopcall)r.   rB   r   r    r   Branchcondr   getattrr6   r(   r"   boolargsappend)
func_irbranchesblkbranch_or_jumpbranchpredfunction	conditionr   r   s
   &       r   find_branches(dead_branch_prune.<locals>.find_branches0  s    >>((*C XXb\N."))44'^Wkk6F6FG#dD(AV(K$^WiiHH ,"8RYY77$NNd2$).'99Q<$P	$0$OOV,DE + r9   c                    < V '       d   SP                   MSP                  p\        P                  ! VSP                  R 7      pW1P
                  R&   VSP                   8X  d   ^# ^ # )locr   )truebrfalsebrr   Jumpr   r   )take_truebrr   keepjmpr   s   &&  r   do_prune#dead_branch_prune.<locals>.do_pruneB  sI     +v}}ggd

+FMM)q0q0r9   c                   < Vw  rE\        V\        P                  4      p\        V\        P                  4      pV'       g	   V'       de    VP                  WE4      pS^ 8  d@   T'       d   T P
                  MT P                  p	\        RT	,          YTTP                  4       S! Y4      p
RT
3# R#   \         d    Ru # i ; iF
Pruning %sTFN)r    r   NoneTyperG   	Exceptionr   r   print)r   r   r   condslhs_condrhs_condlhs_nonerhs_noner   killtakenDEBUGr   s   &&&*       r   prune_by_type(dead_branch_prune.<locals>.prune_by_typeI  s     #h7h7x#'ll8> qy)4v~~&--lT)6Xll$[.E;  #""#s   B0 0C ?C c                    < Vw  rE VP                  WE4      pS^ 8  d?   T'       d   T P                  MT P                  p\	        RT,          YYQP                   4       S	! Yb4       RT3#   \         d    Ru # i ; ir   )rG   r   r   r   r   )
r   r   r   r   r   r   r   r   r   r   s
   &&&*    r   prune_by_value)dead_branch_prune.<locals>.prune_by_value\  sy    "	#,,x:K 19%06>>fmmD,%v<<P"
 [    		s   A) )A98A9c                 v  <  \        V\        P                  \        P                  \        P                  34      '       g   \        R 4      h\        VP                  4      pS^ 8  d4   T'       d   T P                  MT P                  p\        RT,          Y4       S! Y24      pRT3#   \
         d    Ru # i ; i)zExpected constant Numba IR noder   Tr   )r    r   r'   r)   r(   	TypeErrorr   r"   r   r   r   )r   r   r   r   r   r   r   r   s   &&&   r   prune_by_predicate-dead_branch_prune.<locals>.prune_by_predicatel  s    	 dRXXrzz299$EFF ABBtzz*K 19%06>>fmmD,%v4*U{  		s   >B(  B( (B87B8c                       ] tR tRtRtR# )"dead_branch_prune.<locals>.Unknowni{  r   N)__name__
__module____qualname____firstlineno____static_attributes__r   r9   r   Unknownr   {  s    r9   r   c                N  < SV ,          p\        V\        P                  4      '       d   V# \        V\        P                  4      '       dI   VP                  p\        V\        P                  4      '       d   V# Vf   \        P                  ! R4      # \        VRS! 4       4      # )z3
Resolves an input arg to a constant (if possible)
noneliteral_type)r    r   r   Omittedr"   r   )input_arg_idxinput_arg_tyvalr   called_argss   &  r   resolve_input_arg_const2dead_branch_prune.<locals>.resolve_input_arg_const~  s     #=1 lENN33 lEMM22$$C#u~~..
~~f--
 |^WY??r9   before-phibinopNr   TFr   after)2numba.core.ir_utilsr   r   r   r   objectr   centerdumprl   r.   r   r   r    r   r!   r"   Exprr   lhsrhsr&   indexr   r   r   r=   r   r   r   r   rewrite_stmttaken_brr'   r   _definitionsr+   r   r   
dead_nodesrU   r   incoming_blocksincoming_valueszipclearextendr	   ConstantInference_consts)1r   r   r   r   r   r   r   r   r   phi2lblphi2asgnlblr   r5   branch_infonullified_conditionsr   const_condspruneargresolved_constarg_def
prune_statr   	pred_callxdeadcondrP   r   nullified_info
branch_bitdefnsrepl_idxnew_cfgdead_blocksr   new_incomingidx
ic_val_tmp
ic_blk_tmpic_valic_blkdeadr   r   r   r   r   r   s1   &f                                         @@@@@@r   dead_branch_pruner*  #  sk   5 5 E$1&! & @. qyhoob#&'gllnfGvHNN((*HHD$		**djj"''22tzz}}7M*-DJJ'+/TZZ(	  +  (K"-	3i))illg.E"E!y}}5!(=grvv..%<W]]%KN)E)3GS)A)1-2^^F-CN ".'::&&~6% 6* ;1$$)&)S$O;$O!
E(//	)U:>1@ A  % %YN*7FKK@	!+GY^^A5F!G!)%*^^F%;N ng66$6vy#$N!
EJ(//	)U:?1A B_ #.B &::%9%9H:#48XXa++4%9(..:N%ON &222%3%<%<
"$((:155"A ' 4 4QXX]] C#(;;t#4*+''h  $^ &gnn5G$$&K MMOS+&-&:&:3&?@&?!&?@|C$7$7 88< A% ))//Q@&)&9&9#&>#  

&)#*=*=*-*=*='?NFF, "))&1"))&1'? ##))+##**:6##))+##**:65 $: NN4    227;qygnnR%&glln O * , " 2 ;n As1   #Y>&AZ?Z2Z>Z	Z	ZZc                  aaaa	a
 ^ pV^8  db   \        RV P                  P                  ,           P                  ^PR4      4       \        RP                  ^PR4      4       V P	                  4        V
3R loVVVV	3R lpVVVV	3R lp^ RIHoHo V P                  P                  4        Fx  pVP                   Fe  o	\        S	\        P                  4      '       g   K%  S	P                  o
\        S
\        P                  4      '       g   KS  V! S
W4       V! S
W4       Kg  	  Kz  	  V^8  d9   \        R	P                  ^PR4      4       V P	                  4        \        R4       R
# R
# )a8  
This rewrites values known to be constant by their semantics as ir.Const
nodes, this is to give branch pruning the best chance possible of killing
branches. An example might be rewriting len(tuple) as the literal length.

func_ir is the IR
called_args are the actual arguments with which the function is called
zrewrite_semantic_constants: r   r   *c                   < \         P                  ! W!P                  4      Vn        V P                  VP
                  P                  ,          pVP                  S4      pVP                  W4&   R# )zZ
Rewrites the stmt as a ir.Const new_val and fixes up the entries in
func_ir._definitions
N)r   r'   r   r"   r  r+   r   r  )r   r5   new_valr  r   r   s   &&&  r   rewrite_statement5rewrite_semantic_constants.<locals>.rewrite_statementY  sL    
 XXgxx0
$$T[[%5%56;;s#**r9   c                 P  < \        V R R4      R8X  d   V P                  R8X  d   S! SWP                  4      p\        V\        P
                  4      '       dK   W#P                  ,          p\        V\        P                  4      '       d   S! VSVP                  4       R# R# R# R# R# )r   Nr   ndim)
r   attrr"   r    r   r&   r  r   Arrayr2  )	r   r   r   r  argtyr   r   r/  r5   s	   &&&  r   rewrite_array_ndim6rewrite_semantic_constants.<locals>.rewrite_array_ndimc  s    3d#y0xx6!Cgrvv..'6E!%55)'4D 6 / " 1r9   c                   < \        V R R4      R8X  EdO   S! SWP                  4      pVEe5   \        V\        P                  4      '       Ed   \        VRR4      \
        J d   V P                  w  pS! SW4      p\        V\        P                  4      '       dK   W%P                  ,          p\        V\        P                  4      '       d   S	! VS
VP                  4       R# R# \        V\        P                  4      '       dX   VP                  R8X  dE   VP                  p\        V\        P                  4      '       d   S	! VS
VP                  4       R# R# R# R# R# R# R# R# )r   Nr   r"   typed_getitem)r   r6   r    r   r(   r=   r   r&   r  r   	BaseTuplecountr   r   dtype)r   r   r   r6   r  r  r5  r   r   r/  r5   s   &&&    r   rewrite_tuple_len5rewrite_semantic_constants.<locals>.rewrite_tuple_lenm  s   3d#v-((;D Zbii%@%@D'40C7=grvv..'6E!%99)'4E : "''22jjO3#MME!%99)'4E : 4 3 8 &A  .r9   )r   r   r   NzP--------------------------------------------------------------------------------)r   func_id	func_namer   r   r   r   r   r.   rB   r   r    r   r!   r"   r   )r   r   r   r6  r=  r   r   r   r/  r5   r   s   &&    @@@@@r   rewrite_semantic_constantsrA  H  s    Eqy-(()*0&S/	;hoob#&'%E EF F& :~~$$&HHD$		**jjc277++&sGA%c7@  ' qygnnR%&h r9   c                0   ^ RI Hp \        4       p/ pV P                  P	                  4        EF-  pVP                  RR7       EF  pVP                  VP                  WP                  4      p\        V\        P                  \        P                  34      '       d   VP                  pMVP                  VP                  W4      pV\        P                   J g   K  VP"                  w  p	V P                  V	4      p
\        V
\        P$                  4      '       g   K  V
P&                  pVP)                  V4       VP+                  WP,                  4       EK  	  EK0  	  V F  pW,          p\        V\.        P0                  4      ;'       d    VP2                  RJ pV'       d    WL,          p\4        P6                  ! W?R7      h\        V\.        P8                  \.        P0                  34      '       d   K  WL,          p\4        P6                  ! W?R7      h	  R# )a  An analysis to find `numba.literally` call inside the given IR.
When an unsatisfied literal typing request is found, a `ForceLiteralArg`
exception is raised.

Parameters
----------

func_ir : numba.ir.FunctionIR

argtypes : Sequence[numba.types.Type]
    The argument types.
)ir_utilsr   )r   Nr   )
numba.corerC  r   r.   rB   
find_exprsr   r   r6   r    r   r(   r)   r"   resolve_func_from_moduler
   	literallyr   r&   r  r,   
setdefaultr   r   InitialValueinitial_valuer   ForceLiteralArgLiteral)r   argtypesrC  marked_args	first_locr   assignr   fnobjr  defargargindexpos	query_argdo_raiser   s   &&              r   find_literally_callsrW    s    $%KI~~$$&nnn/F..!8!8';;OC#		2::677		 x'H'H'.5))) //4fbff--%||HOOH-((::> 0 '" M	y%*<*<= 4 4++t3 	.C((>>)emmU5G5G%HII.C((>> r9   c                    \        4       pV P                  4        FJ  pVP                   F7  p\        V4      \        9   g   K  \        \        V4      ,          pV! W14       K9  	  KL  	  V# )a  
Analyzes a dictionary of blocks to find variables that must be
stack allocated with alloca.  For each statement in the blocks,
determine if that statement requires certain variables to be
stack allocated.  This function uses the extension point
ir_extension_use_alloca to allow other IR node types like parfors
to register to be processed by this analysis function.  At the
moment, parfors are the only IR node types that may require
something to be stack allocated.
)r   rB   r   r   ir_extension_use_alloca)r.   use_alloca_varsr2   r5   r6   s   &    r   must_use_allocar[    sW     eOMMOMMDDz44.tDz:T+	 " $ r9   ) __doc__rn   	functoolsr   collectionsr   r   controlflowr   rD  r   r   r   r	   
numba.miscr
   r-   r   r8   r_   rs   r   r   r   r   r   r   r*  rA  rW  rY  r[  r   r9   r   <module>ra     s      /   0 0  /A   "DJ4n 13OP E0P&Z, * {$GH	bJ	DN-?`  r9   