Ë
    üÇ:j24  ã                   óè   — d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ  G d„ d«      Z G d	„ d
«      Z edg d¢«      Zd„ Z G d„ d«      Z edddg«      Z G d„ de«      Zy)é    N)Ú
namedtuple)ÚSequence)Úcontextmanager)Úcached_property)Úconfigc                   ó(   — e Zd ZdZdgZd„ Zd„ Zd„ Zy)ÚRecordLLVMPassTimingsLegacyú9A helper context manager to track LLVM pass timings.
    Ú_datac                 ó0   — t        j                  d«       | S )ú)Enables the pass timing in LLVM.
        T)ÚllvmÚset_time_passes©Úselfs    úq/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/numba/misc/llvm_pass_timings.pyÚ	__enter__z%RecordLLVMPassTimingsLegacy.__enter__   s   € ô 	×Ñ˜TÔ"Øˆó    c                 ó`   — t        j                  «       | _        t        j                  d«       y)ú2Reset timings and save report internally.
        FN)r   Úreport_and_reset_timingsr   r   ©r   Úexc_valÚexc_typeÚexc_tbs       r   Ú__exit__z$RecordLLVMPassTimingsLegacy.__exit__   s%   € ô ×2Ñ2Ó4ˆŒ
Ü×Ñ˜UÔ#Ør   c                 ó,   — t        | j                  «      S ©ztRetrieve timing data for processing.

        Returns
        -------
        timings: ProcessedPassTimings
        ©ÚProcessedPassTimingsr   r   s    r   ÚgetzRecordLLVMPassTimingsLegacy.get!   ó   € ô $ D§J¡JÓ/Ð/r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r!   © r   r   r	   r	      s   „ ñð �	€Iòòó0r   r	   c                   ó0   — e Zd ZdZddgZd„ Zd„ Zd„ Zd„ Zy)	ÚRecordLLVMPassTimingsr
   r   Ú_pbc                 ó    — || _         d | _        y ©N)r+   r   )r   Úpbs     r   Ú__init__zRecordLLVMPassTimings.__init__1   s   € ØˆŒØˆ�
r   c                 ó:   — | j                   j                  «        | S )r   )r+   Ústart_pass_timingr   s    r   r   zRecordLLVMPassTimings.__enter__5   s   € ð 	�‰×"Ñ"Ô$Øˆr   c                 óB   — | j                   j                  «       | _        y)r   N)r+   Úfinish_pass_timingr   r   s       r   r   zRecordLLVMPassTimings.__exit__;   s   € ð —X‘X×0Ñ0Ó2ˆŒ
Ør   c                 ó,   — t        | j                  «      S r   r   r   s    r   r!   zRecordLLVMPassTimings.getA   r"   r   N)	r#   r$   r%   r&   r'   r/   r   r   r!   r(   r   r   r*   r*   +   s'   „ ñð ˜%Ð €Iòòòó0r   r*   ÚPassTimingRecord)
Ú	user_timeÚuser_percentÚsystem_timeÚsystem_percentÚuser_system_timeÚuser_system_percentÚ	wall_timeÚwall_percentÚ	pass_nameÚinstructionc                 óÀ   ‡‡— | d   Š‰j                   dk(  sJ ‚ˆfd„}dD �cg c]
  } ||«      ‘Œ c}Št        d„ | «      }ˆfd„}t        t        ||«      «      S c c}w )zÎAdjust timing records because of truncated information.

    Details: The percent information can be used to improve the timing
    information.

    Returns
    -------
    res: List[PassTimingRecord]
    éÿÿÿÿÚTotalc                 ó\   •‡‡‡— | › d�Š| › d�Št        j                  ‰«      Šˆˆˆˆfd„}|S )NÚ_timeÚ_percentc                 ó8   •—  ‰‰«      }|| ‰   z  dz  }|| ‰<   | S )z'Compute percent x total_time = adjustedg{®Gáz„?r(   )ÚdÚtotalÚadjustedÚpercent_attrÚ	time_attrÚtime_getterÚ	total_recs      €€€€r   Úadjustz6_adjust_timings.<locals>.make_adjuster.<locals>.adjustn   s.   ø€ á 	Ó*ˆEØ˜q ™Ñ.°Ñ5ˆHØ#ˆAˆi‰LØˆHr   )ÚoperatorÚ
