
    vh                        d Z ddlZddlZddlmZ ddlZddlmZ ddlm	Z	 ddlm
Z
  G d dej                        Z ej                  d	      Zd
edej                   fdZd Zdeeef   de	j(                  fdZ e	j,                   e	j.                  ej0                  j2                  ee             deeef   de	j(                  fdZ e	j,                   e	j.                  ej6                  j2                  ee             	 ddeeef   deeef   dz  de	j(                  fdZ e	j,                   e	j.                  ej<                  j2                  ee             y)z*Source mapping generator for HLO dialects.    N)Any)	sourcemap)common)mlirc                       e Zd ZdZdZdZy)HloPasszhlo:stable-hlozhlo:originalzhlo:optimizedN)__name__
__module____qualname__
STABLE_HLOORIGINAL	OPTIMIZED     ]/opt/face_recognition/venv/lib/python3.12/site-packages/jax/experimental/source_mapper/hlo.pyr   r      s    *()r   r   zgmetadata={op_name=\"(?P<scope>.*)\" source_file=\"(?P<src_file>.*)\" source_line=(?P<src_line>[0-9]+)\}textreturnc                 ,   t        j                         }g }| j                  d      D ]  }|j                          t        j                  |      }|s+|j                         }|d   }|d   }t        |d         }||vr|j                  |       |j                  |      }	|dz  }|j                  |j                         d         }
|j                  |
|	|d        |j                          t        j                  d|g |j                         g       S )	N
scopesrc_filesrc_line   r      )versionsourcessources_contentmappingsnames)r   MappingsGeneratorsplit	new_groupMETADATA_REGEXsearch	groupdictintappendindexstripnew_segment	SourceMapr   )r   r   used_source_fileslinematch
match_dict_r   r   src_file_idx	first_cols              r   parse_hlo_dumpr3   &   s   ((*(jj Ad!!$'E??$j
W
aJ'hZ
+,h	*	*  *&,,X6l!mh**TZZ\!_-i9lHa@A 			  "
 r   c                 Z     t        j                  fd      j                  | }|| fS )Nc                       | i S Nr   )argsff_kwargss    r   <lambda>z!trace_and_lower.<locals>.<lambda>C   s    !T"6X"6 r   )jaxjitlower)work_dirr8   f_argsr9   r0   lowereds    ` `  r   trace_and_lowerrA   B   s*    =CGG67==vF'
8	r   r7   c                     | \  }}~|j                  d      }t        j                  |      }t        j                  ||t
        j                  j                        S )NT)
debug_info
source_mapgenerated_code	pass_name)as_textr   create_mlir_sourcemapr   SourceMapDumpr   r   valuer7   r0   r@   r>   hlo_textrE   s         r   stable_hlo_generate_dumprN   G   sW    '8___-())(3*			""((
 r   )name
compile_fngenerate_dumpc                     | \  }}~|j                  dd      }t        |      }t        j                  ||t        j
                  j                        S )NhloT)dialectrC   rD   )rH   r3   r   rJ   r   r   rK   rL   s         r   original_hlo_generate_dumprU   ]   sS    '8__Ut_<(h'*			  &&
 r   xla_compiler_flagsc                     | \  }}d|i|xs i }|j                  |      j                         }t        |      }t        j                  ||t
        j                  j                        S )Nxla_dump_torD   )compilerH   r3   r   rJ   r   r   rK   )r7   rV   r0   r@   r>   compilation_argsrM   rE   s           r   optimized_generate_dumpr[   s   sn     '8#XL2D2JL__-.668(h'*			!!''
 r   r6   )__doc__enumretypingr   r;   jax._srcr   jax.experimental.source_mapperr   r   Enumr   rY   r#   strr+   r3   rA   tuplerJ   rN   register_passPassr   rK   rU   r   dictr[   r   r   r   r   <module>rh      s   1  	  
  1 /dii  + !4!4 8

5c? 
%+%9%9
   FKK%%".
U38_ 
'-';';
   FKK##"0 IM%S/ 04S#X0E$*$8$8   FKK$$"-r   