
    I/Ph                        d Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
mZmZmZ ddlmZ  G d dee          Z G d de          Z eg d	          Z G d
 de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d dee          Z G d dee          Z G d dee          Z G d de          Z G d  d!e          Z G d" d#e          Z  G d$ d%e           Z! G d& d'e           Z" G d( d)e          Z# G d* d+e          Z$ G d, d-e          Z% G d. d/e          Z& G d0 d1e          Z' G d2 d3e          Z( G d4 d5e          Z) G d6 d7e          Z* G d8 d9e          Z+ G d: d;e          Z, G d< d=e          Z- G d> d?e          Z. G d@ dAe          Z/ G dB dCe          Z0 G dD dEe1          Z2 G dF dGe          Z3 G dH dIe          Z4 G dJ dKe1          Z5 G dL dMe5          Z6 G dN dOe5          Z7 G dP dQe          Z8 G dR dSe          Z9 G dT dUe          Z:dVS )Wz)
Implementation of LLVM IR instructions.
    )types)
BlockFunctionValue
NamedValueConstantMetaDataArgumentMetaDataStringAttributeSet	UndefinedArgumentAttributes)_HasMetadatac                   ^     e Zd Zd	 fd	Zed             Zed             Zd Zd Zd Z	 xZ
S )
Instruction  c                    t          t          |                               |||           t          |t                    sJ t          |t
          t          f          sJ || _        || _        t          |          | _	        i | _
        d S Nname)superr   __init__
isinstancer   tuplelistopnameoperandsflagsmetadata)selfparenttypr   r   r   r   	__class__s          X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/llvmlite/ir/instructions.pyr   zInstruction.__init__   s~    k4  ))&#D)AAA&%(((((%%///// %[[
    c                     | j         j        S N)r!   functionr    s    r$   r(   zInstruction.function   s    {##r%   c                 $    | j         j        j        S r'   )r!   r(   moduler)   s    r$   r+   zInstruction.module   s    {#**r%   c                 6   | j         }| j        rd                    |g| j        z             }d                    d | j        D                       }| j        }|                     d          }|                    d                    ||||                     d S )N , c                 6    g | ]}|                                 S r   )get_reference.0ops     r$   
<listcomp>z%Instruction.descr.<locals>.<listcomp>"   s$    IIIRb..00IIIr%   Tleading_comma{0} {1} {2}{3}
)r   r   joinr   type_stringify_metadataappendformat)r    bufr   r   r"   r   s         r$   descrzInstruction.descr   s    : 	5XXvh344F99II4=IIIJJi++$+??

%F63(;;	= 	= 	= 	= 	=r%   c                     || j         v rQg }| j         D ]}|                    ||u r|n|           t          |          | _         |                                  d S d S r'   )r   r;   r   _clear_string_cache)r    oldnewopsr3   s        r$   replace_usagezInstruction.replace_usage(   ss    $-Cm 5 5

"))334444!#JJDM$$&&&&&  r%   c                 b    d| j         j        d| j        d| j        d| j        d| j        dS )Nz<ir.r-   z
 of type 'z
', opname z, operands >)r#   __name__r   r9   r   r   r)   s    r$   __repr__zInstruction.__repr__0   s=     N###TYYY			KKK( 	(r%   r   r   )rG   
__module____qualname__r   propertyr(   r+   r>   rD   rH   __classcell__r#   s   @r$   r   r      s              $ $ X$ + + X+= = =' ' '( ( ( ( ( ( (r%   r   c                   (    e Zd Z eg d          ZdS )CallInstrAttributes)
convergentnoreturnnounwindreadonlyreadnonenoinlinealwaysinlineNrG   rJ   rK   	frozenset_knownr   r%   r$   rP   rP   6   s3        Y @ @ @ A AFFFr%   rP   )tailmusttailnotailc                   (    e Zd Z eg d          ZdS )FastMathFlags)fastnnanninfnszarcpcontractafnreassocNrX   r   r%   r$   r_   r_   >   s.        Y * * * + +FFFr%   r_   c                        e Zd Z	 	 d fd	Zed             Zej        d             Zed             Zd Zed	             Z	d
 Z
d Z xZS )	CallInstrr   Nr   c
           	         |t          |t                    r|j        n|| _        t          |t                    r
|t
          v rn|rd}nd}|| _        t          |          | _        t          |          | _
        i | _        |	ro|	                                D ]Z\  }
}d|
cxk    rt          |          k     s$n t          d                    |
                    t!          |          | j        |