attrgetter)ÚattrrN   rJ   rK   rL   rM   s     @@@€r   Úmake_adjusterz&_adjust_timings.<locals>.make_adjusteri   s6   û€ Ø�f˜E�Nˆ	Ø˜˜xÐ(ˆÜ×)Ñ)¨)Ó4ˆ÷	ð ˆr   )ÚuserÚsystemÚuser_systemÚwallc                 ó"   — | j                  «       S r-   )Ú_asdict©Úxs    r   ú<lambda>z!_adjust_timings.<locals>.<lambda>}   s   € ˜!Ÿ)™)›+€ r   c                 ó8   •— ‰D ]
  } || «      } Œ t        di | ¤ŽS )Nr(   )r5   )rG   ÚfnÚadj_fnss     €r   Úchainedz _adjust_timings.<locals>.chained   s+   ø€ àò 	ˆBÙ�1“‰Að	ô  Ñ$ !Ñ$Ð$r   )r>   ÚmapÚlist)ÚrecordsrR   rZ   Údictsr_   r^   rM   s        @@r   Ú_adjust_timingsrd   \   sq   ù€ ð ˜‘€IØ×Ñ 'Ò)Ð)Ð)ôð  #LöØ‰�aÕò€Gô
 Ñ% wÓ/€Eô%ô ”�G˜UÓ#Ó$Ð$ùòs   ¢Ac                   óR   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	dd„Z
ed	„ «       Zd
„ Zy)r    zœA class for processing raw timing report from LLVM.

    The processing is done lazily so we don't waste time processing unused
    timing information.
    c                 ó   — || _         y r-   ©Ú	_raw_data)r   Úraw_datas     r   r/   zProcessedPassTimings.__init__�   s	   € Ø!ˆ�r   c                 ó,   — t        | j                  «      S r-   )Úboolrh   r   s    r   Ú__bool__zProcessedPassTimings.__bool__“   s   € Ü�D—N‘NÓ#Ð#r   c                 ó   — | j                   S )zWReturns the raw string data.

        Returns
        -------
        res: str
        rg   r   s    r   Úget_raw_dataz!ProcessedPassTimings.get_raw_data–   s   € ð �~‰~Ðr   c                 ó<   — | j                  «       d   j                  S )zhCompute the total time spend in all passes.

        Returns
        -------
        res: float
        rA   )Úlist_recordsr<   r   s    r   Úget_total_timez#ProcessedPassTimings.get_total_timeŸ   s   € ð × Ñ Ó" 2Ñ&×0Ñ0Ð0r   c                 ó   — | j                   S )z{Get the processed data for the timing report.

        Returns
        -------
        res: List[PassTimingRecord]
        )Ú
_processedr   s    r   rp   z!ProcessedPassTimings.list_records¨   s   € ð �‰Ðr   c                 ó€   — | j                  «       }t        j                  d«      }t        j                  ||dd |«      S )a—  Returns the top(n) most time-consuming (by wall-time) passes.

        Parameters
        ----------
        n: int
            This limits the maximum number of items to show.
            This function will show the ``n`` most time-consuming passes.

        Returns
        -------
        res: List[PassTimingRecord]
            Returns the top(n) most time-consuming passes in descending order.
        r<   NrA   )rp   rO   rP   ÚheapqÚnlargest)r   Únrb   Úkeys       r   Úlist_topzProcessedPassTimings.list_top±   s;   € ð ×#Ñ#Ó%ˆÜ×!Ñ! +Ó.ˆÜ�~‰~˜a ¨¨" ¨sÓ3Ð3r   c           	      ó  ‡‡— g Šd|z  Šˆˆfd„} |d| j                  «       d›d�«        |d«       | j                  |«      D ]3  } |d|j                  d›d|j                  d	›d
