a
    ò.;bC  ã                   @   sH   d dl mZ d dlmZ G dd„ deƒZG dd„ deƒZeƒ ZejZ	dS )é    )Údefaultdict)Úconfigc                   @   s*   e Zd ZdZd	dd„Zdd„ Zdd„ ZdS )
ÚRewritez8Defines the abstract base class for Numba rewrites.
    Nc                 C   s   dS )z+Constructor for the Rewrite class.
        N© )ÚselfÚstater   r   ú;lib/python3.9/site-packages/numba/core/rewrites/registry.pyÚ__init__
   s    zRewrite.__init__c                 C   s   dS )z]Overload this method to check an IR block for matching terms in the
        rewrite.
        Fr   )r   Úfunc_irÚblockÚtypemapÚ	calltypesr   r   r   Úmatch   s    zRewrite.matchc                 C   s   t dƒ‚dS )zgOverload this method to return a rewritten IR basic block when a
        match has been found.
        z Abstract Rewrite.apply() called!N)ÚNotImplementedError©r   r   r   r   Úapply   s    zRewrite.apply)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r   r   r   r   r      s   
r   c                   @   s4   e Zd ZdZeddgƒZdd„ Zdd„ Zdd	„ Zd
S )ÚRewriteRegistryz+Defines a registry for Numba rewrites.
    zbefore-inferencezafter-inferencec                 C   s   t tƒ| _dS )ziConstructor for the rewrite registry.  Initializes the rewrites
        member to an empty list.
        N)r   ÚlistÚrewritesr   r   r   r   r	   !   s    zRewriteRegistry.__init__c                    s*   ˆ ˆj vrtdˆ f ƒ‚‡ ‡fdd„}|S )zf
        Decorator adding a subclass of Rewrite to the registry for
        the given *kind*.
        zinvalid kind %rc                    s,   t | tƒstd | ¡ƒ‚ˆjˆ   | ¡ | S )Nz {0} is not a subclass of Rewrite)Ú
issubclassr   Ú	TypeErrorÚformatr   Úappend)Úrewrite_cls©Úkindr   r   r   Údo_register.   s    
ÿz-RewriteRegistry.register.<locals>.do_register)Ú_kindsÚKeyError)r   r   r    r   r   r   Úregister'   s    
zRewriteRegistry.registerc                 C   s$  || j v sJ ‚|jj}| ¡ }| j| D ]°}||ƒ}t| ¡ ƒ}|r(| ¡ \}}	| |j|	|j	|j
¡}
|
r@tjsvtjrœtdƒ td|j ƒ |	 ¡  tdƒ | ¡ }|||< | ||f¡ tjsÆtjr@| ¡  tdƒ q@q(| ¡ D ]\}}	|	|| krâ|	 ¡  qâddlm} | |j¡}| ¡  dS )zŽGiven a pipeline and a dictionary of basic blocks, exhaustively
        attempt to apply all registered rewrites to all basic blocks.
        ZF______________________________________________________________________zREWRITING (%s):Z<____________________________________________________________r   )ÚpostprocN)r!   r
   ÚblocksÚcopyr   r   ÚitemsÚpopr   r   r   r   ÚDEBUGZDUMP_IRÚprintr   Údumpr   r   ZverifyÚ
numba.corer$   ZPostProcessorÚrun)r   r   r   r%   Z
old_blocksr   ZrewriteZ	work_listÚkeyr   ZmatchesZ	new_blockr$   Z	post_procr   r   r   r   6   s:    ÿ
zRewriteRegistry.applyN)	r   r   r   r   Ú	frozensetr!   r	   r#   r   r   r   r   r   r      s
   r   N)
Úcollectionsr   r,   r   Úobjectr   r   Zrewrite_registryr#   Zregister_rewriter   r   r   r   Ú<module>   s
   E