a
    –§»a�)  ã                   @   sj  d dl mZmZmZmZmZ d dlmZ d dlm	Z	 d dl
mZ eddƒZG dd„ deƒZG dd	„ d	eƒZddd„Zdd„ Zdd„ Zdd„ Zdd„ ZG dd„ de	ƒZG dd„ dejƒZG dd„ deƒZG dd„ deƒZejejj_ejgejj_ejejj_ejgejj _ejejgejj!_eejj!_ejgejj"_eejj"_ejgejj#_eejj#_ejej$gejj%_eejj%_ejgejj&_ejgejj'_ejgejj(_ejegejj)_ejgejj*_ejgejj+_ejgejj,_ejgejj-_ejgejj._ejgejj/_ejgejj0_ejgejj1_ejgejj2_ejgejj3_ejgejj4_ejgejj5_ejeegejj6_dS )é    )Úc_boolÚc_intÚc_size_tÚ	StructureÚbyref)Ú
namedtuple)ÚIntFlag)ÚffiÚ
PruneStatsz&basicblock diamond fanout fanout_raisec                   @   s    e Zd ZdZdd„ Zdd„ ZdS )r
   z4 Holds statistics from reference count pruning.
    c                 C   sN   t |tƒs d}t| t|ƒ¡ƒ‚t| j|j | j|j | j|j | j|j ƒS )Nz;PruneStats can only be added to another PruneStats, got {}.©	Ú
isinstancer
   Ú	TypeErrorÚformatÚtypeÚ
basicblockÚdiamondÚfanoutÚfanout_raise©ÚselfÚotherÚmsg© r   úW/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/llvmlite/binding/passmanagers.pyÚ__add__   s    



ýzPruneStats.__add__c                 C   sN   t |tƒs d}t| t|ƒ¡ƒ‚t| j|j | j|j | j|j | j|j ƒS )NzBPruneStats can only be subtracted from another PruneStats, got {}.r   r   r   r   r   Ú__sub__   s    



ýzPruneStats.__sub__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r
   
   s   	c                   @   s(   e Zd ZdefdefdefdefgZdS )Ú_c_PruneStatsr   r   r   r   N)r   r   r   r   Ú_fields_r   r   r   r   r    "   s
   ür    Fc                 C   s>   t ddddƒ}t| ƒ}tj t|ƒ|¡ t|j|j|j	|j
ƒS )z± Returns a namedtuple containing the current values for the refop pruning
    statistics. If kwarg `printout` is True the stats are printed to stderr,
    default is False.
    r   )r    r   r	   ÚlibZLLVMPY_DumpRefPruneStatsr   r
   r   r   r   r   )ZprintoutÚstatsZdo_printr   r   r   Údump_refprune_stats*   s    ÿr$   c                 C   s   t j t| ƒ¡ dS )z¸Enable or disable the pass timers.

    Parameters
    ----------
    enable : bool
        Set to True to enable the pass timers.
        Set to False to disable the pass timers.
    N)r	   r"   ZLLVMPY_SetTimePassesr   )Úenabler   r   r   Úset_time_passes8   s    	r&   c                  C   s@   t  ¡ �$} t j | ¡ t| ƒW  d  ƒ S 1 s20    Y  dS )a  Returns the pass timings report and resets the LLVM internal timers.

    Pass timers are enabled by ``set_time_passes()``. If the timers are not
    enabled, this function will return an empty string.

    Returns
    -------
    res : str
        LLVM generated timing report.
    N)r	   ÚOutputStringr"   ZLLVMPY_ReportAndResetTimingsÚstr)Úbufr   r   r   Úreport_and_reset_timingsD   s    