<   [t#          |          }t%          t          |j        j                            D ]}||         }|j        j        |         }t          |t*          j                  r|j        |k    rt1          |          }|j        |k    r.d                    d|z   ||j                  }t3          |          |||<   t5          t6          |                               ||j        j        d|gt#          |          z   |           d S )	Nr[   r   r   zInvalid argument index {}z%Type of #{0} arg mismatch: {1} != {2}   callr   )r   r   calling_conventioncconvstrTailMarkerOptionsr[   r_   fastmathrP   
attributesarg_attributesitemslen
ValueErrorr<   r   r   rangefunction_typeargsr   MetaDataTyper9   r	   	TypeErrorr   ri   r   return_type)r    r!   funcry   r   rn   r[   rq   attrs	arg_attrsidxiargexpected_typemsgr#   s                  r$   r   zCallInstr.__init__D   s&    :dH+E+E --  	
 dC   	T->%>%> 	DDD	%h//-e44  	E'oo// E E
US,,,,3t99,,,,$%@&,fSkk3 3 3+=e+D+D#C(( Dzzs4-23344 
	 
	Aq'C .3A6M=%*<== ,H--&s++x=((>q1umSX>> nn$DGGi''0B0N(.d0C$ 	( 	P 	P 	P 	P 	Pr%   c                     | j         d         S Nr   r   r)   s    r$   calleezCallInstr.calleeo       }Qr%   c                     || j         d<   d S r   r   )r    	newcallees     r$   r   zCallInstr.callees   s    $ar%   c                      | j         dd          S Nrk   r   r)   s    r$   ry   zCallInstr.argsw   s    }QRR  r%   c                 \    |j         | j        j         k    rt          d          || _        d S )Nz"New function has incompatible type)rx   r   r{   )r    newfuncs     r$   replace_calleezCallInstr.replace_callee{   s/     DK$===@AAAr%   c                     | j         S )zThe callee function)r   r)   s    r$   called_functionzCallInstr.called_function   s     {r%   c                 (   
  fd
d                     
fdt           j                  D                       } j        j        }|j        r|}n|j        }d                    | j                                                  } j	        rd                     j	        |          }d} j
        rd                     j
                  } j        r5dd                      j                            |j                            z   nd} j        r5dd                      j                            |j                            z   nd}	|                    d                    | j        ||	|||r                     d	
          nd                     d S )Nc                     | j         v r<d                    j         |                              |j                            dz   }nd}d                    |j        ||                                          S )Nr-   r   
{0} {1}{2})rs   r8   _to_listr9   r<   r0   )r   ar~   r    s      r$   	descr_argz#CallInstr._descr.<locals>.descr_arg   sj    D'''!4Q!7!@!@!H!HIICO&&qvuaoo6G6GHHHr%   r.   c                 .    g | ]\  }} ||          S r   r   )r2   r   r   r   s      r$   r4   z$CallInstr._descr.<locals>.<listcomp>   s'    KKKda))Aq//KKKr%   {0} {1}r   z{0} r-   z2{tail}{op}{fastmath} {callee}({args}){attr}{meta}
Tr5   )r[   r3   r   rq   ry   attrmeta)r8   	enumeratery   r   rx   var_argr|   r<   r0   rn   r[   rr   r   rq   r;   r   r:   )r    r=   add_metadatary   fntyty
callee_reftail_markerfn_attrsfm_attrsr   s   `         @r$   _descrzCallInstr._descr   s   	I 	I 	I 	I 	I yyKKKKi	6J6JKKKLL{(< 	"BB !B%%b$+*C*C*E*EFF
: 	B"))$*jAAJ9 	3 --	22K '3$/":":4;K"L"LMMMM$& 	 }%3$-"8"89I"J"JKKKK"$ 	 	

HOO{!*$***>>>') P 	
 	
 		 		 		 		 		r%   c                 4    |                      |d           d S )NTr   )r   r    r=   s     r$   r>   zCallInstr.descr   s    Cd+++++r%   )r   NNr   r   N)rG   rJ   rK   r   rL   r   setterry   r   r   r   r>   rM   rN   s   @r$   ri   ri   C   s        EI26)P )P )P )P )P )PV     X  ]% % ]% ! ! X!  
   X( ( (T, , , , , , ,r%   ri   c                   .     e Zd Z	 	 d fd	Z fdZ xZS )InvokeInstrr   Nr   c                     t          |t                    sJ t          |t                    sJ t          t          |                               |||||d||	|
	  	         d| _        || _        || _        d S )NF)r[   rq   r~   r   invoke)r   r   r   r   r   r   	normal_to	unwind_to)r    r!   r}   ry   r   r   r   rn   rq   r~   r   r#   s              r$   r   zInvokeInstr.__init__   s    )U+++++)U+++++k4  ))&$dE/4x05 	* 	L 	L 	L ""r%   c           	      6   t          t          |                               |d           |                    d                    | j                                        | j                                        |                     d                               d S )NFr   z.      to label {0} unwind label {1}{metadata}
Tr5   )r   )	r   r   r   r;   r<   r   r0   r   r:   )r    r=   r#   s     r$   r>   zInvokeInstr.descr   s    k4  ''%'@@@

DKKN((**N((**--D-AA L 
 
 	 	 	 	 	r%   )r   Nr   r   NrG   rJ   rK   r   r>   rM   rN   s   @r$   r   r      s\        FH>B	# 	# 	# 	# 	# 	#        r%   r   c                   $     e Zd Z fdZd Z xZS )
Terminatorc                     t          t          |                               |t          j                    ||           d S r'   )r   r   r   r   VoidType)r    r!   r   r   r#   s       r$   r   zTerminator.__init__   s@    j$((1A1A6)1	3 	3 	3 	3 	3r%   c                     | j         }d                    d | j        D                       }|                     d          }|                    d                    |||                     d S )Nr.   c                 h    g | ]/}d                      |j        |                                          0S r   r<   r9   r0   r1   s     r$   r4   z$Terminator.descr.<locals>.<listcomp>   sF     7 7 7"$ (..rw8H8H8J8JKK 7 7 7r%   Tr5   r   )r   r8   r   r:   r;   r<   )r    r=   r   r   r   s        r$   r>   zTerminator.descr   sz    99 7 7(,7 7 7 8 8++$+??

<&&vxBBCCCCCr%   r   rN   s   @r$   r   r      sN        3 3 3 3 3D D D D D D Dr%   r   c                       e Zd Zd ZdS )PredictableInstrc                 0   t          | j        d          g}|D ]L}|dk     rt          d          |                    t	          t          j        d          |                     M| j                            |          }|                     d|           d S )Nbranch_weightsr   z(branch weight must be a positive integer    prof)	r
   r+   rv   r;   r   r   IntTyper   set_metadata)r    weightsr   wmds        r$   set_weightszPredictableInstr.set_weights   s    "4;0@AAB 	< 	<A1uu !KLLLOOHU]2%6%6::;;;;[%%h//&"%%%%%r%   N)rG   rJ   rK   r   r   r%   r$   r   r      s#        & & & & &r%   r   c                   <     e Zd Zd fd	Zed             Zd Z xZS )RetNc                 j    ||gng }t          t          |                               |||           d S r'   )r   r   r   )r    r!   r   return_valuer   r#   s        r$   r   zRet.__init__   s;    %1%=L>>2c4!!&&(;;;;;r%   c                 .    | j         r| j         d         S d S r   r   r)   s    r$   r   zRet.return_value   s    = 	=##4r%   c                 2   | j         }|                     d          }|I|                    d                    | j        |j        |                                |                     d S |                    d                    | j        |                     d S )NTr5   r7   z{0}{1}
)r   r:   r;   r<   r   r9   r0   )r    r=   r   r   s       r$   r>   z	Ret.descr   s    (++$+??#JJ)t{L,=+99;;') )* * * * *
 JJz((h??@@@@@r%   r'   )rG   rJ   rK   r   rL   r   r>   rM   rN   s   @r$   r   r      sn        < < < < < <   X	A 	A 	A 	A 	A 	A 	Ar%   r   c                       e Zd ZdS )BranchNrG   rJ   rK   r   r%   r$   r   r              Dr%   r   c                       e Zd ZdS )ConditionalBranchNr   r   r%   r$   r   r      r   r%   r   c                   @     e Zd Z fdZed             Zd Zd Z xZS )IndirectBranchc                 l    t          t          |                               |||g           g | _        d S r'   )r   r   r   destinations)r    r!   r   addrr#   s       r$   r   zIndirectBranch.__init__  s5    nd##,,VVdVDDDr%   c                     | j         d         S r   r   r)   s    r$   addresszIndirectBranch.address  r   r%   c                 h    t          |t                    sJ | j                            |           d S r'   )r   r   r   r;   )r    blocks     r$   add_destinationzIndirectBranch.add_destination
  s5    %'''''  '''''r%   c           
         d | j         D             }|                    d                    | j        j        | j                                        d                    |          |                     d                               d S )Nc                 \    g | ])}d                      |                                          *S )z	label {0}r<   r0   )r2   blks     r$   r4   z(IndirectBranch.descr.<locals>.<listcomp>  sB     6 6 6 $**3+<+<+>+>?? 6 6 6r%   zindirectbr {0} {1}, [{2}]  {3}
r.   Tr5   )r   r;   r<   r   r9   r0   r8   r:   )r    r=   r   s      r$   r>   zIndirectBranch.descr  s    6 6#'#46 6 6

5<<LL&&((IIl##$$4$88	
 
 	 	 	 	 	r%   )	rG   rJ   rK   r   rL   r   r   r>   rM   rN   s   @r$   r   r     sq                 X ( ( (      r%   r   c                   @     e Zd Z fdZed             Zd Zd Z xZS )SwitchInstrc                 z    t          t          |                               |||g           || _        g | _        d S r'   )r   r   r   defaultcases)r    r!   r   valr   r#   s        r$   r   zSwitchInstr.__init__  s9    k4  ))&&3%@@@


r%   c                     | j         d         S r   r   r)   s    r$   valuezSwitchInstr.value   r   r%   c                     t          |t                    sJ t          |t                    st          | j        j        |          }| j                            ||f           d S r'   )r   r   r   r   r   r9   r   r;   )r    r   r   s      r$   add_casezSwitchInstr.add_case$  s]    %'''''#u%% 	14:?C00C
3,'''''r%   c                 >   d | j         D             }|                    d                    | j        j        | j                                        | j                                        d                    |          |                     d                               d S )Nc                     g | ]E\  }}d                      |j        |                                |                                          FS )z{0} {1}, label {2}r   )r2   r   r   s      r$   r4   z%SwitchInstr.descr.<locals>.<listcomp>+  s_     - - -S# &,,SXs7H7H7J7J-0->->-@-@B B - - -r%   z%switch {0} {1}, label {2} [{3}]  {4}
r-   Tr5   )	r   r;   r<   r   r9   r0   r   r8   r:   )r    r=   r   s      r$   r>   zSwitchInstr.descr*  s    - -!%- - - 	

;BBJOJ$$&&L&&((HHUOO$$4$88
 
 	 	 	 	 	r%   )	rG   rJ   rK   r   rL   r   r   r>   rM   rN   s   @r$   r   r     sq            
     X ( ( (
 
 
 
 
 
 
r%   r   c                       e Zd ZdS )ResumeNr   r   r%   r$   r   r   7  r   r%   r   c                   h     e Zd Zd fd	Zed             Zed             Zed             Zd Z xZ	S )	SelectInstrr   r   c                     |j         |j         k    sJ t          t          |                               ||j         d|||g||           d S )Nselectr   r   )r9   r   r   r   )r    r!   condlhsrhsr   r   r#   s          r$   r   zSelectInstr.__init__<  s`    x38####k4  ))&#(H+/c*:05 	* 	7 	7 	7 	7 	7r%   c                     | j         d         S r   r   r)   s    r$   r   zSelectInstr.condB  r   r%   c                     | j         d         S r   r   r)   s    r$   r   zSelectInstr.lhsF  r   r%   c                     | j         d         S )N   r   r)   s    r$   r   zSelectInstr.rhsJ  r   r%   c                    |                     d                    d                    | j                  | j        j        | j                                        | j        j        | j                                        | j        j        | j                                        | 	                    d                               d S )Nz)select {0} {1} {2}, {3} {4}, {5} {6} {7}
r-   Tr5   )
r;   r<   r8   r   r   r9   r0   r   r   r:   r   s     r$   r>   zSelectInstr.descrN  s    

