U
    ?hC                     @   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   N/var/www/html/venv/lib/python3.8/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 k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 kst|jj}| }| j| D ]}||}t| }|r(| \}}	|	|j|	|j
|j}
|
r@tjsvtjrtd td|j  |	  td | }|||< |||f tjstjr@|  td q@q(| D ]\}}	|	|| kr|	  qddlm} ||j}|  dS )zGiven 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!   AssertionErrorr
   blockscopyr   r   itemspopr   r   r   r   DEBUGZDUMP_IRprintr   dumpr   r   verify
numba.corer$   ZPostProcessorrun)r   r   r   r&   Z
old_blocksr   ZrewriteZ	work_listkeyr   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