|j                  › �«       Œ5 dj                  ‰«      S )a¢  Return a string summarizing the timing information.

        Parameters
        ----------
        topn: int; optional
            This limits the maximum number of items to show.
            This function will show the ``topn`` most time-consuming passes.
        indent: int; optional
            Set the indentation level. Defaults to 0 for no indentation.

        Returns
        -------
        res: str
        ú c                 ó0   •— ‰j                  ‰› | › �«       y r-   )Úappend)ÚargÚbufÚprefixs    €€r   Úapz(ProcessedPassTimings.summary.<locals>.apÕ   s   ø€ Ø�J‰J˜&˜ # Ð'Õ(r   zTotal ú.4fÚszTop timings:z  zs (Ú5z%) ú
)rq   ry   r<   r=   r>   Újoin)r   ÚtopnÚindentr�   Úpr   r€   s        @@r   ÚsummaryzProcessedPassTimings.summaryÃ   s”   ù€ ð ˆØ�v‘ˆõ	)ñ 	ˆV�D×'Ñ'Ó)¨#Ð.¨aÐ0Ô1Ù
ˆ>ÔØ—‘˜tÓ$ò 	LˆAÙ��A—K‘K Ð$ C¨¯©°qÐ'9¸¸Q¿[¹[¸MÐJÕKð	Là�y‰y˜‹~Ðr   c                 ó"   — | j                  «       S )ztA cached property for lazily processing the data and returning it.

        See ``_process()`` for details.
        )Ú_processr   s    r   rs   zProcessedPassTimings._processedÞ   s   € ð �}‰}‹Ðr   c                 óT   — d„ }t         || j                  «      «      }t        |«      S )z¡Parses the raw string data from LLVM timing report and attempts
        to improve the data by recomputing the times
        (See `_adjust_timings()``).
        c           	   3   ó¸  K  — | j                  «       }d}d|› d�}t        |«      }dddddd	d
œ}|D ]R  }t        j                  ||«      }|sŒt        j                  d|«      }|D �	cg c]  }	||	j                  «          ‘Œ }
}	 n 
d   d	k(  sJ ‚g }d}d}|
dd D ]A  }	|	dk(  r||z  }Œ|j                  |	› d�«       |j                  |	› d�«       |d|› d|› d�z  }ŒC i }t        j                  D ]  }	|	|vsŒ|	d	k7  sŒd||	<   Œ |dz  }|D ]˜  }t        j                  ||«      }|€Œt        |j                  «       «      } t        || «      D �	�ci c]  \  }	}|	|�t        |«      nd“Œ }}	}|j                  |«       | d   }t        dd	|i|¤Ž}|–— |j                  dk(  sŒ˜ n dj                  |«      }d|v ry|rt!        d|› �«      ‚yc c}	w c c}}	w ­w)zwA generator that parses the raw_data line-by-line to extract
            timing information for each pass.
            z[a-zA-Z+ ]+z(?:\s*-+z-+)+rS   rT   rU   rV   r?   r>   )z	User TimezSystem TimezUser+Systemz	Wall TimeÚInstrÚNamez[a-zA-Z][a-zA-Z+ ]+rA   z\s*((?:[0-9]+\.)?[0-9]+)Ú NrD   rE   z\s+(?:z\s*\(z%\)|-+)g        z\s*(.*)rB   r…   z Analysis execution timing reportz'unexpected text after parser finished:
r(   )Ú
splitlinesÚiterÚreÚmatchÚfindallÚstripr}   r5   Ú_fieldsra   ÚgroupsÚzipÚfloatÚupdater>   r†   Ú
ValueError)ri   ÚlinesÚ	colheaderÚmulticolheadersÚ	line_iterÚ
header_mapÚlnÚmÚraw_headersÚkÚheadersÚattrsrw   ÚpatÚmissingÚvÚdatar>   ÚrecÚ	remainings                       r   Úparsez,ProcessedPassTimings._process.<locals>.parseì   s`  è ø€ ð ×'Ñ'Ó)ˆEØ&ˆIà!)¨)¨°DÐ9ˆOä˜U›ˆIð $Ø'Ø,Ø#Ø&Ø#ñˆJð  ò �Ü—H‘H˜_¨bÓ1�Úä"$§*¡*Ð-CÀRÓ"H�KØ>IÖJ¸˜z¨!¯'©'«)Ó4ÐJ�GÐJÙðð ˜2‘; +Ò-Ð-Ð-àˆEØ+ˆAØˆCØ˜S˜b�\ò 8�Ø˜Ò%Ø˜1‘H‘Cà—L‘L A 3 e Ô-Ø—L‘L A 3 h Ô0Ø˜f Q C u¨Q¨C¨wÐ7Ñ7‘Cð8ð ˆGÜ%×-Ñ-ò %�Ø˜E’> a¨;Ó&6Ø!$�G˜A’Jð%ð �:ÑˆCØò �Ü—H‘H˜S "Ó%�Ø‘=Ü# A§H¡H£JÓ/�Hä(+¨E°8Ó(<÷>Ù $  1ð ¨1¨=œu Qœx¸cÑAð >�Dñ >à—K‘K Ô(Ø (¨¡�IÜ*ñ Ø"+ðØ/3ñ�Cð ’IØ—}‘}¨Ó/áðð  Ÿ	™	 )Ó,ˆIð 2°YÑ>ØáÜ Ø>¸y¸kÐJóð ð ùò[ Kùó6>ùs=   ‚A
GÁGÁ'GÂA7GÃ9GÃ?)GÄ)(GÅGÅ+9GÆ%5G)ra   rh   rd   )r   r¯   rb   s      r   rŒ   zProcessedPassTimings._processæ   s)   € òH	ôV ‘u˜TŸ^™^Ó,Ó-ˆÜ˜wÓ'Ð'r   N)é   r   )r#   r$   r%   r&   r/   rl   rn   rq   rp   ry   rŠ   r   rs   rŒ   r(   r   r   r    r    ‰   sD   „ ñò"ò$òò1òò4ó$ð6 ñó ðóR(r   r    ÚNamedTimingsÚnameÚtimingsc                   ór   — e Zd ZdZd„ Zed„ «       Zed„ «       Zd„ Zd„ Z	d„ Z
ed„ «       Zdd	„Zd
„ Zd„ Zd„ Zy)ÚPassTimingsCollectionzˆA collection of pass timings.

    This class implements the ``Sequence`` protocol for accessing the
    individual timing records.
    c                 ó    — || _         g | _        y r-   )Ú_nameÚ_records)r   r²   s     r   r/   zPassTimingsCollection.__init__E  s   € ØˆŒ