r*   c                   C   s   t ƒ S ©N)ÚModulePassManagerr   r   r   r   Úcreate_module_pass_managerT   s    r-   c                 C   s   t | ƒS r+   )ÚFunctionPassManager)Úmoduler   r   r   Úcreate_function_pass_managerX   s    r0   c                   @   s,   e Zd ZdZdZdZdZeeB eB eB ZdS )ÚRefPruneSubpassesé   é   é   é   N)r   r   r   ZPER_BBZDIAMONDZFANOUTZFANOUT_RAISEÚALLr   r   r   r   r1   \   s
   r1   c                   @   s°   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zejd&fd'd(„Zd)S )*ÚPassManagerzPassManager
    c                 C   s   | j  | ¡ d S r+   )Z_capiÚLLVMPY_DisposePassManager©r   r   r   r   Ú_disposeh   s    zPassManager._disposec                 C   s   t j | ¡ dS )zQSee http://llvm.org/docs/Passes.html#constmerge-merge-duplicate-global-constants.N)r	   r"   ÚLLVMPY_AddConstantMergePassr9   r   r   r   Úadd_constant_merge_passk   s    z#PassManager.add_constant_merge_passc                 C   s   t j | ¡ dS )zKSee http://llvm.org/docs/Passes.html#deadargelim-dead-argument-elimination.N)r	   r"   Ú LLVMPY_AddDeadArgEliminationPassr9   r   r   r   Úadd_dead_arg_elimination_passo   s    z)PassManager.add_dead_arg_elimination_passc                 C   s   t j | ¡ dS )zNSee http://llvm.org/docs/Passes.html#functionattrs-deduce-function-attributes.N)r	   r"   ÚLLVMPY_AddFunctionAttrsPassr9   r   r   r   Úadd_function_attrs_passs   s    z#PassManager.add_function_attrs_passc                 C   s   t j | |¡ dS )zJSee http://llvm.org/docs/Passes.html#inline-function-integration-inlining.N)r	   r"   ÚLLVMPY_AddFunctionInliningPass)r   Ú	thresholdr   r   r   Úadd_function_inlining_passw   s    z&PassManager.add_function_inlining_passc                 C   s   t j | ¡ dS )zGSee http://llvm.org/docs/Passes.html#globaldce-dead-global-elimination.N)r	   r"   ÚLLVMPY_AddGlobalDCEPassr9   r   r   r   Úadd_global_dce_pass{   s    zPassManager.add_global_dce_passc                 C   s   t j | ¡ dS )zISee http://llvm.org/docs/Passes.html#globalopt-global-variable-optimizer.N)r	   r"   ÚLLVMPY_AddGlobalOptimizerPassr9   r   r   r   Úadd_global_optimizer_pass   s    z%PassManager.add_global_optimizer_passc                 C   s   t j | ¡ dS )zdSee http://llvm.org/docs/Passes.html#ipsccp-interprocedural-sparse-conditional-constant-propagation.N)r	   r"   ÚLLVMPY_AddIPSCCPPassr9   r   r   r   Úadd_ipsccp_passƒ   s    zPassManager.add_ipsccp_passc                 C   s   t j | ¡ dS )z?See http://llvm.org/docs/Passes.html#dce-dead-code-elimination.N)r	   r"   Ú!LLVMPY_AddDeadCodeEliminationPassr9   r   r   r   Úadd_dead_code_elimination_pass‡   s    z*PassManager.add_dead_code_elimination_passc                 C   s   t j | ¡ dS )zBSee http://llvm.org/docs/Passes.html#simplifycfg-simplify-the-cfg.N)r	   r"   ÚLLVMPY_AddCFGSimplificationPassr9   r   r   r   Úadd_cfg_simplification_pass‹   s    z'PassManager.add_cfg_simplification_passc                 C   s   t j | ¡ dS )z@See http://llvm.org/docs/Passes.html#gvn-global-value-numbering.N)r	   r"   ÚLLVMPY_AddGVNPassr9   r   r   r   Úadd_gvn_pass�   s    zPassManager.add_gvn_passc                 C   s   t j | ¡ dS )z8See http://llvm.org/docs/Passes.html#passes-instcombine.N)r	   r"   Ú"LLVMPY_AddInstructionCombiningPassr9   r   r   r   Úadd_instruction_combining_pass“   s    z*PassManager.add_instruction_combining_passc                 C   s   t j | ¡ dS )zESee http://llvm.org/docs/Passes.html#licm-loop-invariant-code-motion.N)r	   r"   ÚLLVMPY_AddLICMPassr9   r   r   r   Úadd_licm_pass—   s    zPassManager.add_licm_passc                 C   s   t j | ¡ dS )zRSee http://llvm.org/docs/Passes.html#sccp-sparse-conditional-constant-propagation.N)r	   r"   ÚLLVMPY_AddSCCPPassr9   r   r   r   Úadd_sccp_pass›   s    zPassManager.add_sccp_passc                 C   s   t j | ¡ dS )zÆSee http://llvm.org/docs/Passes.html#scalarrepl-scalar-replacement-of-aggregates-dt.
        Note that this pass corresponds to the ``opt -sroa`` command-line option,
        despite the link above.N)r	   r"   ÚLLVMPY_AddSROAPassr9   r   r   r   Úadd_sroa_passŸ   s    zPassManager.add_sroa_passc                 C   s   t j | ¡ d S r+   )r	   r"   Ú$LLVMPY_AddTypeBasedAliasAnalysisPassr9   r   r   r   Ú"add_type_based_alias_analysis_pass¥   s    z.PassManager.add_type_based_alias_analysis_passc                 C   s   t j | ¡ dS )z=See http://llvm.org/docs/AliasAnalysis.html#the-basicaa-pass.N)r	   r"   Ú LLVMPY_AddBasicAliasAnalysisPassr9   r   r   r   Úadd_basic_alias_analysis_pass¨   s    z)PassManager.add_basic_alias_analysis_passc                 C   s   t j | ¡ dS )z:http://llvm.org/docs/Passes.html#loop-rotate-rotate-loops.N)r	   r"   ZLLVMPY_LLVMAddLoopRotatePassr9   r   r   r   Úadd_loop_rotate_pass¬   s    z PassManager.add_loop_rotate_passiè  c                 C   s   t |ƒ}tj | ||¡ dS )aá  Add Numba specific Reference count pruning pass.

        Parameters
        ----------
        subpasses_flags : RefPruneSubpasses
            A bitmask to control the subpasses to be enabled.
        subgraph_limit : int
            Limit the fanout pruners to working on a subgraph no bigger than
            this number of basic-blocks to avoid spending too much time in very
            large graphs. Default is 1000. Subject to change in future
            versions.
        N)r1   r	   r"   ÚLLVMPY_AddRefPrunePass)r   Zsubpasses_flagsZsubgraph_limitZiflagsr   r   r   Úadd_refprune_pass²   s    zPassManager.add_refprune_passN)r   r   r   r   r:   r<   r>   r@   rC   rE   rG   rI   rK   rM   rO   rQ   rS   rU   rW   rY   r[   r\   r1   r6   r^   r   r   r   r   r7   d   s,   ÿr7   c                   @   s   e Zd Zddd„Zdd„ ZdS )r,   Nc                 C   s"   |d u rt j ¡ }t | |¡ d S r+   )r	   r"   ÚLLVMPY_CreatePassManagerr7   Ú__init__)r   Úptrr   r   r   r`   Æ   s    