?FFHHTZ  INDI3355HM481133HM481133$$4$88
 
 	 	 	 	 	r%   rI   )
rG   rJ   rK   r   rL   r   r   r   r>   rM   rN   s   @r$   r   r   ;  s        7 7 7 7 7 7     X      X      X       r%   r   c                   2     e Zd ZdZi Zdg f fd	Zd Z xZS )CompareInstrzinvalid-comparer   c                    || j         vrt          d|d| j                  |D ]%}|| j        vrt          d|d| j                  &| j        }t	          |j        t          j                  r2t          j        t          j        d          |j        j	                  }	nt          j        d          }	t          t          |                               ||	|||g||           || _        d S )Nzinvalid comparison z for zinvalid flag rk   )r   r   )VALID_OPrv   OPNAME
VALID_FLAGr   r9   r   
VectorTyper   countr   r   r   r3   )r    r!   r3   r   r   r   r   flagr   r"   r#   s             r$   r   zCompareInstr.__init__]  s   T]""*rrr4;;OPPP 	Q 	QD4?** jTTT4;;!OPPP +ch 011 	#"5=#3#3SX^DDCC-""ClD!!**63+1C:U04 	+ 	6 	6 	6 r%   c                 x   |                     d                    | j        d                    d | j        D                       | j        | j        d         j        | j        d                                         | j        d                                         | 	                    d                               d S )	Nz.{opname}{flags} {op} {ty} {lhs}, {rhs} {meta}
r   c              3       K   | ]	}d |z   V  
dS )r-   Nr   )r2   its     r$   	<genexpr>z%CompareInstr.descr.<locals>.<genexpr>p  s&      88r#(888888r%   r   rk   Tr5   )r   r   r3   r   r   r   r   )
r;   r<   r   r8   r   r3   r   r9   r0   r:   r   s     r$   r>   zCompareInstr.descrm  s    