Øˆ�r   c              #   óÆ   K  — t         j                  r=t        «       5 }d–— ddd«       j                  «       }|r| j	                  ||«       yyd–— y# 1 sw Y   Œ4xY w­w)a  Record new timings and append to this collection.

        Note: this is mainly for internal use inside the compiler pipeline.

        See also ``RecordLLVMPassTimingsLegacy``

        Parameters
        ----------
        name: str
            Name for the records.
        N)r   ÚLLVM_PASS_TIMINGSr	   r!   Ú_append)r   r²   r³   r­   s       r   Úrecord_legacyz#PassTimingsCollection.record_legacyI  sV   è ø€ ô ×#Ò#ä,Ó.ð °'Û÷à—+‘+“-ˆCáØ—‘˜T 3Õ'ð ô ÷ð üs   ‚A!�A¢3A!ÁAÁA!c              #   óÈ   K  — t         j                  r>t        |«      5 }d–— ddd«       j                  «       }|r| j	                  ||«       yyd–— y# 1 sw Y   Œ4xY w­w)a  Record new timings and append to this collection.

        Note: this is mainly for internal use inside the compiler pipeline.

        See also ``RecordLLVMPassTimings``

        Parameters
        ----------
        name: str
            Name for the records.
        N)r   rº   r*   r!   r»   )r   r²   r.   r³   r­   s        r   ÚrecordzPassTimingsCollection.recordb  sX   è ø€ ô ×#Ò#ä& rÓ*ð ¨gÛ÷à—+‘+“-ˆCáØ—‘˜T 3Õ'ð ô ÷ð üs   ‚A"žA£3A"ÁAÁA"c                 óN   — | j                   j                  t        ||«      «       y)z¿Append timing records

        Parameters
        ----------
        name: str
            Name for the records.
        timings: ProcessedPassTimings
            the timing records.
        N)r¸   r}   r±   )r   r²   r³   s      r   r»   zPassTimingsCollection._append{  s   € ð 	�‰×Ñœ\¨$°Ó8Õ9r   c                 óT   — | j                   rt        d„ | j                   D «       «      S y)zåComputes the sum of the total time across all contained timings.

        Returns
        -------
        res: float or None
            Returns the total number of seconds or None if no timings were
            recorded
        c              3   óP   K  — | ]  }|j                   j                  «       –— Œ  y ­wr-   ©r³   rq   )Ú.0Úrs     r   ú	<genexpr>z7PassTimingsCollection.get_total_time.<locals>.<genexpr>‘  s   è ø€ ÒI°a�q—y‘y×/Ñ/×1ÑIùs   ‚$&N)r¸   Úsumr   s    r   rq   z$PassTimingsCollection.get_total_time‡  s#   € ð �=Š=ÜÑI¸4¿=¹=ÔIÓIÐIàr   c                 ó4   — t        | j                  d„ d¬«      S )z‘Returns the timings in descending order of total time duration.

        Returns
        -------
        res: List[ProcessedPassTimings]
        c                 ó6   — | j                   j                  «       S r-   rÂ   rY   s    r   r[   z:PassTimingsCollection.list_longest_first.<locals>.<lambda>�  s   €  A§I¡I×$<Ñ$<Ó$>€ r   T)rx   Úreverse)Úsortedr¸   r   s    r   Úlist_longest_firstz(PassTimingsCollection.list_longest_first•  s   € ô �d—m‘mÙ>Ø"ô$ð 	$r   c                 ó   — | j                    S )z	
        ©r¸   r   s    r   Úis_emptyzPassTimingsCollection.is_empty   s   € ð —=‘=Ð Ð r   c                 óÆ  — | j                   ryg }|j                  } |d| j                  › �«       | j                  «       } |d|d›�«       t	        | j
                  «      D ]m  \  }} |d|› d|j                  › �«       |j                  j                  «       |z  dz  } |d|d	›d
