ó
\K]c           @@ s’  d  d l  m Z m Z d  d l Z d  d l Z d d l m Z m Z m	 Z	 d  d l
 Z
 d  d l
 m Z d  d l
 m Z m Z m Z m Z m Z d  d l m Z m Z m Z m Z d  d l m Z d  d	 l m Z d d
 l m Z e e j f d e ƒd „  ƒ Z e e j f d e ƒd „  ƒ Z  d „  Z! d „  Z" e d „  ƒ Z# d e
 j j$ f d „  ƒ  YZ% d e f d „  ƒ  YZ& e' d k rŽe j( ƒ  n  d S(   i    (   t   print_functiont   absolute_importNi   (   t   TestCaset   override_configt   captured_stdout(   t   unittest_support(   t   jitt   njitt   typest   irt   compiler(   t   guardt   find_callnamet
   find_constt   get_definition(   t   CPUDispatcher(   t   inline_closure_call(   t   skip_unsupportedt   nopythonc         C@ s   |  d S(   Ni   (    (   t   a(    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   inner   s    c         C@ s   t  t  |  ƒ ƒ S(   N(   R   (   R   (    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   more   s    c         C@ s   t  |  ƒ d S(   Ni   (   R   (   R   (    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   outer_simple   s    c         C@ s   t  |  ƒ t |  ƒ S(   N(   R   R   (   R   (    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   outer_multiple   s    c           C@ s   d  S(   N(    (    (    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt	   __dummy__   s    t   InlineTestPipelinec           B@ s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s>   compiler pipeline for testing inlining after optimization
    c         C@ sø   d } | j  | ƒ |  j | ƒ |  j | ƒ |  j | ƒ |  j | ƒ | j |  j d ƒ |  j j s| | j |  j	 d ƒ n  |  j j
 j r¡ | j |  j d ƒ n  | j |  j d ƒ | j |  j d ƒ |  j | ƒ |  j | ƒ | j |  j d ƒ d  S(   Nt   inline_tests   Preprocessing for parforss   nopython rewritess   convert to parforss   inline tests$   ensure IR is legal prior to lowerings   preserve IR(   t   create_pipelinet   add_preprocessing_staget   add_with_handling_staget   add_pre_typing_staget   add_typing_staget	   add_staget   stage_pre_parfor_passt   flagst   no_rewritest   stage_nopython_rewritest   auto_parallelt   enabledt   stage_parfor_passt   stage_inline_test_passt   stage_ir_legalizationt   add_lowering_staget   add_cleanup_staget   stage_preserve_final_ir(   t   selft   pmt   name(    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   define_pipelines$   s"    c         C@ s   |  j  j ƒ  |  j d <d  S(   Nt   final_func_ir(   t   func_irt   copyt   metadata(   R-   (    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyR,   7   s    c         C@ s±   t  |  j j ƒ d k s t ‚ t |  j j j ƒ  ƒ d } xp t | j ƒ D]_ \ } } t t	 |  j | j
 ƒ d  k	 rJ t |  j i  | | d „  |  j d |  j |  j ƒ	 PqJ qJ Wd  S(   Ni   i    c           S@ s   d  S(   N(   t   None(    (    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   <lambda>@   t    (    (   t   lenR2   t   blockst   AssertionErrort   listt   valuest	   enumeratet   bodyR   R   t   valueR5   R   t	   typingctxt   typemapt	   calltypes(   R-   t   blockt   it   stmt(    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyR(   :   s    (   t   __name__t
   __module__t   __doc__R0   R,   R(   (    (    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyR   !   s   		t   TestInliningc           B@ sw   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z e d	 „  ƒ Z RS(
   sÕ   
    Check that jitted inner functions are inlined into outer functions,
    in nopython mode.
    Note that not all inner functions are guaranteed to be inlined.
    We just trust LLVM's inlining heuristics.
    c         C@ s<   | j  d ƒ } d d j g  | D] } d j | ƒ ^ q ƒ S(   s4   
        Make regexpr to match mangled name
        t   .s   _ZN?R7   s   \d+{}(   t   splitt   joint   format(   R-   t   fullnamet   partst   p(    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   make_patternM   s    c         C@ s;   |  j  | ƒ } |  j t j | | ƒ d d j | ƒ ƒd  S(   Nt   msgs   expected {}(   RQ   t   assertIsNotNonet   ret   searchRM   (   R-   RN   t   textt   pat(    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   assert_has_patternT   s    c         C@ s;   |  j  | ƒ } |  j t j | | ƒ d d j | ƒ ƒd  S(   NRR   s   unexpected {}(   RQ   t   assertIsNoneRT   RU   RM   (   R-   RN   RV   RW   (    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   assert_not_has_patternY   s    c         C@ sš   t  d t ƒ 5 t ƒ  % } t t j f d t ƒt ƒ } Wd  QXWd  QX|  j | d ƒ d ƒ | j ƒ  } t	 } |  j
 d | | ƒ |  j d | | ƒ d  S(   Nt   DUMP_ASSEMBLYR   i   i   s   %s.outer_simples   %s.inner(   R   t   TrueR   R   R   t   int32R   t   assertPreciseEqualt   getvalueRF   RX   RZ   (   R-   t   outt   cfunct   asmt   prefix(    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   test_inner_function^   s    *c         C@ s®   t  d t ƒ 5 t ƒ  % } t t j f d t ƒt ƒ } Wd  QXWd  QX|  j | d ƒ d ƒ | j ƒ  } t	 } |  j
 d | | ƒ |  j d | | ƒ |  j d | | ƒ d  S(   NR[   R   i   i   s   %s.outer_multiples   %s.mores   %s.inner(   R   R\   R   R   R   R]   R   R^   R_   RF   RX   RZ   (   R-   R`   Ra   Rb   Rc   (    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   test_multiple_inner_functionsj   s    *c         C@ sS   d „  } t  d t d t ƒ | ƒ } t j d ƒ } |  j | | ƒ | | ƒ ƒ d  S(   Nc         S@ s   t  ƒ  |  j ƒ  S(   N(   R   t   sum(   t   A(    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt	   test_impl|   s    t   parallelt   pipeline_classi
   (   R   R\   R   t   npt   aranget   assertEqual(   R-   Rh   t   j_funcRg   (    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   test_inline_call_after_parforx   s
    		c         C@ sQ  d „  } t  j | ƒ } t | j j ƒ  ƒ } x | D]ø } xï t | j ƒ D]Þ \ } } t | t j	 ƒ rJ t | j
 t j ƒ rJ t t | | j
 ƒ d k rJ | j | j j j | j
 ƒ t j j t j | j d d | j ƒd d | j ƒ | _
 | j | j j j | j
 ƒ t | i  | | d „  ƒ PqJ qJ Wq4 W|  j t | j d ƒ d ƒ d  S(	   Nc         S@ s   |  d k r d } n d } | S(   Ni   i   i   (    (   R   t   b(    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyRh   ‡   s    	i   t   myvart   locc           S@ s   d S(   Ni   (    (    (    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyR6   š   R7   Rp   (    (    (   R
   t   run_frontendR;   R9   R<   R=   R>   t
   isinstanceR	   t   AssignR?   t   VarR   R   t   _definitionst   targetR/   t   removet   Exprt   callt   scopeRr   t   appendR   Rm   R8   (   R-   Rh   R2   R9   RC   RD   RE   (    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   test_inline_update_target_def„   s    	'9c         @ sR  t  j d i t  j d 6ƒ d „  ƒ ‰  ‡  f d †  } t j | ƒ } t | j j ƒ  ƒ } xà | D]Ø } xÏ t | j	 ƒ D]¾ \ } } t
 | t j ƒ ru t
 | j t j ƒ ru | j j d k ru t t | | j j ƒ } t
 | t j t j f ƒ r3t
 | j t ƒ r3| j j } t | | j | | | ƒ \ }	 }
 Pq3qu qu Wq_ W|  j d |
 k ƒ d  S(   Nt   localsRp   c         S@ s   |  d } | S(   Ni   (    (   R   Rp   (    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   g£   s    
c           @ s
   ˆ  d ƒ S(   Ni   (    (    (   R€   (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyRh   ¨   s    R{   (   t   numbaR   t   float64R
   Rs   R;   R9   R<   R=   R>   Rt   R	   Ru   R?   Rz   t   opR   R   t   funct   Globalt   FreeVarR   t   py_funcR   t   __globals__t
   assertTrue(   R-   Rh   R2   R9   RC   RD   RE   t   func_defR‡   t   _t   var_map(    (   R€   s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   test_inline_var_dict_retŸ   s"    %c         @ sâ   t  d  d „ ƒ ‰  d  ‡  f d † } d t f ‡  f d †  ƒ  Y} t  d | ƒ | ƒ } d } |  j | | ƒ | | ƒ ƒ |  j | ƒ  | ƒ  ƒ | j t j d  ƒ f j d } t j	 j
 | j ƒ | _ |  j t | j ƒ d ƒ d  S(	   Nc         S@ s   |  d  k r d S|  Sd  S(   Ni   (   R5   (   Rg   (    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   fooÀ   s    c         @ s
   ˆ  |  ƒ S(   N(    (   Rg   (   RŽ   (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyRh   Ç   s    t   InlineTestPipelinePrunec           @ s   e  Z ‡  f d  †  Z RS(   c         @ sÈ   t  |  j j ƒ d k s t ‚ t |  j j j ƒ  ƒ d } x‡ t | j ƒ D]v \ } } t t	 |  j | j
 ƒ d  k	 rJ t |  j i  | | ˆ  j |  j |  j | j
 j d j f |  j |  j ƒ	 PqJ qJ Wd  S(   Ni   i    (   R8   R2   R9   R:   R;   R<   R=   R>   R   R   R?   R5   R   R‡   R@   RA   t   argsR/   RB   (   R-   RC   RD   RE   (   RŽ   (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyR(   Ë   s    	(   RF   RG   R(   (    (   RŽ   (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyR   Ê   s   Rj   i   R1   i   (   R   R5   R   Rm   t	   overloadsR   t   OmittedR4   R   t   ir_utilst   simplify_CFGR9   R8   (   R-   Rh   R   Rn   Rg   t   fir(    (   RŽ   s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   test_inline_call_branch_pruning¼   s     (   RF   RG   RH   RQ   RX   RZ   Rd   Re   R   Ro   R~   R   R–   (    (    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyRI   E   s   					t   __main__()   t
   __future__R    R   RT   t   numpyRk   t   supportR   R   R   R   R   t   unittestR   R   R   R	   R
   t   numba.ir_utilsR   R   R   R   t   numba.targets.registryR   t   numba.inline_closurecallR   t   test_parforsR   R]   R\   R   R   R   R   R   t   BasePipelineR   RI   RF   t   main(    (    (    s8   lib/python2.7/site-packages/numba/tests/test_inlining.pyt   <module>   s&   ("!!		$ž