
\K]c           @@ s  d  d l  m Z m Z d  d l Z d  d l Z d  d l 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
 m Z m Z m Z m Z m Z m Z m Z d  d l m Z m Z m Z d  d l m Z d  d l m Z m Z m Z d  d	 l m  Z  m! Z! m" Z" d  d l# Z# d  a$ d
   Z% d  a& d   Z' d   Z( d   Z) d   Z* d   Z+ d   Z, d   Z- d   Z. d   Z/ d   Z0 d   Z1 d   Z2 d   Z3 d   Z4 d   Z5 d   Z6 i  Z7 d   Z8 d   Z9 d   Z: i  Z; d   Z< i  Z= d   Z> d    Z? d!   Z@ d d d d"  ZB d d d d#  ZC i  ZD d$   ZE g  ZF d%   ZG eF jH eG  d&   ZI g  ZJ d'   ZK d(   ZL i  ZM i  ZN d d d)  ZO d*   ZP d+   ZQ d,   ZR d-   ZS i  ZT d.   ZU i  ZV d d/  ZW d0   ZX d d1  ZY d d2  ZZ i  Z[ d d e\ d3  Z] i  Z^ d d4  Z_ d5   Z` d6   Za d7   Zb d8 d9 d: d; d< d= d> d? d@ dA dB dC dD dE g Zc dF   Zd i  Ze d dG  Zf dH   Zg dI   Zh dJ   Zi dK   Zj dL ek f dM     YZl dN   Zm dO   Zn dP   Zo d dQ  Zp i  Zq d eo dR  Zr dS   Zs dT   Zt d d d d dU  Zu dV   Zv dW   Zw dX   Zx dY   Zy dZ   Zz d[   Z{ d\   Z| d]   Z} d^   Z~ d_   Z d`   Z da   Z db   Z dc   Z dd   Z de   Z df   Z d S(g   i    (   t   print_functiont   absolute_importN(   t   ir(   t   exec_(   R   t   typest   typingt   configt   analysist   utilst   cgutilst   rewrites(   t	   signaturet   infer_globalt   AbstractTemplate(   t   impl_ret_untracked(   t   compute_live_mapt   compute_use_defst   compute_cfg_from_blocks(   t   TypingErrort   UnsupportedErrort   NumbaPendingDeprecationWarningc         C@ s"   |  d t  t  } t d a | S(   Nt   .i   (   t   strt   _unique_var_count(   t   prefixt   var(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   mk_unique_var   s    
c         C@ sA   d } x4 t  r< |  t |  } | | k r/ | S| d 7} q	 Wd S(   sl    Get a new var name with a given prefix and
        make sure it is unused in the given variable table.
    i    i   N(   t   TrueR   (   R   t	   var_tablet   curR   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   get_unused_var_name(   s    	c           C@ s   t  d 7a  t  S(   Ni   (   t
   _max_label(    (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt
   next_label4   s    
c         C@ s  g  } d } t  j }	 t | t  r-t |  d k r[ | d } t | |  | | |  } q-t |  } t j | t d  |  }
 |  r t  j	 j
 t  j |  |  |
 j <n  g  | D] } t | |  | | |  ^ q } t j j | |  } t j | |
 |  } | j |  |
 } t  j	 j
 t  j |  }	 n  t j | t d  |  } |  rjt  j j t  |  | j <n  t j d t |  } t j | | |  } t j j | d |  } t j | t d  |  } |  rt t j  |  | j <n  t j | | |  } t j | t d  |  } |  r8t  j j |  |  | j <n  t |  } | d	 k rYd
 } n  t j j | | |  } t j | | |  } t j j | | | g d |  } | r|  | j j t j   |	 t  j j |  g i   | | <n  t j | | |  } | j | | | | g  | S(   s   generate an array allocation with np.empty() and return list of nodes.
    size_var can be an int variable or tuple of int variables.
    i   i    s
   $tuple_vars	   $np_g_vart   npt   emptys   $empty_attr_attrs   $np_typ_vart   boolt   bool_(    (   R   t   intpt
   isinstancet   tuplet   lent   convert_size_to_varR   t   VarR   t
   containerst   UniTuplet   namet   Exprt   build_tuplet   Assignt   appendt   misct   Modulet   numpyt   Globalt   getattrt   get_np_ufunc_typR"   t	   functionst   NumberClassR   t   callt   get_call_typeR   t   Contextt   extend(   t   typemapt	   calltypest   lhst   size_vart   dtypet   scopet   loct   outt   ndimst   size_typt	   tuple_vart   st	   new_sizest
   tuple_callt   tuple_assignt   g_np_vart   g_npt   g_np_assignt   empty_attr_callt   attr_vart   attr_assignt   typ_vart	   dtype_strt   np_typ_getattrt   typ_var_assignt
   alloc_callt   alloc_assign(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   mk_alloc:   sX    	
	(	!.c         C@ s   t  |  t  ru t j | t d  |  } | rC t j | | j <n  t j t j	 |  |  | |  } | j
 |  | St  |  t j  s t  |  S(   Ns   $alloc_size(   R&   t   intR   R*   R   R   R%   R-   R0   t   ConstR1   t   AssertionError(   RA   R>   RC   RD   t   nodest   new_sizet   size_assign(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR)   x   s    !c         C@ sF   x- t  j j j D] \ } } | |  k r | Sq Wt d |  d   d S(   s7   get type of the incoming function from builtin registrys   type for func s
    not foundN(   R   t   npydeclt   registryt   globalst   RuntimeError(   t   funct   kt   v(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR7      s    c         C@ s   t  j | t d  |  } t t  |  | j <t  j d t |  } t  j | | |  }	 t |  | | | | |  \ }
 } t  j	 j
 | | d |  } |  | j j t j   t j g t |  i   | | <t  j | t d  |  } t j j t j  |  | j <t  j | | |  } t  j	 j | |  } t t j t j  | | <t  j | t d  |  } t j j t j  |  | j <t  j | | |  } t  j | t d  |  } t j j t j  |  | j <t  j | | |  } t  j d |  } t  j | |  } |
 |	 | | | | g | _ | S(   sp   make a block that initializes loop range and iteration variables.
    target label in jump needs to be set.
    s   $range_g_vart   ranges   $range_c_vars	   $iter_vars   $phii(    (   R   R*   R   t   get_global_func_typRg   R-   R5   R0   t   _mk_range_argsR.   R:   R;   R   R<   R   R%   R(   t	   iteratorst	   RangeTypet   getiterR   t   range_iter64_typet   range_state64_typet   RangeIteratorTypet   Jumpt   Blockt   body(   R>   t   startt   stopt   stepR?   RC   RD   t   g_range_vart   g_ranget   g_range_assignt	   arg_nodest   argst
   range_callt   range_call_vart   range_call_assignt	   iter_callt   iter_vart   iter_call_assignt   phi_vart
   phi_assignt   jump_headert   range_block(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   mk_range_block   s2    !)		c         C@ s  g  } t  | t j  r! | } nw t  | t  s6 t  t j | t d  |  } |  rj t j |  | j <n  t j	 t j
 | |  | |  } | j |  | d k r | d k r | | g f St  | t j  r | }	 nw t  | t  s t  t j | t d  |  }	 |  r!t j |  |	 j <n  t j	 t j
 | |  |	 |  }
 | j |
  | d k rk| |	 | g f St  | t j  r| } nw t  | t  st  t j | t d  |  } |  rt j |  | j <n  t j	 t j
 | |  | |  } | j |  | |	 | | g f S(   Ns   $range_stopi    i   s   $range_starts   $range_step(   R&   R   R*   RZ   R\   R   R   R%   R-   R0   R[   R1   (   R>   Rs   Rt   Ru   RC   RD   R]   t
   g_stop_vart   stop_assignt   g_start_vart   start_assignt
   g_step_vart   step_assign(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyRi      s<    	!	!	!c         C@ sI   x- t  j j j D] \ } } | |  k r | Sq Wt d j |     d S(   s2   get type variable for func() from builtin registrys   func type not found {}N(   R   t	   templatest   builtin_registryRb   Rc   t   format(   Rd   Re   Rf   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyRh      s    c         C@ s  t  j | t d  |  } t j j t j t j  |  | j <t  j	 j
 | |  } t t j j t j t j  t j  | | <t  j | | |  } t  j | t d  |  } t j |  | j <t  j	 j | |  }	 t  j |	 | |  }
 t  j | t d  |  } t j |  | j <t  j	 j | |  } t  j | | |  } t  j | t d  |  } t j |  | j <t  j | | |  } t  j | d d |  } t  j | |  } | |
 | | | g | _ | S(   sq   make a block that is a loop header updating iteration variables.
    target labels in branch need to be set.
    s   $iternext_vars   $pair_first_vars   $pair_second_vars   $phii(   R   R*   R   R   R+   t   PairR%   t   booleanR-   R.   t   iternextR   Rm   R0   t
   pair_firstt   pair_secondt   BranchRq   Rr   (   R>   R   R?   RC   RD   t   iternext_vart   iternext_callt   iternext_assignt   pair_first_vart   pair_first_callt   pair_first_assignt   pair_second_vart   pair_second_callt   pair_second_assignt	   phi_b_vart   phi_b_assignt   brancht   header_block(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   mk_loop_header   s4    			c         C@ sa   i  } xT |  D]L } | j  d d  j  d d  j  d d  } | | k sO t  | | | <q W| S(   sX   returns a dictionary for conversion of variable names to legal
    parameter names.
    t   _t   __t   $R   (   t   replaceR\   (   t   varnamest   var_mapR   t   new_name(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   legalize_names  s    *c         C@ s#   d   } i  } t  |  | |  | S(   s<   create a mapping from variable names to their ir.Var objectsc         S@ s   |  | |  j  <|  S(   N(   R-   (   R   t   namevar(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   get_name_var_visit  s    (   t
   visit_vars(   t   blocksR   R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   get_name_var_table  s    	c         C@ sY   i  } x3 | j    D]% \ } } | | k r | | | <q q Wd   } t |  | |  d S(   sC   replace variables (ir.Var to ir.Var) from dictionary (name -> name)c         S@ sT   t  |  t j  s t  x5 |  j | k rO t j |  j | |  j |  j  }  q W|  S(   N(   R&   R   R*   R\   R-   RC   RD   (   R   t   namedict(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   replace_name#  s    &N(   t   itemsR   (   R   R   t   new_namedictt   lt   rR   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   replace_var_names  s    	c         C@ sc   t  |  t j  s t  xD |  j | j   k r^ | |  j } t j | j | j | j  }  q W|  S(   N(   R&   R   R*   R\   R-   t   keysRC   RD   (   R   t   vardictt   new_var(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   replace_var_callback+  s
    "c         C@ sS   i  } x6 | j    D]( \ } } | | j k r | | | <q q Wt |  t |  d S(   sE   replace variables (ir.Var to ir.Var) from dictionary (name -> ir.Var)N(   R   R-   R   R   (   R   R   t   new_vardictR   R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   replace_vars3  s
    c         C@ s   t  |  t |  d  S(   N(   t   visit_vars_stmtR   (   t   stmtR   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   replace_vars_stmt=  s    c         C@ s   t  |  t |  S(   N(   t   visit_vars_innerR   (   t   nodeR   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   replace_vars_innerA  s    c         C@ s?   x8 |  j    D]* } x! | j D] } t | | |  q Wq Wd S(   sW   go over statements of block bodies and replace variable names with
    dictionary.
    N(   t   valuesRr   R   (   R   t   callbackt   cbdatat   blockR   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR   J  s    c         C@ s  x= t  j   D]/ \ } } t |  |  r | |  | |  d  Sq Wt |  t j  r t |  j | |  |  _ t |  j | |  |  _ nt |  t j  r t |  j	 | |  |  _	 nt |  t j
  r t |  j | |  |  _ nt |  t j  rt |  j | |  |  _ nt |  t j  r9t |  j | |  |  _ n\t |  t j  rft |  j | |  |  _ n/t |  t j  rt j d  |  j |  j  } t | | |  } | j	 |  _ nt |  t j  rt |  j | |  |  _ t |  j | |  |  _ nt |  t j  rVt |  j | |  |  _ t |  j | |  |  _ t |  j | |  |  _ n?t |  t j  rt |  j | |  |  _ t |  j | |  |  _ n t |  t j  rt |  j | |  |  _ t |  j | |  |  _ t |  j | |  |  _ n t |  t j  rUt |  j | |  |  _ t |  j | |  |  _ t |  j | |  |  _ n@ t |  t j  rg  |  j D] } t | | |  ^ qq|  _ n  d  S(   N(   t   visit_vars_extensionsR   R&   R   R0   R   t   targett   valuet   ArgR-   t   Returnt   Raiset	   exceptionR   t   condRp   t   DelR*   t   NoneRD   t   DelAttrt   attrt   SetAttrt   DelItemt   indext   StaticSetItemt	   index_vart   SetItemt   PrintRz   (   R   R   R   t   tt   fR   t   x(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR   T  sT    .c         C@ s   t  |  t j  r | |  |  St  |  t  rQ g  |  D] } t | | |  ^ q5 St  |  t  r t g  |  D] } t | | |  ^ qj  St  |  t j  r x: |  j j   D]& } t |  j | | |  |  j | <q Wn  |  S(   N(	   R&   R   R*   t   listR   R'   R.   t   _kwsR   (   R   R   R   t   nt   arg(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR     s    #)'c   
      C@ s&  i  } x|  j    D]\ } } d } | j r | j d } xR | j D]D } x; t j    D]- \ } } t | |  rX | | |  }	 qX qX WqE Wn  t | t j  r t j | j | | j  | j d <n  t | t j	  rt j	 | j
 | j | | j | | j  | j d <n  | | | | <q W| S(   s>   add an offset to all block labels and jump/branch targets
    iN(   R   R   Rr   t   add_offset_to_labels_extensionsR&   R   Rp   R   RD   R   R   t   truebrt   falsebr(
   R   t   offsett
   new_blocksR   t   bt   termt   instt   TR   t   f_max(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   add_offset_to_labels  s     	& c   	      C@ s   d } x |  j    D] \ } } d  } | j r | j d } xd | j D]V } xM t j    D]? \ } } t | |  rX | |  } | | k r | } q qX qX WqE Wn  | | k r | } q q W| S(   Ni    i(   R   R   Rr   t   find_max_label_extensionsR&   (	   R   t	   max_labelR   R   R   R   R   R   R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   find_max_label  s    	c         C@ s`   xY |  j    D]K } g  } x3 | j D]( } t | t j  s# | j |  q# q# W| | _ q Wd S(   s   remove ir.Del nodesN(   R   Rr   R&   R   R   R1   (   R   R   t   new_bodyR   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   remove_dels  s    c         C@ sx   xq |  j    D]c } g  } xK | j D]@ } t | t j  rV t | j t j  rV q# n  | j |  q# W| | _ q Wd S(   s   remove ir.Arg nodesN(   R   Rr   R&   R   R0   R   R   R1   (   R   R   R   R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   remove_args  s    'c         C@ s]   t  } x+ t |  j |  j |  | | |  r3 t } q	 W| rY t j j |   } | j   n  d S(   s    Performs dead code elimination and leaves the IR in a valid state on
    exit (ir.Dels are present in correct locations).
    N(	   t   Falset   remove_deadR   t	   arg_namesR   t   numbat   postproct   PostProcessort   run(   t   func_irR>   t	   alias_mapt   arg_aliasest   do_post_proct	   post_proc(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   dead_code_elimination  s    
c         C@ s?  t  |   } t |   } t | |  | j | j  } t |   \ }	 }
 | d k s] | d k r{ t |  | | |  \ } } n  t j	 d k r t
 d |  n  t | j    } t } x |  j   D]x \ } } d   | j j   D } x+ | j |  D] \ } } | | | O} q W| t | | |	 | | | | |  O} q W| S(   s   dead code elimination using liveness and CFG info.
    Returns True if something has been removed, or False if nothing is removed.
    i   s
   alias map:c         S@ s   h  |  ] } | j   q S(    (   R-   (   t   .0Rf   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pys	   <setcomp>  s   	 N(   R   R   R   t   usemapt   defmapt   get_call_tableR   t   find_potential_aliasesR   t   DEBUG_ARRAY_OPTt   printt   setR   R   R   t
   terminatort	   list_varst
   successorst   remove_dead_block(   R   Rz   R   R>   R   R   t   cfgt   usedefst   live_mapt
   call_tableR   t	   alias_sett   removedt   labelR   t   livest   out_blkt   _data(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR     s$    c         C@ sc  t  } |  j g }	 x7t |  j d   D]"}
 t   } | | @} x | D] } | | | O} qF W| | B| B} t |
  t k r t t |
  } | |
 | | | | |  }
 |
 d k r t } q& q n  t	 |
 t
 j  rH|
 j } |
 j } | j | k rt | | |  rt } q& n  t	 | t
 j  rH| j | j k rHt } q& qHn  t	 |
 t
 j  rx|
 j | k rxt } q& qxn  t	 |
 t
 j  r|
 j j } | | k rq& qn  t |
  t j k rt j t |
  } | |
  \ } } | | 8} | | O} n? | d   |
 j   D O} t	 |
 t
 j  r;| j | j  n  |	 j |
  q& W|	 j   |	 |  _ | S(   s   remove dead code using liveness info.
    Mutable arguments (e.g. arrays) that are not definitely assigned are live
    after return of function.
    ic         S@ s   h  |  ] } | j   q S(    (   R-   (   R   Rf   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pys	   <setcomp>H  s   	 N(   R   R  t   reversedRr   R  t   typet   remove_dead_extensionsR   R   R&   R   R0   R   R   R-   t   has_no_side_effectR*   R   R   R   t   ir_extension_usedefsR  t   removeR1   t   reverse(   R   R  R  R   R   R  R   R>   R  R   R   t   alias_livest   init_alias_livesRf   t   lives_n_aliasesR   R@   t   rhsR-   t   def_funct   usest   defs(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR
    sX    	
			$			

	c         C@ s@   t  |  d k r< | d d t g k r< | d d d h k St S(   Ni   i   t   randomi    t   seedt   shuffle(   R(   R4   R   (   R  R  t	   call_list(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   remove_dead_random_callT  s    (c   	      C@ s  t  |  t j  r|  j d k r|  j j } | | k sI | | g  k rM t S| | } | d t g k s | t g k s | d t	 g k s | d t g k s | d t g k s | t	 j
 j g k r t St  | d t	 j j  r
| d j d k s| d j d k r
t Sd d	 l m } d d
 l m } t  | d |  r]| d j } | | k r]t Sn  x$ t D] } | |  | |  rdt SqdWt St  |  t j  r|  j d k r|  j j | k St  |  t j  rt St  |  t j  r|  j d k rt St S(   sa    Returns True if this expression has no side effects that
        would prevent re-ordering.
    R:   R"   t   stencilt   logRB   i    t   empty_inferredt   unsafe_empty_inferred(   t   CPUDispatcher(   t   dot_3_mv_check_argst   inplace_binopR   (   R&   R   R.   t   opRd   R-   R   R4   t   sliceR   t   array_analysist
   wrap_indexR   t	   extendingt
   _Intrinsict   _namet   numba.targets.registryR,  t   numba.targets.linalgR-  t   py_funct   remove_call_handlersR@   t   Yield(	   R  R  R  t	   func_nameR&  R,  R-  R8  R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR  [  sB    !
!!c         C@ s   t  |  t j  r |  j d k r |  j j } | | k sI | | g  k rM t S| | } | t g k s | d t g k s | d t g k r t	 Sx$ t
 D] } | |  | |  r t	 Sq Wt S|  j d k s |  j d k r t Sn  t  |  t j  r t St	 S(   s    Returns True if every time this expression is evaluated it
        returns the same result.  This is not the case for things
        like calls to numpy.random.
    R:   R)  R"   Rl   R   (   R&   R   R.   R/  Rd   R-   R   R0  R4   R   t   is_pure_extensionsR:  (   R  R  R  R;  R&  R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   is_pure  s&    
c         C@ s#   |  d k r | d k r t  Sn  t S(   NR4   R"   (   R"   (   R   R   (   t   module_nameR;  (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   is_const_call  s    c      	   @ s  | d k r i  } n  | d k r@ t   f d   | D  } n  t | j  | _ d d d g } x|  j   D]} x| j D]} t |  t k r t t |  }	 |	 | |   | | |  n  t	 | t
 j  r~ | j }
 | j j } t |    r q~ n  t	 |
 t
 j  r8| |
 j k r8t | |
 j | |  n  t	 |
 t
 j  r|
 j d k sh|
 j d k rt | |
 j j | |  n  t	 |
 t
 j  r|
 j d k r|
 j d k rt | |
 j j | |  n  t	 |
 t
 j  r|
 j d k r|
 j j | k rt | |
 j j | |  n  t	 |
 t
 j  r|
 j d k rt t | |
    } | d k rgq~ n  | \ } } | t k rt | } | | |
 j | |  n  | d k r| | k rt | |
 j d j | |  n  t	 | t
 j  r| | k rt | | j | |  qqq~ q~ Wqn Wt j |  } xZ | D]R } x& | | D] } | | c | | O<qFWx  | | D] } | | | | <qoWq5W| | f S(   sC   find all array aliases and argument aliases to avoid remove as deadc         3@ s$   |  ] } t  |    s | Vq d  S(   N(   t   is_immutable_type(   R   t   a(   R>   (    s-   lib/python2.7/site-packages/numba/ir_utils.pys	   <genexpr>  s    t   ravelt	   transposet   reshapet   castt   getitemt   static_getitemR6   R   t   ctypest   flatR:   R4   i    N(   RF  RG  (   R   RH  RI  (   R   R  t   build_definitionsR   t   _definitionsR   Rr   R  t   alias_analysis_extensionsR&   R   R0   R   R   R-   R@  R*   t
   _add_aliasR.   R/  R   t   guardt   find_callnamet   alias_func_extensionsRz   t   copyt   deepcopy(   R   Rz   R>   R   R   R   t   np_alias_funcst   blt   instrR   t   exprR@   t   fdeft   fnamet   fmodt
   alias_funct   old_alias_mapRf   t   w(    (   R>   s-   lib/python2.7/site-packages/numba/ir_utils.pyR    s\    		!!!!!
 'c         C@ sz   | | k r | j  |   nZ | | k r8 t   | | <n  |  | k rT t   | |  <n  | | j  |   | |  j  |  d  S(   N(   t   addR  (   R@   R  R   R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyRM    s    c         C@ sq   | d  k s |  | k r t S| |  } t | t j t j j t j j t j	 j
 f  rZ t S| t j k rm t St S(   N(   R   R   R&   R   t   Numbert   scalarst   _NPDatetimeBaseR+   t	   BaseTupleRj   Rk   R   t   string(   R   R>   t   typ(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR@    s    
	c         C@ sQ  t  |   } | j   } t |  | |  } | \ } } } } }	 d }
 t j |	  } x |
 | k r'x |  j   D] } | | k r qp n  g  | j |  D] \ } } | ^ q } |	 | d j   | | <x" | D] } | | c |	 | M<q W| | | | | | B|	 | <qp W| }
 t j |	  } qW Wt j	 d k rGt
 d |	  n  | |	 f S(   s   compute copy propagation information for each block using fixed-point
     iteration on data flow equations:
     in_b = intersect(predec(B))
     out_b = gen_b | (in_b - kill_b)
    i    i   s   copy propagate out_copies:N(   R   t   entry_pointt   init_copy_propagate_dataR   RQ  RR  R   t   predecessorsR   R  R  (   R   R>   R  t   entryt   c_datat
   gen_copiest
   all_copiest   kill_copiest	   in_copiest
   out_copiest	   old_pointt	   new_pointR  t   it   _dt   predecst   p(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   copy_propagate  s*    (c         @ s  t  |  |  \ } } t     x( | j   D] \ } }   | | O  q+ Wi  } x | j   D] \ } }	 t   | | <x   D] \ }
 } |
 | | k s | | | k r | | j |
 | f  n  d   |	 D } |
 | f |	 k r| |
 | k s | | k r| | | j |
 | f  q| q| Wq\ W  f d   |  j   D } t   | | <i  } x2 |  j   D]$ } | | | | | | B| | <qZW| | | | <|   | | | f S(   sH   get initial condition of copy propagation data flow for each block.
    c         S@ s   h  |  ] \ } } |  q S(    (    (   R   R@   R  (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pys	   <setcomp><  s   	 c         @ s   i  |  ] }   j    |  q S(    (   RQ  (   R   R   (   Rj  (    s-   lib/python2.7/site-packages/numba/ir_utils.pys
   <dictcomp>B  s   	 (   t   get_block_copiesR  R   R]  R   (   R   Rg  R>   Ri  t
   extra_killR   RI   Rk  R  t   gen_setR@   R  t   assignedRl  Rm  (    (   Rj  s-   lib/python2.7/site-packages/numba/ir_utils.pyRe  *  s,    	 "c         C@ s  i  } i  } x|  j    D]\ } } i  } t   | | <xT| j D]I} x t j    D] \ } }	 t | |  rU |	 | |  \ }
 } x |
 D] \ } } | | | <q Wi  } x_ | j    D]Q \ } } | | k r | | k r | | | <n  | | k r | | j |  q q W| } | | c | O<qU qU Wt | t j  rB | j j	 } t | j
 t j  r| j
 j	 } | | | | k r| | | <qB qn  t | j
 t j  rw| j
 j d k rw| j
 j j	 } | | } t | t j  p| t j k sw| | j |  i  } x_ | j    D]Q \ } } | | k rG| | k rG| | | <n  | | k r| | j |  qqW| } qwn  | | j |  qB qB Wt | j     } | | | <q W| | f S(   s2   get copies generated and killed by each block
    R.  (   R   R  Rr   t   copy_propagate_extensionsR&   R]  R   R0   R   R-   R   R*   R.   R/  R@   R   R^  Rb  (   R   R>   t   block_copiesRv  R  R   t   assign_dictR   R   R   Rw  t   kill_setR@   R  t   new_assign_dictR   R   t   in1_vart   in1_typt	   block_cps(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyRu  R  sX    
		
c      	   @ sa  | d k r g  } n  xE|  j   D]7\ } }   f d   | | D } x| j D]}	 t |	  t k r t t |	  }
 |
 |	 |   | | |  n7 t |	 t j  r t |	 j	 |  |	 _	 n t
 |	 |  t |	 | |  x t j   D] \ } }
 t |	 |  r |
 |	 |  \ } } x1 | D]) \ } } |   k r!  | | | <q!q!WxN | j   j   D]7 \ } } | | k s| j | k ra| j |  qaqaWq q Wt |	 t j  rt |	 j	 t j  r|	 j j } |	 j	 j } | | k r| | | | k r|   k r  | | | <n | j | d  g  } x9 | j   D]+ \ } } | j | k rB| j |  qBqBWx! | D] } | j | d  qxWqn  t |	 t j  rR t |	 j	 t j  rR |	 j j } | j | d  g  } x9 | j   D]+ \ } } | j | k r| j |  qqWx! | D] } | j | d  q%WqR qR W| j | j    q" W| S(   sE   apply copy propagation to IR: replace variables when copies availablec         @ s#   i  |  ] \ } }   | |  q S(    (    (   R   R   R   (   t   name_var_table(    s-   lib/python2.7/site-packages/numba/ir_utils.pys
   <dictcomp>  s   	 N(   R   R   Rr   R  t   apply_copy_propagate_extensionsR&   R   R0   R   R   R   t   fix_setitem_typeRy  RQ  R-   t   popR*   R   R1   R=   (   R   Rl  R  R>   R?   t   save_copiesR  R   t   var_dictR   R   R   Rw  R|  R@   R  R   R   t   lhs_killRe   Rf   (    (   R  s-   lib/python2.7/site-packages/numba/ir_utils.pyt   apply_copy_propagate  s^    	' c         C@ s   t  |  t j t j f  s d S| |  j j } | |  j d } t  | t j j	  sl t  | t j j	  rp d S| j
 d k r | j
 d k r | j d | j
  } | | |  j d | |  j d f | |  _ n  d S(   s   Copy propagation can replace setitem target variable, which can be array
    with 'A' layout. The replaced variable can be 'C' or 'F', so we update
    setitem call type reflect this (from matrix power test)
    Ni    t   At   layouti   i   (   R&   R   R   R   R   R-   Rz   R   t   npytypest   ArrayR  RQ  (   R   R>   R?   t   t_typt   s_typt	   new_s_typ(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR    s     c         C@ s   t  j d k r |  j } | d k r* | n | |  _ |  j j } t d | | f j d d   |  j   t d d  | |  _ n  d S(   sq   Debug print function IR, with an optional blocks argument
    that may differ from the IR's original blocks.
    i   s	   IR %s: %siP   t   -i(   N(	   R   R  R   R   t   func_idt   func_qualnameR  t   centert   dump(   R   t   titleR   t	   ir_blocksR-   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   dprint_func_ir  s    	 
c         @ sc    d k r t    n  g   t          f d        j     j    S(   s{   find topological order of blocks such that true branches are visited
    first (e.g. for_break test in test_dataflow).
    c         @ s   |   k r  j  |    j |  }  |  j d } t | t j  r^ | j | j g } n  x0 | D]( } |  | f  j k re   |  qe qe W j	 |   n  d  S(   Ni(
   R]  t   _succsRr   R&   R   R   R   R   t   _back_edgesR1   (   R   t   succst	   last_instt   dest(   t   _dfs_recR   R  t
   post_ordert   seen(    s-   lib/python2.7/site-packages/numba/ir_utils.pyR     s    N(   R   R   R  Rd  R  (   R   R  (    (   R  R   R  R  R  s-   lib/python2.7/site-packages/numba/ir_utils.pyt   find_topo_order  s    	
c         C@ s  | d k r i  } n  | d k r* i  } n  | r? t |   } n t |  j    } x-t |  D]} xt |  | j  D]} t | t j  r:| j	 j
 } | j } t | t j  r | j d k r g  | | j j
 <n  t | t j  rm| j d k rm| | k r-| | j | j  | | | j j
 <n  | | k rm| | }	 | |	 j | j  |	 | | j j
 <qmn  t | t j  r| | k r| | j | j  n  | | k r| | }	 | |	 j | j  qn  t | t j  r:| | k r| | j | j  n  | | k r7| | }	 | |	 j | j  q7q:n  x< t j   D]. \ }
 } t | |
  rG| | | |  qGqGWqx Wq^ W| | f S(   sA   returns a dictionary of call variables and their references.
    R:   R6   N(   R   R  R   R   R  Rr   R&   R   R0   R   R-   R   R.   R/  Rd   R1   R   R5   t   FreeVart   call_table_extensionsR   (   R   R  t   reverse_call_tablet   topological_orderingt   orderR  R   R@   R  t   call_varR   R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR    sL    			!!


c         C@ s  | d k r i  } n  x |  j   D] } x | j D] } t | t j  r | j j } | j } t | t j	  r | j
 d k r | j | | <n  t | t j  r t | j t  r | j | | <q n  x9 t j   D]+ \ } } t | |  r | | |  q q Wq2 Wq" W| S(   s>   returns a dictionary of tuple variables and their values.
    R/   N(   R   R   Rr   R&   R   R0   R   R-   R   R.   R/  R   R[   R'   t   tuple_table_extensions(   R   t   tuple_tableR   R   R@   R  R   R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   get_tuple_tableK  s    		!$c         C@ sD   t    } t |  t j t j t j f  r@ | j |  j j  n  | S(   N(	   R  R&   R   R0   R   R   R]  R   R-   (   R   t   writes(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   get_stmt_writes`  s    	!c         C@ sh  t  |   } d } x< |  j   D]. \ } } t | j d t j  r | } q q W| d k rz | j |  | j |  n  i  } t | d t	 } x | D] } | j
   | | <q Wxw |  j   D]i } | j } t | t j  r | | j | _ n  t | t j  r | | j | _ | | j | _ q q Wi  }	 x. |  j   D]  \ }
 } | |
 } | |	 | <q@W|	 S(   s   rename labels of function body blocks according to topological sort.
    The set of labels of these blocks will remain unchanged.
    iR  (   R  R   R&   Rr   R   R   R  R1   t   sortedR   R  R   R  Rp   R   R   R   R   (   R   t
   topo_ordert   return_labelR   R   t	   label_mapt
   all_labelsR  R   R   Re   t	   new_label(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   rename_labelsg  s0    	
c         @ s  t     }   f d   } t t |   j     } t   } x | D] }   | j d } | j |  } t } xV | D]N \ }	 }
   |	 } t | j d t	 j
  r t j |  | j d <qy t } qy W| rF | j |  qF qF Wx | D] }   | =q Wt    t    S(   s@   transform chains of blocks that have no loop into a single blockc         @ s6     |  } t  | j  d k o5 t | j d t j  S(   Ni   i    (   R(   Rr   R&   R   R   (   R  R   (   R   (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   find_single_branch  s    
i    i(   R   R   t   filterR   R  Rr   Rf  R   R&   R   Rp   RQ  R   R]  t   merge_adjacent_blocksR  (   R   R  R  t   single_branch_blockst   marked_for_delR  R   Rf  t   delete_blockRs  t   qR   (    (   R   s-   lib/python2.7/site-packages/numba/ir_utils.pyt   simplify_CFG  s&    	


t   mint   maxt   sumt   prodt   meanR   t   stdt   cumsumt   cumprodt   argmint   argmaxt   argsortt   nonzeroRB  c         @ s  |  j  } i  } t |  } xm| D]e} | | } g  }	 xC| j D]8}
 t |
 t j  rmt |
 j t j  rm|
 j j	 } |
 j } | j
 d k r| j t k rt   | j j	 t j j  r|
 j } | j } | | | <| j } | j } t j | t d  |  } t j j t    | j	 <t j d t |  } t j | | |  } | | _ |	 j |  | g |  j | j	 <t t | j  } t |  }   j |  |   | <n  | j
 d k rm| j j	 | k rm| | j j	 } | j |  } | j t | j   }   f d   | j  D }   | j j	 j! |   | j	 g t" |  |  | | <| g | j | _ qmn  |	 j |
  qB W|	 | _ q" Wd  S(   NR6   s	   $np_g_varR!   R:   c         @ s&   i  |  ] \ } }   | j  |  q S(    (   R-   (   R   R-   Rf   (   R>   (    s-   lib/python2.7/site-packages/numba/ir_utils.pys
   <dictcomp>  s   	 (#   R   R  Rr   R&   R   R0   R   R.   R   R-   R/  R   t   arr_mathR   R  R  RC   RD   R*   R   R2   R3   R4   R5   R1   RK  R6   R7   R  Rd   Rz   R(   t   kwsR;   R   (   R   R>   R?   t	   typingctxR   t   saved_arr_argR  R  R   R   R   R@   R  t   arrRC   RD   RM   RN   RO   Rd   t   func_typt   old_sigt   argtypst   kwtyps(    (   R>   s-   lib/python2.7/site-packages/numba/ir_utils.pyt   canonicalize_array_math  sP    	
'			
			!'c   	      C@ s  | d k r t   } n  x|  j   D]} x| j D]} t | t j  ro | j | j j	 | j
 j	 f  n  t | t j  r | j | j j	 | j j	 f  n  t | t j  r}| j j	 } | j } t | t j  r| j d k r| j | j j	 | j
 j	 f  n  t | t j  r}| j d k r}| j
 } | d k sOt |  r^| j j	 } n  | j | j j	 | f  q}n  x9 t j   D]+ \ } } t | |  r| | |  qqWq5 Wq% W| S(   s8   returns a set of arrays accessed and their indices.
    RF  RG  N(   R   R  R   Rr   R&   R   R   R]  R   R-   R   R   R   R0   R   R.   R/  t   is_slice_indext   array_accesses_extensionsR   (	   R   t   accessesR   R   R@   R  R   R   R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   get_array_accesses  s,    ""	!"!	c         C@ sM   t  |  t  r t St  |  t  rI x$ |  D] } t  | t  r) t Sq) Wn  t S(   s0   see if index is a slice index or has slice in it(   R&   R0  R   R'   R   (   R   Rp  (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR    s    c   	      C@ s?  t  |   } t   } x#t |  j    D]} | | k r@ q( n  |  | } t | j |   } x t r6t |  d k r~ Pn  | d d } | | k r Pn  t | j |   } t | j |   } t |  d k s | d d | k r Pn  |  | } | j j	   | j | j 7_ |  | =| j
 |  | } qb Wq( Wd  S(   Ni   i    (   R   R  R   R   R	  R   R(   Rf  Rr   R  R]  (	   R   R  R  R  R   R  R    t   predst
   next_block(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR    s.    	
	&
c         C@ s   i  } x | D]~ \ } } | j  d  r | j j  d  r | j | k r t d j |   } | | | j <| j | j  } | | | <q q Wt |  |  d S(   sS   
    restores variable names of user variables after applying copy propagation
    R   s   ${}N(   t
   startswithR-   R   R   R  R   (   R   R  R>   t   rename_dictRA  R   R   Rc  (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   restore_copy_var_names,  s    "c         C@ s   t  |  j  t |  j |  \ } } t |  j  } t |  j | | | |  } t |  j | |  t |  j |  j |  |  t |  j  |  _ t	 j
 d k r t |  d  n  d  S(   Ni   s   after simplify(   R   R   Rt  R   R  R  R   R   R  R   R  R  (   R   R>   R?   t   in_cpst   out_cpsR  R  (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   simplify>  s    	t   GuardExceptionc           B@ s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR  Q  s   c         C@ s   |  s t   n  d S(   s?   
    Raise GuardException if the given condition is False.
    N(   R  (   R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   requireT  s    c         O@ s*   y |  | |   SWn t  k
 r% d SXd S(   s   
    Run a function with given set of arguments, and guard against
    any GuardException raised by the function by returning None,
    or the expected return results if no such exception was raised.
    N(   R  R   (   Rd   Rz   t   kwargs(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyRN  [  s    c         K@ s2   y |  j  | |  SWn t k
 r- t  n Xd S(   sm   
    Same as func_ir.get_definition(name), but raise GuardException if
    exception KeyError is caught.
    N(   t   get_definitiont   KeyErrorR  (   R   R-   R  (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR  f  s    c         C@ s   | d k r t j t  } n  x |  j   D] } x | j D] } t | t j  r | j	 j
 } | j | g   } | g  k r | | | <n  | j | j  n  t |  t k r; t t |  } | | |  q; q; Wq+ W| S(   s   Build the definitions table of the given blocks by scanning
    through all blocks and instructions, useful when the definitions
    table is out-of-sync.
    Will return a new definition table if one is not passed.
    N(   R   t   collectionst   defaultdictR   R   Rr   R&   R   R0   R   R-   t   getR1   R   R  t   build_defs_extensions(   R   t   definitionsR   R   R-   t
   definitionR   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyRJ  p  s    c         C@ s  t  t | t j  o! | j d k  | j } | |  |  } g  } d } xot rt | t j t j	 f  rd d d g } d }	 x6 | D]. }
 t
 | j |
  r t | j |
  }	 Pq q W|	 s t |	 t  r t  n  | j |	  | j } t | t j j  r| j } n  t
 | d  r| j } t
 t |	  r^| t t |	  k r^| d g 7} qt
 t j |	  r| t t j |	  k r| d d g 7} q| d k	 r| j |  qn= | j j } | d k rd	 } n  | d
 k r| j |  n  PqL t | t j  r| j d k r| j } | j | j  | rz| j | k rz| | j } t | t j  sz| d | f Sn  | |  |  } qL | d k	 rd j t |   | f St  qL W| d d j t | d   f S(   sz  Try to find a call expression's function and module names and return
    them as strings for unbounded calls. If the call is a bounded call, return
    the self object instead of module name. Raise GuardException if failed.

    Providing typemap can make the call matching more accurate in corner cases
    such as bounded call on an object which is inside another object.
    R:   R-   R5  R  R  R4   R#  t   builtin_function_or_methodt   builtint   moduleR6   i    R   i   N(   R  R&   R   R.   R/  Rd   R   R   R5   R  t   hasattrR   R6   R   R  R1   R   R3  R4  t   _defnR  R4   R#  t	   __class__R  R   R-   R   R3   t   joinR  (   R   RV  R>   t   definition_findert   calleet
   callee_deft   attrst   objR   R   t   keyt   def_valt   mod_namet
   class_nameRc  (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyRO    s^    %						!	
c         C@ sm   t  t | t j   t |  |  } t  t | t j   d d d g } t  | j | k  | j | j f S(   s   Check if a variable is constructed via build_tuple or
    build_list or build_set, and return the sequence and the
    operator, or raise GuardException otherwise.
    Note: only build_tuple is immutable, so use with care.
    R/   t
   build_listt	   build_set(   R  R&   R   R*   R  R.   R/  R   (   R   R   t   var_deft	   build_ops(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   find_build_sequence  s    c         C@ sQ   t  t | t j   t |  |  } t  t | t j t j t j f   | j S(   sv   Check if a variable is defined as constant, and return
    the constant value, or raise GuardException otherwise.
    (	   R  R&   R   R*   R  R[   R5   R  R   (   R   R   R  (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt
   find_const  s    %c         C@ s  d d l  m } t |  d  r+ |  j } n0 t |  d  rF |  j } n t d j |     t | |  } t | j	  t
 | j	 t d  | _	 t | j	 j    }	 |	 a t | j	  }
 i  } x* |
 j   D] \ } } t |  | | <q Wt | j	 |  | r| j | | | d  \ } } } g  | D] } | j d  r+| ^ q+} x | D] } | j |  qSW| j |  | j |  n  | S(	   s  
    Compile a function or a make_function node to Numba IR.

    Rename variables and
    labels to avoid conflict if inlined somewhere else. Perform type inference
    if typingctx and other typing inputs are available and update typemap and
    calltypes.
    i    (   t   compilert   codet   __code__s   function type not recognized {}i   s   arg.N(   R   R   R  R  R  t   NotImplementedErrorR   t   get_ir_of_codeR   R   R   R   R  R   R   R   R   R   t   type_inference_stageR   R  R  t   update(   t   mk_funct   glblsR  t   arg_typsR>   R?   R   R  t   f_irR   R   t   new_var_dictR-   R   t	   f_typemapt   f_return_typet   f_calltypest   vnameR   RA  (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   compile_to_numba_ir  s2    
(c         C@ s^  t  | j  } d j g  t |  D] } d | ^ q"  } d j g  t |  D] } d | ^ qN  } d j g  t | j  D] } d | ^ q}  } d | | | f } i  } t | |  |  t j d k rt j d k  rt | j	  }	 t  |	  d	 k r|	 d	 d
 k rd |	 d	 <n  t
 j | j | j | j | j | j | j | j | j t |	  | j | j | j | j | j | j  } n  | d   }
 | |
 _ | j |
 _ d	 d l m } | j |
  } d t f d     Y} t j  j! d | |  |  i  } t j" j# | t j$ j% j& t'  |  } | j(   d	 d l m) } | j* |  } | j(   | S(   s.   
    Compile a code object to get its IR.
    s   