DKK;''88TZ88888w}Q$a ..00a ..00)))== L 
 
 	 	 	 	 	r%   )rG   rJ   rK   r   r   r   r>   rM   rN   s   @r$   r   r   X  s[        FH24B       	 	 	 	 	 	 	r%   r   c                   @    e Zd ZdZdddddddd	d
dd
Z e            ZdS )	ICMPInstricmpequalz	not equalzunsigned greater thanzunsigned greater or equalzunsigned less thanzunsigned less or equalzsigned greater thanzsigned greater or equalzsigned less thanzsigned less or equal)
eqneugtugeultulesgtsgesltsleN)rG   rJ   rK   r   r   setr  r   r%   r$   r
  r
  y  sJ        F&*#'$(!% H JJJr%   r
  c                   ~    e Zd ZdZi dddddddd	d
dddddddddddddddddddddd d!Zh d"Zd#S )$	FCMPInstrfcmpfalsez#no comparison, always returns falseoeqzordered and equalogtzordered and greater thanogez!ordered and greater than or equaloltzordered and less thanolezordered and less than or equalonezordered and not equalordzordered (no nans)ueqzunordered or equalr  zunordered or greater thanr  z"unordered or greater than or equalr  zunordered or less thanr  zunordered or less than or equalunezunordered or not equalunozunordered (either nans)truez"no comparison, always returns true>   rf   rc   rd   r`   rb   ra   rg   re   N)rG   rJ   rK   r   r   r  r   r%   r$   r  r    s        F6" 	) 	2	
 	& 	/ 	& 	" 	# 	* 	3 	' 	0 	' 	(  	4!H$  JJJr%   r  c                   &     e Zd Zd fd	Zd Z xZS )	CastInstrr   c                 d    t          t          |                               ||||g|           d S r   )r   r(  r   )r    r!   r3   r   r"   r   r#   s         r$   r   zCastInstr.__init__  s4    i''R#T'JJJJJr%   c                     |                     d                    | j        | j        d         j        | j        d                                         | j        |                     d                               d S )Nz{0} {1} {2} to {3} {4}
r   Tr5   )r;   r<   r   r   r9   r0   r:   r   s     r$   r>   zCastInstr.descr  sv    

-44KM!!M!**,,I$$4$88
 
 	 	 	 	 	r%   r   r   rN   s   @r$   r(  r(    sR        K K K K K K      r%   r(  c                   &     e Zd Zd fd	Zd Z xZS )	LoadInstrr   Nc                     |Et          |t                    r|j        }n(|j        j        s|j        j        }nt          d          t          t          |           	                    ||d|g|           d | _
        d S )NzLoad lacks type.loadr   )r   AllocaInstrallocated_typer9   	is_opaquepointeerv   r   r-  r   align)r    r!   ptrr   r"   r#   s        r$   r   zLoadInstr.__init__  s    ;#{++ 5( X' 5h& !3444i''VcU'NNN


r%   c                     | j         \  }| j        d| j        z  }nd}|                    d                    | j        |j        |                                ||                     d                               d S )N
, align %dr   zload {0}, {1} {2}{3}{4}
Tr5   r   r4  r;   r<   r9   r0   r:   )r    r=   r   r4  s       r$   r>   zLoadInstr.descr  s    :! DJ/EEE

.55IH$$4$88
 
 	 	 	 	 	r%   r   Nr   rN   s   @r$   r-  r-    sL                   r%   r-  c                   $     e Zd Z fdZd Z xZS )
StoreInstrc                     t          t          |                               |t          j                    d||g           d S )Nstore)r   r;  r   r   r   )r    r!   r   r5  r#   s       r$   r   zStoreInstr.__init__  sD    j$((1A1A7*-s	5 	5 	5 	5 	5r%   c                     | j         \  }}| j        d| j        z  }nd}|                    d                    |j        |                                |j        |                                ||                     d                               d S )Nr7  r   zstore {0} {1}, {2} {3}{4}{5}
Tr5   r8  )r    r=   r   r5  r4  s        r$   r>   zStoreInstr.descr  s    =S:! DJ/EEE

3::HH$$4$88
 
 	 	 	 	 	r%   r   rN   s   @r$   r;  r;    sG        5 5 5 5 5      r%   r;  c                   &     e Zd Zd fd	Zd Z xZS )LoadAtomicInstrr   Nc                    |Et          |t                    r|j        }n(|j        j        s|j        j        }nt          d          t          t          |           	                    ||d|g|           || _
        || _        d S )NzLoad atomic lacks type.zload atomicr   )r   r0  r1  r9   r2  r3  rv   r   r@  r   orderingr4  )r    r!   r5  rB  r4  r   r"   r#   s          r$   r   zLoadAtomicInstr.__init__  s    ;#{++ <( X' <h& !:;;;ot$$--fc=/2e$ 	. 	@ 	@ 	@ 


r%   c                     | j         \  }|                    d                    | j        |j        |                                | j        | j        |                     d                               d S )Nz+load atomic {0}, {1} {2} {3}, align {4}{5}
Tr5   r   r;   r<   r9   r0   rB  r4  r:   )r    r=   r   s      r$   r>   zLoadAtomicInstr.descr  su    

