+
    :i@                     r   R t ^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHtHtHt ^ RIHtHt ^ RIHt ]P(                  ! ]4      tR	 t ! R
 R4      tR tR tR tR tR tR tR tR t R t!R t"R t# ! R R4      t$ ! R R]$4      t% ! R R4      t& ! R R]$4      t' ! R R ]$4      t(R! t)R# )"a  
Implement Dominance-Fronter-based SSA by Choi et al described in Inria SSA book

References:

- Static Single Assignment Book by Inria
  http://ssabook.gforge.inria.fr/latest/book.pdf
- Choi et al. Incremental computation of static single assignment form.
N)reduce)copy)defaultdict)config)irir_utilserrors)
OrderedSet_lazy_pformat)compute_cfg_from_blocksc                :    \        V P                  4      V n        V # )zfApply SSA reconstruction algorithm on the given IR.

Produces minimal SSA using Choi et al algorithm.
)_run_ssablocks)func_irs   &L/var/www/html/photoedit/myenv/lib/python3.14/site-packages/numba/core/ssa.pyreconstruct_ssar      s    
 gnn-GNN    c                   ,   a  ] tR t^$t o R tR tRtV tR# )_CacheListVarsc                    / V n         R # N_savedselfs   &r   __init___CacheListVars.__init__%   s	    r   c                    V P                   P                  V4      pVf    VP                  4       ;V P                   V&   pV# r   )r   get	list_vars)r   instgots   && r   r   _CacheListVars.get(   s8    kkood#;&*nn&66DKK
r   r   N)__name__
__module____qualname____firstlineno__r   r   __static_attributes____classdictcell____classdict__s   @r   r   r   $   s      r   r   c           	     p   V '       g   / # \        V 4      p\        V4      p\        W4      p\        4       pV FS  p\        P                  RV4       \        W4      w  r\        P                  R\        V4      4       \        WWaVV4      p KU  	  \        V 4      pWq8w  d   \        P                  ! R4      hV # )z7Run SSA reconstruction on IR blocks of a function.
    zFix SSA violator on var %szReplaced assignments: %szCFG mutated in SSA pass)r   _iterated_domfronts_find_defs_violatorsr   _loggerdebug_fresh_varsr
   _fix_ssa_varsr   CompilerError)r   cfgdf_plus	violatorscache_list_varsvarnamedefmapcfg_posts   &       r   r   r   /   s     	
!&
)C!#&G$V1I$&O ('	

 %V50-2GH vW.0  'v.H""#<==Mr   c                   \        V 4      pWR&   W&R&   \        \        4      ;VR&   pW6R&   \        WB4      VR&   \	        W\        V4      4      pVP                  4        F$  w  rW,          pWP                  ,           Vn        K&  	  V# )z=Rewrite all uses to ``varname`` given the definition map
    r7   r8   phimapr3   phi_locations)_make_statesr   list_compute_phi_locations_run_block_rewrite_FixSSAVarsitemsbody)r   r7   r8   r3   r4   r6   statesr;   	newblockslabelphilistcurblks   &&&&&&      r   r1   r1   S   s     &!F98 +D 11F8v5M4WEF?"6;3OPI ,,.!+ ) r   c           	        V P                  4       P                  4        UUu/ uF  w  rV\        V4      bK  	  pppRpV'       dz   RpVP                  4        Fa  w  r\        \        P
                  V Uu. uF  qSV,          NK  	  up\        4       4      pVP                  V4      '       g   KW  W&,          pRpKc  	  K  V# u uppi u upi )zCompute the iterated dominance frontiers (DF+ in literatures).

Returns a dictionary which maps block label to the set of labels of its
iterated dominance frontiers.
TF)dominance_frontierrB   setr   operatoror_
difference)r3   kvs	domfronts
keep_goingvinners   &      r   r,   r,   e   s     *-)?)?)A)G)G)IJ)ICG)IIJJ

__&EA8<<)C1A,,)CSUKE##!
	 '
  K
 *Ds   C5Cc                 ~    \        4       pVP                  4        F  w  r4V'       g   K  W V,          ,          pK   	  V# r   )rK   rB   )iterated_dfr8   r<   deflabeldefstmtss   &&   r   r?   r?   w   s8     EM$lln822M - r   c                v    \        V 4      pWR&   \        \        4      ;VR&   p\        W\	        4       4      pWC3# )z(Rewrite to put fresh variable names
    r7   r8   )r=   r   r>   r@   _FreshVarHandler)r   r7   rD   r8   rE   s   &&   r   r0   r0      sC     &!F9 +D 11F8v"63C3EFIr   c                 <    V P                  4       vrVP                  # r   )valuesscope)r   first_s   &  r   