�«        ||j                  j                  |d¬«      «       Œo dj                  |«      S )a�  Return a string representing the summary of the timings.

        Parameters
        ----------
        topn: int; optional, default=5.
            This limits the maximum number of items to show.
            This function will show the ``topn`` most time-consuming passes.

        Returns
        -------
        res: str

        See also ``ProcessedPassTimings.summary()``
        zNo pass timings were recordedzPrinting pass timings for zTotal time: r‚   z== #r{   éd   z
 Percent: z.1fú%é   )r‡   rˆ   r…   )
rÎ   r}   r·   rq   Ú	enumerater¸   r²   r³   rŠ   r†   )r   r‡   r   r�   Úoverall_timeÚirÄ   Úpercents           r   rŠ   zPassTimingsCollection.summary¦  sà   € ð �=Š=Ø2àˆCØ—‘ˆBÙÐ+¨D¯J©J¨<Ð8Ô9Ø×.Ñ.Ó0ˆLÙ�˜l¨3Ð/Ð0Ô1Ü! $§-¡-Ó0ò ;‘��1Ù�T˜!˜˜A˜aŸf™f˜XÐ&Ô'ØŸ)™)×2Ñ2Ó4°|ÑCÀcÑI�Ù�Z ¨˜}¨AÐ.Ô/Ù�1—9‘9×$Ñ$¨$°qÐ$Ó9Õ:ð	;ð
 —9‘9˜S“>Ð!r   c                 ó    — | j                   |   S )zÒGet the i-th timing record.

        Returns
        -------
        res: (name, timings)
            A named tuple with two fields:

            - name: str
            - timings: ProcessedPassTimings
        rÍ   )r   rÕ   s     r   Ú__getitem__z!PassTimingsCollection.__getitem__Ä  s   € ð �}‰}˜QÑÐr   c                 ó,   — t        | j                  «      S )z#Length of this collection.
        )Úlenr¸   r   s    r   Ú__len__zPassTimingsCollection.__len__Ñ  s   € ô �4—=‘=Ó!Ð!r   c                 ó"   — | j                  «       S r-   )rŠ   r   s    r   Ú__str__zPassTimingsCollection.__str__Ö  s   € Ø�|‰|‹~Ðr   N)r°   )r#   r$   r%   r&   r/   r   r¼   r¾   r»   rq   rË   ÚpropertyrÎ   rŠ   rØ   rÛ   rÝ   r(   r   r   rµ   rµ   >  sk   „ ñòð ñó ðð0 ñó ðò0
:òò	$ð ñ!ó ð!ó
"ò< ò"ó
r   rµ   )r”   rO   ru   Úcollectionsr   Úcollections.abcr   Ú
contextlibr   Ú	functoolsr   Ú
numba.corer   Úllvmlite.bindingÚbindingr   r	   r*   r5   rd   r    r±   rµ   r(   r   r   ú<module>ræ      s~   ðÛ 	Û Û Ý "Ý $Ý %Ý %å å ÷0ñ 0÷:0ñ 0ñ@ ØòóÐ ò"*%÷Zo(ñ o(ñd ˜.¨6°9Ð*=Ó>€ôY˜Hõ Yr   