AHHIHMJ$$4$88
 
 	 	 	 	 	r%   r9  r   rN   s   @r$   r@  r@    sL             	 	 	 	 	 	 	r%   r@  c                   $     e Zd Z fdZd Z xZS )StoreAtomicInstrc                     t          t          |                               |t          j                    d||g           || _        || _        d S )Nzstore atomic)r   rF  r   r   r   rB  r4  )r    r!   r   r5  rB  r4  r#   s         r$   r   zStoreAtomicInstr.__init__   sP    %%..vu~7G7G/=Sz	K 	K 	K 


r%   c                    | j         \  }}|                    d                    |j        |                                |j        |                                | j        | j        |                     d                               d S )Nz0store atomic {0} {1}, {2} {3} {4}, align {5}{6}
Tr5   rD  )r    r=   r   r5  s       r$   r>   zStoreAtomicInstr.descr  s    =S

FMMHHMJ$$4$88
 
 	 	 	 	 	r%   r   rN   s   @r$   rF  rF    sG            
 
 
 
 
 
 
r%   rF  c                   $     e Zd Z fdZd Z xZS )r0  c                     |r|gnd}t          t          |                               ||                                d||           || _        d | _        d S )Nr   alloca)r   r0  r   
as_pointerr1  r4  )r    r!   r"   r  r   r   r#   s         r$   r   zAllocaInstr.__init__  s]    #+E77k4  ))&#..2B2BH*2D	: 	: 	:!


r%   c                    |                     d                    | j        | j                             | j        rI| j        \  }|                     d                    |j        |                                                     | j        -|                     d                    | j                             | j        r+|                     | 	                    d                     d S d S )Nr   z	, {0} {1}z, align {0}Tr5   )
r;   r<   r   r1  r   r9   r0   r4  r   r:   )r    r=   r3   s      r$   r>   zAllocaInstr.descr  s    

9##DK1DEEFFF= 	H-CBJJ{))"'23C3C3E3EFFGGG:!JJ}++DJ77888= 	EJJt//d/CCDDDDD	E 	Er%   r   rN   s   @r$   r0  r0    sN            E E E E E E Er%   r0  c                   (     e Zd Z	 d fd	Zd Z xZS )GEPInstrNc           	      R   ||j         }|| _        n|j         j        s|j         }d }d}	|D ]:}
||                    |
          }}t	          |t
          j                  r|j        }	;t	          |t
          j                  st	          |t
          j                  r|}n|                    |	          }|j         j	        | _        nt          d          t          t          |                               ||d|gt          |          z   |           || _        || _        || _        d S )Nr   zGEP lacks type.getelementptrr   )r9   source_etyper2  gepr   r   PointerType	addrspacerL  r3  rv   r   rO  r   r   pointerindicesinbounds)r    r!   r5  rW  rX  r   rR  r"   lasttyplastaddrspacer   r#   s              r$   r   zGEPInstr.__init__'  s7   #(C ,D # 	0(CGM 6 6"CGGAJJgu'899 6$+$5MsE$566 4w(9::4nn]33 # 0D.///h&&vsO(+utG}}'<4 	' 	I 	I 	I r%   c                 2   d | j         D             }| j        rdnd}|                    d                    || j        | j        j        | j                                        d                    |          | 	                    d                               d S )Nc                 h    g | ]/}d                      |j        |                                          0S r   r   r2   r   s     r$   r4   z"GEPInstr.descr.<locals>.<listcomp>G  sD     * * * ##AFAOO,=,=>> * * *r%   zgetelementptr inboundsrQ  z{0} {1}, {2} {3}, {4} {5}
r.   Tr5   )
rW  rX  r;   r<   rR  rV  r9   r0   r8   r:   )r    r=   rW  r3   s       r$   r>   zGEPInstr.descrF  s    * * L* * *)-K%%O

077$<$<--//99W%%++$+??  	 	 	 	 	r%   r'   r   rN   s   @r$   rO  rO  &  sO        "! ! ! ! ! !>      r%   rO  c                   2     e Zd Zd fd	Zd Zd Zd Z xZS )PhiInstrr   c                 r    t          t          |                               ||dd||           g | _        d S )Nphir   r   )r   r_  r   	incomings)r    r!   r"   r   r   r#   s        r$   r   zPhiInstr.__init__U  sB    h&&vsE2D-2 	' 	4 	4 	4r%   c           
         d                     d | j        D                       }|                    d                    d                     | j                  | j        ||                     d                               d S )Nr.   c              3      K   | ]A\  }}d                      |                                |                                          V  BdS )z
[{0}, {1}]Nr   )r2   vbs      r$   r  z!PhiInstr.descr.<locals>.<genexpr>[  se       5 5!Q &,,Q__->->-.__->->@ @ 5 5 5 5 5 5r%   zphi {0} {1} {2} {3}
r-   Tr5   )r8   rb  r;   r<   r   r9   r:   )r    r=   incss      r$   r>   zPhiInstr.descrZ  s    yy 5 5%)^5 5 5 5 5 	