_get_scoper`      s    IE;;r   c           	        \        \        4      p\        \        4      p\        W#R7      p\	        W\        4       4       \        P                  R\        V4      4       \        VP                  4        UUu. uF  w  rV\        V4      ^8  g   K  VNK  	  upp4      pVP                  4       pVP                  4        Fd  w  rYWW9  g   K  V	 FQ  p
W,          pW%,           UU
u0 uF  w  rV
kK	  	  ppp
VP                  V4      '       d   K?  VP                  V4        Kb  	  Kf  	  \        P                  R\        V4      4       V# u uppi u up
pi )zY
Returns
-------
res : Set[str]
    The SSA violators in a dictionary of variable names.
)defsuseszdefs %szSSA violators %s)r   r>   rK   dict_run_block_analysis_GatherDefsHandlerr.   r/   r
   r	   rB   len
dominatorsintersectionadd)r   r3   rb   rc   rD   rO   rP   r5   doms
use_blocksrF   dom_assign
def_labelss   &&            r   r-   r-      s    tDsDt'F(:(<=MM)]401 4::<G<%!3r7Q;AA<GHI>>D#k:>'C'e'
C!..s33MM!$ $ & MM$mI&>? H Ds   6E
E
"E
c                     V P                  4        F2  w  r4\        P                  R V4       W1R&   \        WV4       F  pK  	  K4  	  R# )z"==== SSA block analysis pass on %srF   N)rB   r.   r/   _run_ssa_block_pass)r   rD   handlerrF   blkr_   s   &&&   r   re   re      s>    lln
:EBw$V':A ; %r   c                 <   / pV P                  4        F  w  rE\        P                  R V4       \        P                  ! VP
                  VP                  R7      p. pWAR&   WQR&   \        WV4       F  pVf   Q hVP                  V4       K  	  Wvn	        WcV&   K  	  V# )z!==== SSA block rewrite pass on %s)r]   locrF   block)
rB   r.   r/   r   Blockr]   ru   rq   appendrC   )	r   rD   rr   rE   rF   rs   newblknewbodystmts	   &&&      r   r@   r@      s    Illn
95A		sww7ww'W=D###NN4  > !% % r   c                 ,    \        \        V 4      R 7      # ))r]   )rd   r`   )r   s   &r   r=   r=      s      r   c              #   X  "   \         P                  R V4       VP                   F  p\         P                  RV4       \        V\        P
                  4      '       d   VP                  W4      pMVP                  W4      pWCJd   Ve   \         P                  RV4       Vx  K  	  R# 5i)z
Running %szon stmt: %sNzreplaced with: %s)r.   r/   rC   
isinstancer   Assign	on_assignon_other)rD   rs   rr   r{   rets   &&&  r   rq   rq      s}     MM,(mT*dBII&&##F1C""60C?sMM-s3	 s   B(B*c                   0   a  ] tR t^t o RtR tR tRtV tR# )_BaseHandlerzGA base handler for all the passes used here for the SSA algorithm.
    c                    R# )a2  
Called when the pass sees an ``ir.Assign``.

Subclasses should override this for custom behavior

Parameters
-----------
states : dict
assign : numba.ir.Assign

Returns
-------
stmt : numba.ir.Assign or None
    For rewrite passes, the return value is used as the replacement
    for the given statement.
N )r   rD   assigns   &&&r   r   _BaseHandler.on_assign       r   c                    R# )aE  
Called when the pass sees an ``ir.Stmt`` that's not an assignment.

Subclasses should override this for custom behavior

Parameters
-----------
states : dict
assign : numba.ir.Stmt

Returns
-------
stmt : numba.ir.Stmt or None
    For rewrite passes, the return value is used as the replacement
    for the given statement.