zModulePassManager.__init__c                 C   s   t j | |¡S )z>
        Run optimization passes on the given module.
        )r	   r"   ÚLLVMPY_RunPassManager)r   r/   r   r   r   ÚrunË   s    zModulePassManager.run)N)r   r   r   r`   rc   r   r   r   r   r,   Ä   s   
r,   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
r.   c                 C   s(   t j |¡}|| _d|_t | |¡ d S )NT)r	   r"   Ú LLVMPY_CreateFunctionPassManagerÚ_moduleZ_ownedr7   r`   )r   r/   ra   r   r   r   r`   Ô   s    zFunctionPassManager.__init__c                 C   s   t j | ¡S )zk
        Initialize the FunctionPassManager.  Returns True if it produced
        any changes (?).
        )r	   r"   Ú$LLVMPY_InitializeFunctionPassManagerr9   r   r   r   Ú
initializeÚ   s    zFunctionPassManager.initializec                 C   s   t j | ¡S )zi
        Finalize the FunctionPassManager.  Returns True if it produced
        any changes (?).
        )r	   r"   Ú"LLVMPY_FinalizeFunctionPassManagerr9   r   r   r   Úfinalizeá   s    zFunctionPassManager.finalizec                 C   s   t j | |¡S )z@
        Run optimization passes on the given function.
        )r	   r"   ÚLLVMPY_RunFunctionPassManager)r   Úfunctionr   r   r   rc   è   s    zFunctionPassManager.runN)r   r   r   r`   rg   ri   rc   r   r   r   r   r.   Ò   s   r.   N)F)7Úctypesr   r   r   r   r   Úcollectionsr   Úenumr   Zllvmlite.bindingr	   Z_prunestatsr
   r    r$   r&   r*   r-   r0   r1   Z	ObjectRefr7   r,   r.   ZLLVMPassManagerRefr"   r_   ÚrestypeZLLVMModuleRefrd   Úargtypesr8   rb   rf   rh   ZLLVMValueRefrj   r;   r=   r?   rA   rD   rF   rH   rJ   rL   rN   rP   rR   rT   rV   rX   rZ   r]   r   r   r   r   Ú<module>   sj   ÿ
` ÿ



ÿ

ÿ
ÿ