*1188DJ''9++$+??	  	 	 	 	 	r%   c                 l    t          |t                    sJ | j                            ||f           d S r'   )r   r   rb  r;   )r    r   r   s      r$   add_incomingzPhiInstr.add_incominge  s8    %'''''uen-----r%   c                 <    fd| j         D             | _         d S )Nc                 *    g | ]\  }}|u rn||fS r   r   )r2   r   r   rB   rA   s      r$   r4   z*PhiInstr.replace_usage.<locals>.<listcomp>j  s>     < < <(sC $'#::CC3= < < <r%   )rb  )r    rA   rB   s    ``r$   rD   zPhiInstr.replace_usagei  s9    < < < < <,0N< < <r%   )r   )rG   rJ   rK   r   r>   ri  rD   rM   rN   s   @r$   r_  r_  T  sj             
	 	 	. . .< < < < < < <r%   r_  c                   &     e Zd Zd fd	Zd Z xZS )ExtractElementr   c                 6   t          |j        t          j                  st	          d          t          |j        t          j                  st	          d          |j        j        }t          t          |           	                    ||d||g|           d S )N!vector needs to be of VectorType.index needs to be of IntType.extractelementr   )
r   r9   r   r  r{   r   elementr   rm  r   )r    r!   vectorindexr   r"   r#   s         r$   r   zExtractElement.__init__o  s    &+u'788 	A?@@@%*em44 	=;<<<k!nd##,,VS:J.4e_4 	- 	I 	I 	I 	I 	Ir%   c                     d                     d | j        D                       }|                    d                    | j        |                     d S )Nr.   c              3   p   K   | ]1}d                      |j        |                                          V  2dS r   Nr   r1   s     r$   r  z'ExtractElement.descr.<locals>.<genexpr>y  a       I I46 '--7B,,..0 0 I I I I I Ir%   {opname} {operands}
r   r   r8   r   r;   r<   r   r    r=   r   s      r$   r>   zExtractElement.descrx  y    99 I I:>-I I I I I

*11+ 2 : : 	; 	; 	; 	; 	;r%   r+  r   rN   s   @r$   rm  rm  n  sR        I I I I I I; ; ; ; ; ; ;r%   rm  c                   &     e Zd Zd fd	Zd Z xZS )InsertElementr   c                    t          |j        t          j                  st	          d          |j        |j        j        k    s2t	          d                    |j        j        |j                            t          |j        t          j                  st	          d          |j        }t          t          |           
                    ||d|||g|           d S )Nro  z$value needs to be of type {} not {}.rp  insertelementr   )r   r9   r   r  r{   rr  r<   r   r   r  r   )r    r!   rs  r   rt  r   r"   r#   s          r$   r   zInsertElement.__init__  s    &+u'788 	A?@@@zV[0006==K'5 56 6 6 %*em44 	=;<<<kmT""++FC-3UE,B 	, 	O 	O 	O 	O 	Or%   c                     d                     d | j        D                       }|                    d                    | j        |                     d S )Nr.   c              3   p   K   | ]1}d                      |j        |                                          V  2dS rw  r   r1   s     r$   r  z&InsertElement.descr.<locals>.<genexpr>  rx  r%   ry  rz  r{  r|  s      r$   r>   zInsertElement.descr  r}  r%   r+  r   rN   s   @r$   r  r    sR        O O O O O O; ; ; ; ; ; ;r%   r  c                   &     e Zd Zd fd	Zd Z xZS )ShuffleVectorr   c                 N   t          |j        t          j                  st	          d          |t
          k    r|j        |j        k    rt	          d          t          |t                    rXt          |j        t          j                  r9t          |j        j        t          j                  r|j        j        j	        dk    st	          d          t          j        |j        j        |j        j
                  }t          |t
          k    r|j        j
        nd|j        j
        z            t          fd|j        D                       s"t          d                                        t!          t"          |                               ||d|||g|	           d S )
Nz"vector1 needs to be of VectorType.z=vector2 needs to be Undefined or of the same type as vector1.r   z'mask needs to be a constant i32 vector.r   c              3   *   K   | ]}|j         v V  d S r'   )constant)r2   iiindex_ranges     r$   r  z)ShuffleVector.__init__.<locals>.<genexpr>  s*      FF"2;+-FFFFFFr%   zmask values need to be in {0}shufflevectorr   )r   r9   r   r  r{   r   r   rr  r   widthr  rw   allr  
IndexErrorr<   r   r  r   )	r    r!   vector1vector2maskr   r"   r  r#   s	          @r$   r   zShuffleVector.__init__  s   ',(899 	B@AAAi|w|++ !L M M M4** 	G49e&677	GDI-u}==	G "(B..EFFFw|3TY_EE&)33 $L..!"W\%7!79 9 FFFFFFFFF 	/66{CC   	mT""++FC-4gt,D4 	, 	Q 	Q 	Q 	Q 	Qr%   c                     |                     d                    d                    d | j        D                       |                     d                               d S )Nzshufflevector {0} {1}
r.   c              3   p   K   | ]1}d                      |j        |                                          V  2dS rw  r   r1   s     r$   r  z&ShuffleVector.descr.<locals>.<genexpr>  sT       6 6!# '--bgr7G7G7I7IJJ 6 6 6 6 6 6r%   Tr5   )r;   r<   r8   r   r:   r   s     r$   r>   zShuffleVector.descr  sx    

,3399 6 6'+}6 6 6 6 6++$+??  	 	 	 	 	r%   r+  r   rN   s   @r$   r  r    sR        Q Q Q Q Q Q.      r%   r  c                   &     e Zd Zd fd	Zd Z xZS )ExtractValuer   c                 .   |j         }	 |D ]}|j        |         }n<# t          t          f$ r( t	          dt          |          d|j                   w xY wt          t          |                               ||d|g|           || _	        || _
        d S )NCan't index at  in extractvaluer   )r9   elementsAttributeErrorr  r{   r   r   r  r   	aggregaterW  )r    r!   aggrW  r   r"   r   r#   s          r$   r   zExtractValue.__init__  s    h	9 & &l1o&
+ 	9 	9 	9)#G}}}}chh8 9 9 9	9 	lD!!**63,/5t 	+ 	= 	= 	= 	    9Ac           
         d | j         D             }|                    d                    | j        j        | j                                        d                    |          |                     d                               d S )Nc                 ,    g | ]}t          |          S r   ro   r]  s     r$   r4   z&ExtractValue.descr.<locals>.<listcomp>      000a3q66000r%   zextractvalue {0} {1}, {2} {3}
r.   Tr5   )rW  r;   r<   r  r9   r0   r8   r:   r    r=   rW  s      r$   r>   zExtractValue.descr  s    004<000

4;;>&>//1199W%%++$+??	  	 	 	 	 	r%   r+  r   rN   s   @r$   r  r    sL                   r%   r  c                   &     e Zd Zd fd	Zd Z xZS )InsertValuer   c           
         |j         }	 |D ]}|j        |         }n<# t          t          f$ r( t	          dt          |          d|j                   w xY w|j         |k    r2t	          d|dt          |          d|j         d|j                   t          t          |                               ||j         d||g|           || _	        || _
        || _        d S )Nr  r  zCan only insert z at z: got insertvaluer   )r9   r  r  r  r{   r   r   r  r   r  r   rW  )	r    r!   r  elemrW  r   r"   r   r#   s	           r$   r   zInsertValue.__init__  s   h	9 & &l1o&
+ 	9 	9 	9)#G}}}}chh8 9 9 9	9 9)"ssDMMMM3888TYYH I I Ik4  ))&#(M+.+D 	* 	B 	B 	B 
r  c                 T   d | j         D             }|                    d                    | j        j        | j                                        | j        j        | j                                        d                    |          |                     d                               d S )Nc                 ,    g | ]}t          |          S r   r  r]  s     r$   r4   z%InsertValue.descr.<locals>.<listcomp>  r  r%   z&insertvalue {0} {1}, {2} {3}, {4} {5}
r.   Tr5   )	rW  r;   r<   r  r9   r0   r   r8   r:   r  s      r$   r>   zInsertValue.descr  s    004<000

<CC>&(D(D(F(F:?DJ$<$<$>$>99W%%++$+??	  	 	 	 	 	r%   r+  r   rN   s   @r$   r  r    sL             $      r%   r  c                   $     e Zd Z fdZd Z xZS )Unreachablec                     t          t          |                               |t          j                    ddd           d S )Nunreachabler   r   r   )r   r  r   r   r   )r    r!   r#   s     r$   r   zUnreachable.__init__  sL    k4  ))&%.2B2B*7" 	* 	F 	F 	F 	F 	Fr%   c                     || j         dfz  }d S )N
)r   r   s     r$   r>   zUnreachable.descr  s    T""r%   r   rN   s   @r$   r  r    sL        F F F F F# # # # # # #r%   r  c                   (    e Zd ZddZd Zd Zd ZdS )	InlineAsmFc                 V    |j         | _        || _        || _        || _        || _        d S r'   )r|   r9   rx   asm
constraintside_effect)r    ftyper  r  r  s        r$   r   zInlineAsm.__init__  s0    %	"$&r%   c                     | j         rdnd}d}|                    |                    || j        | j                             d S )N
sideeffectr   z)asm {sideeffect} "{asm}", "{constraint}"
)r  r  r  )r  r;   r<   r  r  )r    r=   r  fmts       r$   r>   zInlineAsm.descr  sX    %)%5=\\2
:

3::)-  : : 	; 	; 	; 	; 	;r%   c                 Z    g }|                      |           d                    |          S Nr   )r>   r8   r   s     r$   r0   zInlineAsm.get_reference  s&    

3wws||r%   c                 \    d                     | j        |                                           S )Nr   r   r)   s    r$   __str__zInlineAsm.__str__	  s&    	4+=+=+?+?@@@r%   N)F)rG   rJ   rK   r   r>   r0   r  r   r%   r$   r  r    sZ        ' ' ' '; ; ;  
A A A A Ar%   r  c                   $     e Zd Z fdZd Z xZS )	AtomicRMWc                     t          t          |                               ||j        d||f|           || _        || _        d S )N	atomicrmwr   )r   r  r   r9   	operationrB  )r    r!   r3   r5  r   rB  r   r#   s          r$   r   zAtomicRMW.__init__  sM    i''+),c
 	( 	? 	? 	? r%   c                    | j         \  }}d}|                    |                    | j        |j        |                                |j        |                                | j        |                     d                               d S )NzBatomicrmw {op} {ptrty} {ptr}, {valty} {val} {ordering} {metadata}
Tr5   )r3   ptrtyr5  valtyr   rB  r   )r   r;   r<   r  r9   r0   rB  r:   )r    r=   r5  r   r  s        r$   r>   zAtomicRMW.descr  s    =S

3::$'H"%"3"3"5"5$'H"%"3"3"5"5'+}'+'?'?04 (@ (6 (6      	! 	! 	! 	! 	!r%   r   rN   s   @r$   r  r    sG        ! ! ! ! !! ! ! ! ! ! !r%   r  c                   (     e Zd ZdZ fdZd Z xZS )CmpXchgzdThis instruction has changed since llvm3.5.  It is not compatible with
    older llvm versions.
    c                     t          j        |j        t          j        d          g          }t	          t
          |                               ||d|||f|           || _        || _        d S )Nrk   cmpxchgr   )	r   LiteralStructTyper9   r   r   r  r   rB  failordering)
r    r!   r5  cmpr   rB  r  r   outtyper#   s
            r$   r   zCmpXchg.__init__(  st    )38U]15E5E*FGGgt%%fgy'*CoD 	& 	B 	B 	B (r%   c                 <   | j         \  }}}d}|                    |                    |j        |                                |j        |                                |                                | j        | j        |                     d                               d S )NzScmpxchg {ptrty} {ptr}, {ty} {cmp}, {ty} {val} {ordering} {failordering} {metadata}
Tr5   )r  r5  r   r  r   rB  r  r   )r   r;   r<   r9   r0   rB  r  r:   )r    r=   r5  cmpvalr   r  s         r$   r>   zCmpXchg.descr/  s    =VS,

3::CH"%"3"3"5"5!'"("6"6"8"8"%"3"3"5"5'+}+/+<'+'?'?04 (@ (6 (6  	  	  		! 		! 		! 		! 		!r%   rG   rJ   rK   __doc__r   r>   rM   rN   s   @r$   r  r  #  sQ         ) ) ) ) )! ! ! ! ! ! !r%   r  c                       e Zd Zd Zd ZdS )_LandingPadClausec                     || _         d S r'   )r   )r    r   s     r$   r   z_LandingPadClause.__init__@  s    


r%   c                 ~    d                     | j        | j        j        | j                                                  S )Nz{kind} {type} {value})kindr9   r   )r<   r  r   r9   r0   r)   s    r$   r  z_LandingPadClause.__str__C  s<    &--***,, . . . 	.r%   N)rG   rJ   rK   r   r  r   r%   r$   r  r  ?  s2          . . . . .r%   r  c                       e Zd ZdZdS )CatchClausecatchN)rG   rJ   rK   r  r   r%   r$   r  r  J  s        DDDr%   r  c                   "     e Zd ZdZ fdZ xZS )FilterClausefilterc                     t          |t                    sJ t          |j        t          j                  sJ t          t          |                               |           d S r'   )r   r   r9   r   	ArrayTyper   r  r   )r    r   r#   s     r$   r   zFilterClause.__init__Q  sW    %*****%*eo66666lD!!**511111r%   )rG   rJ   rK   r  r   rM   rN   s   @r$   r  r  N  s=        D2 2 2 2 2 2 2 2 2r%   r  c                   ,     e Zd Zd fd	Zd Zd Z xZS )LandingPadInstrr   Fc                 ~    t          t          |                               ||dg |           || _        g | _        d S )N
landingpadr   )r   r  r   cleanupclauses)r    r!   r"   r   r  r#   s        r$   r   zLandingPadInstr.__init__X  sG    ot$$--fc<37 	. 	9 	9 	9r%   c                 h    t          |t                    sJ | j                            |           d S r'   )r   r  r  r;   )r    clauses     r$   
add_clausezLandingPadInstr.add_clause^  s5    &"344444F#####r%   c           
          d}|                     |                    | j        | j        rdndd                    d | j        D                                            d S )Nz$landingpad {type}{cleanup}{clauses}
z cleanupr   c                 8    g | ]}d                      |          S )z

      {0})r<   )r2   r  s     r$   r4   z)LandingPadInstr.descr.<locals>.<listcomp>f  s<     /K /K /K39 0=/C/CF/K/K /K /K /Kr%   )r9   r  r  )r;   r<   r9   r  r8   r  )r    r=   r  s      r$   r>   zLandingPadInstr.descrb  s    5

3::4948L&Hjjb&(gg /K /K=A\/K /K /K 'L 'L      	! 	! 	! 	! 	!r%   )r   F)rG   rJ   rK   r   r  r>   rM   rN   s   @r$   r  r  W  s[             $ $ $! ! ! ! ! ! !r%   r  c                   2     e Zd ZdZh dZd fd	Zd Z xZS )Fencez|
    The `fence` instruction.

    As of LLVM 5.0.1:

    fence [syncscope("<target-scope>")] <ordering>  ; yields void
    >   acq_relacquirereleaseseq_cstNr   c                 ,   t          t          |                               |t          j                    dd|           || j        vr=d}t          |                    |d                    | j                                      || _	        || _
        d S )Nfencer   r   z3Invalid fence ordering "{0}"! Should be one of {1}.r.   )r   r  r   r   r   VALID_FENCE_ORDERINGSrv   r<   r8   rB  targetscope)r    r!   rB  r  r   r   r#   s         r$   r   zFence.__init__v  s    eT##FEN,<,<gr)- 	$ 	/ 	/ 	/4555ICS[[)-43M)N)NP P Q Q Q &r%   c                     | j         d}nd                    | j                   }d}|                    |                    || j                             d S )Nr   zsyncscope("{0}") zfence {syncscope}{ordering}
)	syncscoperB  )r  r<   r;   rB  )r    r=   r  r  s       r$   r>   zFence.descr  si    #II+2243CDDI-

3::	'+}      	! 	! 	! 	! 	!r%   r  )rG   rJ   rK   r  r  r   r>   rM   rN   s   @r$   r  r  k  se          IHH' ' ' ' ' '	! 	! 	! 	! 	! 	! 	!r%   r  c                   (     e Zd ZdZ fdZd Z xZS )Commentz
    A line comment.
    c                     t          t          |                               |t          j                    ddd           d|vs
J d            || _        d S )N;r   r   r   r  zComment cannot contain new line)r   r  r   r   r   text)r    r!   r  r#   s      r$   r   zComment.__init__  sb    gt%%fen.>.>R+- 	& 	/ 	/ 	/4!B			r%   c                 @    |                     d| j                    d S )Nz; )r;   r  r   s     r$   r>   zComment.descr  s%    

#	##$$$$$r%   r  rN   s   @r$   r  r    sQ             % % % % % % %r%   r  N);r  llvmlite.irr   llvmlite.ir.valuesr   r   r   r   r   r	   r
   r   r   r   llvmlite.ir._utilsr   r   rP   rY   rp   r_   ri   r   r   r   r   r   r   r   r   r   r   r   r
  r  r(  r-  r;  r@  rF  r0  rO  r_  rm  r  r  r  r  r  objectr  r  r  r  r  r  r  r  r  r   r%   r$   <module>r     s         ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? , + + + + +'( '( '( '( '(*l '( '( '(TA A A A A, A A A
 I<<<== + + + + +L + + +
m, m, m, m, m, m, m, m,`    )   *
D 
D 
D 
D 
D 
D 
D 
D	& 	& 	& 	& 	&{ 	& 	& 	&A A A A A* A A A0	 	 	 	 	Z 	 	 		 	 	 	 	(* 	 	 	    %z   0    "J   <	 	 	 	 	Z 	 	 	    +   :    ;   B       "       0              <       *    k   8    {   (E E E E E+ E E E&+ + + + +{ + + +\< < < < <{ < < <4; ; ; ; ;[ ; ; ;"; ; ; ; ;K ; ; ;*    K   @    ;   6    +   <# # # # #+ # # #A A A A A A A A.! ! ! ! ! ! ! !,! ! ! ! !k ! ! !8. . . . . . . .    #   2 2 2 2 2$ 2 2 2! ! ! ! !k ! ! !(! ! ! ! !K ! ! !B% % % % %k % % % % %r%   