Nr   r   rD   r{   s   &&&r   r   _BaseHandler.on_other   r   r   r   N	r#   r$   r%   r&   __doc__r   r   r'   r(   r)   s   @r   r   r      s     $ r   r   c                   0   a  ] tR tRt o RtR tR tRtV tR# )rf   i  aB  Find all defs and uses of variable in each block

``states["label"]`` is a int; label of the current block
``states["defs"]`` is a Mapping[str, List[Tuple[ir.Assign, int]]]:
    - a mapping of the name of the assignee variable to the assignment
      IR node and the block label.
``states["uses"]`` is a Mapping[Set[int]]
c                F   VR ,          VP                   P                  ,          P                  W!R,          34       VP                  4        FQ  pVP                  pWBP                   P                  8w  g   K+  VR,          V,          P	                  VR,          4       KS  	  R# )rb   rF   rc   N)targetnamerx   r   rj   )r   rD   r   varrO   s   &&&  r   r   _GatherDefsHandler.on_assign  sq    vv}}))*116'?2KL##%CAMM&&&vq!%%fWo6 &r   c                    VP                  4        F5  pVP                  pVR ,          V,          P                  VR,          4       K7  	  R# )rc   rF   N)r   r   rj   )r   rD   r{   r   rO   s   &&&  r   r   _GatherDefsHandler.on_other  s7    >>#CA6N1!!&/2 $r   r   Nr   r)   s   @r   rf   rf     s     73 3r   rf   c                   >   a  ] tR tRt o R t]P                  tRtV t	R# )UndefinedVariablei  c                    \        R 4      h)zNot intended for instantiation)NotImplementedErrorr   s   &r   r   UndefinedVariable.__init__  s    !"BCCr   r   N)
r#   r$   r%   r&   r   r   	UNDEFINEDr   r'   r(   r)   s   @r   r   r     s     D \\Fr   r   c                   0   a  ] tR tRt o RtR tR tRtV tR# )rZ   i#  z9Replaces assignment target with new fresh variables.
    c                   VP                   P                  VR ,          8X  Ed$   VR,          pVR,          p\        V4      ^ 8X  d   VP                   p\        P	                  RV4       VP                  VP
                  9  dH   RVP                  : R2p\        P                  ! \        P                  ! VVP                  R7      4       M1VP                  VP                   P                  VP                  R7      p\        P                  ! VVP                  VP                  R7      pWAR,          ,          P                  V4       V# )	r7   r]   r8   zfirst assign: %sz	variable z is not in scope.ru   r   valueru   rF   )r   r   rg   r.   r/   	localvarswarningswarnr   NumbaIRAssumptionWarningru   redefiner   r   r   rx   )r   rD   r   r]   r8   	newtargetwmsgs   &&&    r   r   _FreshVarHandler.on_assign&  s    ==	!227OEH%F6{a"MM	0)<>>8&y~~&88IJDMM&"A"A$&,jj#2 3 "NN6==+=+=6::NN	YY llJJF
 '?#**62r   c                    V# r   r   r   s   &&&r   r   _FreshVarHandler.on_other<  s    r   r   Nr   r)   s   @r   rZ   rZ   #  s     , r   rZ   c                   X   a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tRR
 ltRtV tR# )rA   i@  a2  Replace variable uses in IR nodes to the correct reaching variable
and introduce Phi nodes if necessary. This class contains the core of
the SSA reconstruction algorithm.

See Ch 5 of the Inria SSA book for reference. The method names used here
are similar to the names used in the pseudocode in the book.
c                    Wn         R # r   _cache_list_vars)r   r6   s   &&r   r   _FixSSAVars.__init__I  s     /r   c                v   VP                   p\        V\        P                  4      '       d   V P	                  WV P
                  P                  VP                   4      4      pVe   VP                  \        P                  Jd   VR,          VP                  P                  8w  dd   VR,          VP                  /p\        V4      p\        P                  ! W54       \        P                  ! VP                  VVP                  R7      # V# \        V\        P                  4      '       d   V P	                  WV.4      pVex   VP                  \        P                  JdZ   VR,          VP                  P                  8w  d8   \        P                  ! VP                  VP                  VP                  R7      # V# )Nr7   r   )r   r~   r   Inst_fix_varr   r   r   r   r   r   r   replace_vars_innerr   ru   Var)r   rD   r   rhsnewdefreplmaps   &&&   r   r   _FixSSAVars.on_assignL  sC   llc277##]] 5 5 9 9&,, GF !fmm2<<&G)$(:(::%i0&--@Gs)C//=99%}}!"JJ    RVV$$]]6C59F!fmm2<<&G)$(:(::99%}}$mm"JJ  r   c                P   V P                  WV P                  P                  V4      4      pVew   VP                  \        P
                  JdY   VR,          VP                  P                  8w  d7   VR,          VP                  /p\        V4      p\        P                  ! W$4       V# )Nr7   )
r   r   r   r   r   r   r   r   r   replace_vars_stmt)r   rD   r{   r   r   s   &&&  r   r   _FixSSAVars.on_otherk  s    $//33D9
 &--r||"Ci FMM$6$66!),fmm<Dz**49r   c                    V Uu. uF  qDP                   NK  	  ppVR,          pWe9   d   V P                  W4      # R# u upi )z0Fix all variable uses in ``used_vars``.
        r7   N)r   	_find_def)r   rD   r{   	used_varsrO   varnamesphivars   &&&&   r   r   _FixSSAVars._fix_varv  sC     %..IqFFI.	">>&//  /s   =c                   \         P                  RVR,          V4       RpVR,          pVR,          V,          pVR,          V,          pVR,          pV P                  W'4      p\        V4       F1  p	V P                  WVR7      p
W8  d   T	p MW9   g   K(  VR
,          p M	  Vf   V P	                  WVP
                  R	7      pV# )z?Find definition of ``stmt`` for the statement ``stmt``
        zfind_def var=%r stmt=%sr7   NrF   r8   r;   rv   )stopr   )r.   r/   _stmt_indexreversed_find_def_from_topru   )r   rD   r{   selected_defrF   
local_defs
local_phisrv   cur_posdefstmtdef_poss   &&&        r   r   _FixSSAVars._find_def~  s     	/	1BDIwH%e,
H%e,
w""4/
+G&&wG&DG &&)"~ , 22488 3 L r   c                   \         P                  RV4       VR,          pVR,          pVR,          pVR,          pW'9   EdL   VR,          pVR,          P                  pVP                  VR,          VR	7      p	\        P
                  ! V	\        P                  P                  VR	7      VR