s     c_%d = Nonet   ,s   c_%ds   x_%ds3   def g():
%s
  def f(%s):
    return (%s)
  return fi   i   i    s   .0t	   implicit0t   g(   R   t   DummyPipelinec           B@ s   e  Z d    Z RS(   c         S@ sC   d  |  _ d  |  _ d  |  _ | |  _ d  |  _ d  |  _ d  |  _ d  S(   N(   R   R  t	   targetctxRz   R   R>   t   return_typeR?   (   t   selfR
  (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   __init__=  s    						(   R  R  R  (    (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR  <  s   s   before-inference(   R   (   i   (   i   i   (+   R(   t   co_freevarsR  Rg   t   co_argcountR   R   t	   PYVERSIONR   t   co_varnamest   pytypest   CodeTypet   co_kwonlyargcountt
   co_nlocalst   co_stacksizet   co_flagst   co_codet	   co_constst   co_namesR'   t   co_filenamet   co_namet   co_firstlinenot	   co_lnotabt   co_cellvarsR  R  R   R   t   run_frontendt   objectR
   t   rewrite_registryt   applyt   inline_closurecallt   InlineClosureCallPasst   targetst   cput   ParallelOptionsR   R   R   R   (   R  t   fcodet   nfreeRp  t   func_envt   func_clot   func_argt	   func_textRD   R  R   R   R   R  t   swappedt   inline_passR   R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyR    sX    ,,/"				

c         C@ ss   xl |  j  D]a } t | t j  r
 t | j t j  r
 | j j } | t |  k  s[ t  | | | _ q
 q
 Wd S(   s,   
    Replace ir.Arg(...) with variables
    N(	   Rr   R&   R   R0   R   R   R   R(   R\   (   R   Rz   R   t   idx(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   replace_arg_nodesQ  s    'c         C@ s:  x3|  j    D]%} g  } xt | j  D]\ } } t | t j  r | d t | j  k sf t  t j | j	 | | j
  | j | <| j j t j | | j
   x | D]0 } | j j | j	 j k r | j	 j	 | _	 q q Wq) t | t j  r) t | j	 t j  r) | j	 j d k r) | j |  q) q) Wq Wd S(   sN   
    Return return statement by assigning directly to target, and a jump.
    i   RE  N(   R   t	   enumerateRr   R&   R   R   R(   R\   R0   R   RD   R1   Rp   R   R-   R.   R/  (   R   R   R  R   t   castsRp  R   RE  (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   replace_returns\  s    "9c         C@ sU  | d j  } | d j } t j | t d  |  }	 t j j t  | |	 j	 <t j
 d t |  }
 t j |
 |	 |  } t j j |	 |  |  } t j | t d  |  } t |  } | | | j	 <t j | | |  } t j j | | d |  } g  | D] } | | j	 ^ q } | j | | i   } | | | <t j | | |  } | | | g S(   Ni    s	   $np_g_varR!   s   $np_attr_attr(    (   RC   RD   R   R*   R   R   R2   R3   R4   R-   R5   R0   R.   R6   R7   R:   R;   (   t   func_as_strRd   R@   Rz   R  R>   R?   RC   RD   RM   RN   RO   t   np_attr_callRQ   t   func_var_typRR   t   np_callR   t	   arg_typesR  t	   np_assign(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   gen_np_calln  s"     
c         C@ sO   xH |  j    D]: \ } } t | d  x | j D] } t d |  q0 Wq Wd  S(   Nt   :s       (   R   R  Rr   (   R   R  R   R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   dump_blocks  s    c         C@ s   t  |   p t |   S(   s8   stmt is getitem assignment or setitem (and static cases)(   t
   is_getitemt
   is_setitem(   R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   is_get_setitem  s    c         C@ s7   t  |  t j  o6 t  |  j t j  o6 |  j j d k S(   s6   true if stmt is a getitem or static_getitem assignmentRF  RG  (   RF  RG  (   R&   R   R0   R   R.   R/  (   R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyRJ    s    c         C@ s   t  |  t j t j f  S(   s/   true if stmt is a SetItem or StaticSetItem node(   R&   R   R   R   (   R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyRK    s    c         C@ sh   t  |   r5 |  j j d k r( |  j j S|  j j Sn  t |   rd t |  t j  rZ |  j S|  j Sn  d S(   s?   get index variable for getitem/setitem nodes (and static cases)RF  N(
   RJ  R   R/  R   R   RK  R&   R   R   R   (   R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   index_var_of_get_setitem  s    

c         C@ s   t  |   r< |  j j d k r- | |  j _ q | |  j _ nK t |   rr t |  t j  rf | |  _ q | |  _ n t	 d j
 |     d  S(   NRF  s0   getitem or setitem node expected but received {}(   RJ  R   R/  R   R   RK  R&   R   R   t
   ValueErrorR   (   R   t	   new_index(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   set_index_var_of_get_setitem  s    	c         C@ s   t  |  t  s t S|  j } t |  d k s> | d t k rB t St |  d  sU t St |  d d  } t  | t  sz t St	 d   | D  S(   s    check if c is a namedtuple classi   i    t   _maket   _fieldsc         s@ s   |  ] } t  | t  Vq d  S(   N(   R&   R   (   R   R   (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pys	   <genexpr>  s    N(
   R&   R  R   t	   __bases__R(   R'   R  R6   R   t   all(   t   ct   basest   fields(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   is_namedtuple_class  s    	"c      
   C@ s|  |  j  } |  j } t j d | d |  } | j d |  } |  j t j d | d | d |   g  | D] }	 | j |	  ^ qh }
 t j j	 d | d |
 d d	 d |  } | j d |  } |  j t j d | d | d |   xu t
 |  D]g \ } } | j |  } t j j d | d | d d
 d |  } |  j t j d | d | d |   q W|  j t j d | d |   |  S(   s   Fill *newblock* to call *callee* with arguments listed in *inputs*.
    The returned values are unwraped into variables in *outputs*.
    The block would then jump to *label_next*.
    R   RD   R   Rd   Rz   R  R   R   (    N(   RC   RD   R   R[   t	   make_tempR1   R0   t	   get_exactR.   R:   R>  RG  R   Rp   (   t   newblockR  t
   label_nextt   inputst   outputsRC   RD   t   fnt   fnvarR-   Rz   t   callexprt   callresRp  RE   R   RF  (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   fill_block_with_call  s     		%"'%)c      	   C@ s   |  j  } |  j } g  t |  D]* \ } } t j d | d | d |  ^ q } x` t | |  D]O \ } }	 t j d | d | d |  }
 |  j t j d |
 d |	 d |   q_ W|  j t j	 d | d |   |  S(   s   
    Fill a new block *block* that unwraps arguments using names in *inputs* and
    then jumps to *label_next*.

    Expected to use with *fill_block_with_call()*
    R-   R   RD   RC   R   R   (
   RC   RD   R>  R   R   t   zipR*   R1   R0   Rp   (   R   R]  R\  RC   RD   Rp  Re   Rz   t   anamet   avalt   tmp(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   fill_callee_prologue  s    		:)c         C@ s   |  j  } |  j } g  | D] } | j d |  ^ q } t j j d | d |  } | j d |  } |  j t j d | d | d |   |  j t j	 d | d |   |  S(   s   
    Fill a new block *block* to prepare the return values.
    This block is the last block of the function.

    Expected to use with *fill_block_with_call()*
    R-   R   RD   R   R   (
   RC   RD   RZ  R   R.   R/   RY  R1   R0   R   (   R   R^  RC   RD   R-   t   valst   tupexprt   tup(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   fill_callee_epilogue  s    		%%c         C@ s   |  j  |  } t | t j  r( | j St | t j  r | j d k r t |  | j  } y t | | j	  } | SWq t
 k
 r t  q Xn  t  d S(   sh   Check if a variable is a global value, and return the value,
    or raise GuardException otherwise.
    R6   N(   R  R&   R   R5   R   R.   R/  t   find_global_valueR6   R   R  R  (   R   R   t   dfnt   prev_valt   val(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyRm    s    !c         C@ s'  g  } xm |  j  D]b } | | k r t | | t j j  r | | j d k r d j |  } t | |  j   q q WxW|  j	 j
   D]F} x=| j t j  D])} t | j t j  rg| j j d k rg| j } t | d d  } | d k	 r0t | d d  d k	 rd }	 d }
 q<| j }	 d |	 }
 n d	 }	 d }
 d
 |	 |
 f } t | | j j   qgn  t | j t j t j f  r"| j } t | d d  } | d k rq n  t } t | t j  r| t j t j h k } n  | st | d d  d k } n  | r"| j | j  q"n  t | j t j  rK| j j d k rK| j j d k rK| j j j } t | | t j  rq n  |  j  |  } t! t" |  |  } | r| d d k rt t# | d  } t# j$ | t# j%  s t# j$ | t# j&  rq qn  | j' d  rd n d j |  } t( d j |  d | j  qKn  t | j t j  r | | j) j } d } t | d t  st | t j*  rt( | | | j j | f d | j  qq q Wq Wt+ |  d k r#d } d j, g  | D] } | j-   ^ q } t | |   n  d S(   s&  
    Helper function to walk IR and raise if it finds op codes
    that are unsupported. Could be extended to cover IR sequences
    as well as op codes. Intended use is to call it as a pipeline
    stage just prior to lowering to prevent LoweringErrors for known
    unsupported features.
    i  s'  Tuple '{}' length must be smaller than 1000.
Large tuples lead to the generation of a prohibitively large LLVM IR which causes excessive memory pressure and large compile times.
As an alternative, the use of a 'list' is recommended in place of a 'tuple' as lists do not suffer from this problem.t   make_functionR  t   closures$   <creating a function from a closure>t    s   (%s) s   <could not ascertain use case>s   Numba encountered the use of a language feature it does not support in this context: %s (op code: make_function not supported). If the feature is explicitly supported it is likely that the result of the expression %sis being used in an unsupported manner.R   R5  t   gdb_internalR6   t   viewi   R4   i    R   s   '{}' sZ   'view' can only be called on NumPy dtypes, try wrapping the variable {}with 'np.<dtype>()'RD   s   The use of a %s type, assigned to variable '%s' in globals, is not supported as globals are considered compile-time constants and there is no known way to compile a %s type as a constant.t	   reflecteds  Calling either numba.gdb() or numba.gdb_init() more than once in a function is unsupported (strange things happen!), use numba.gdb_breakpoint() to create additional breakpoints instead.

Relevant documentation is available here:
http://numba.pydata.org/numba-doc/latest/user/troubleshoot.html/troubleshoot.html#using-numba-s-direct-gdb-bindings-in-nopython-mode

Conflicting calls found at:
 %ss   
N(.   R   R&   R   R+   R,   t   countR   R   RD   R   R   t
   find_instsR   R0   R   R.   R/  R6   R   R'  R5   R  R   R  t   FunctionTypeR   t   gdbt   gdb_initR1   R   R-   R  R  RN  RO  R4   t
   issubdtypet   integert   floatingR  R   R   t   DictTypeR(   R  t	   strformat(   R   R>   t	   gdb_callst   arg_namet   msgt   blkR   Rp  R  t   useRV  t   foundR   t   dft   cnt   tyt   vardescrR   t   buf(    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   raise_on_unsupported_feature!  s~    					$	$6(c   
      C@ s   x | j    D] \ } } | j r | j d  r |  j } | j d  d } |  j j } t | t j	  rq d n d } d } d | | | | f }	 t
 j t |	 d |  q q q Wd  S(	   Ns   arg.R   i   R   R  st   http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-reflection-for-list-and-set-typess   
Encountered the use of a type that is scheduled for deprecation: type 'reflected %s' found for argument '%s' of function '%s'.

For more information visit %sRD   (   R   Rv  R  RD   t   splitR  R  R&   R   t   Listt   warningst   warnR   (
   R   R>   R-   R  RD   R   RX  t   tynamet   urlR  (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   warn_deprecated  s    		(   t
   __future__R    R   R4   R   R  R  t   operatorR  t   llvmliteR   t   lirR   t	   numba.sixR   R   R   R   R   R	   R
   t   numba.typing.templatesR   R   R   t   numba.targets.imputilsR   t   numba.analysisR   R   R   t   numba.errorsR   R   R   RQ  R   R   R   R   R    RY   R)   R7   R   Ri   Rh   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R  R
  R9  R'  R1   R  R<  R=  R?  RL  RP  R  RM  R@  Rt  Re  Ry  Ru  R  R  R  R  R  R  R   R  R  R  R  R  R  R  R  R  R  R  R  R  R  t	   ExceptionR  R  RN  R  RJ  R  RO  R  R  R  R  R=  R@  RG  RI  RL  RJ  RK  RM  RP  RX  Rc  Rh  Rl  Rm  R  R  (    (    (    s-   lib/python2.7/site-packages/numba/ir_utils.pyt   <module>   s   :				>			%	'		%		
			
			
	3						D		'		B			%	%	9A	2		%		6	
	 					
C			.	@															t