7      p
\         P                  RW4       WR,          P                  ^ V
4       Wb,          P                  V
4       VP                  V4       F  w  rV P                  WVR	7      p\         P                  RV4       V
P                  P                  P                  VP                  4       V
P                  P                  P                  V4       K  	  V
# VP!                  4       V,          pW8X  d   \#        VR,          V4       \$        # \         P                  RW4       V P                  WVR	7      # )zFind definition reaching block of ``label``.

This method would look at all dominance frontiers.
Insert phi node if necessary.
zfind_def_from_top label %rr3   r8   r;   r<   r]   rv   r7   r   r   zinsert phi node %s at %szincoming_def %szidom %s from label %s)r.   r/   ru   r   r   r   Exprphiinsertrx   predecessors_find_def_from_bottomr   incoming_valuesr   incoming_blocksimmediate_dominators"_warn_about_uninitialized_variabler   )r   rD   rF   ru   r3   r8   r;   r<   r]   freshvarphinodepredr_   incoming_defidoms   &&&&           r   r   _FixSSAVars._find_def_from_top  s    	2E:Um!!/!7OE/%%C~~fY&7S~AHiiggkkck*G
 MM4gEM  G,M  )++E2#99c  :   />--44\5H5HI--44T: 3 N++-e4D} 36)3DcJ((MM14?--f-DDr   c                    \         P                  RV4       VR,          pWB,          pV'       d   VR,          pV# V P                  WVR7      # )z<Find definition from within the block at ``label``.
        zfind_def_from_bottom label %rr8   r   r   )r.   r/   r   )r   rD   rF   ru   r8   rb   lastdefs   &&&&   r   r   !_FixSSAVars._find_def_from_bottom  sK     	5u=!}2hGN**6c*BBr   c                    \        \        VP                  4      4      RV  F  pVP                  V,          VJ g   K  Vu # 	  \        VP                  4      # )zyFind the positional index of the statement at ``block``.

Assumptions:
- no two statements can point to the same object.
N)rangerg   rC   )r   r   rv   r   is   &&&& r   r   _FixSSAVars._stmt_index  sG     s5::'.Azz!}' / 5::r   r   N)r   )r#   r$   r%   r&   r   r   r   r   r   r   r   r   r   r'   r(   r)   s   @r   rA   rA   @  s:     0>	08,E\
C r   rA   c                     \         P                  '       d2   \        P                  ! \        P
                  ! R V  2VR7      4       R# R# )z Detected uninitialized variable r   N)r   ALWAYS_WARN_UNINIT_VARr   r   r   NumbaWarning)r7   ru   s   &&r   r   r     s:    $$$27)<	
 %r   )*r   loggingrL   r   	functoolsr   r   collectionsr   numbar   
numba.corer   r   r   numba.core.utilsr	   r
   numba.core.analysisr   	getLoggerr#   r.   r   r   r   r1   r,   r?   r0   r`   r-   re   r@   r=   rq   r   rf   r   rZ   rA   r   r   r   r   <module>r      s         #  + + 6 7 

H
% !H$$
<"
% %P3 32 | :`, `F
r   