
    Upf1                        d dl T d dl mZ 	 ddlT d dlmZmZ ddlZddl	m
Z
mZmZmZmZ n# e$ rZ ed          edZ[ww xY wd	Zd
Z ej        ed           G d de                      Z ej        ed           G d de                      Zej        Z ej        ed           G d de                      ZdS )   )*)_Dialect   )get_default_loc_context_cext    N)AnyListOptionalSequenceUnionz+Error loading imports from extension module	arg_attrs	res_attrsT)replacec                   (    e Zd ZdZed             ZdS )
ConstantOpz)Specialization for the constant op class.c                 &    | j         d         j        S Nr   )resultstypeselfs    Y/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jaxlib/mlir/dialects/func.pyr   zConstantOp.type   s    |A##    N)__name__
__module____qualname____doc__propertyr    r   r   r   r      s3        33$ $ X$ $ $r   r   c            	           e Zd ZdZddddd fd
Zed             Zed             Zed             Zed             Z	ed	e
fd
            Zed             Zddeee                  fdZed             Zej        deeef         fd            Zed             Zed             Zej        defd            Zeddddedeee                  dee         fd            Z xZS )FuncOpz%Specialization for the func op class.N)
visibilitybody_builderlocipc                <   t                               t          |                    }t          |t                    r(t
                              |d         |d                   }t                              |          }|'t                               t          |                    nd}t                                          |||||           |rI| 	                                }	t          |	          5   ||            ddd           dS # 1 swxY w Y   dS dS )a  
        Create a FuncOp with the provided `name`, `type`, and `visibility`.
        - `name` is a string representing the function name.
        - `type` is either a FunctionType or a pair of list describing inputs and
          results.
        - `visibility` is a string matching `public`, `private`, or `nested`. None
          implies private visibility.
        - `body_builder` is an optional callback, when provided a new entry block
          is created and the callback is invoked with the new op as argument within
          an InsertionPoint context already set for the block. The callback is
          expected to insert a terminator in the block.
        r   r   inputsr   N)sym_visibilityr%   r&   )
StringAttrgetstr
isinstancetupleFunctionTypeTypeAttrsuper__init__add_entry_blockInsertionPoint)r   namer   r#   r$   r%   r&   sym_namer*   entry_block	__class__s             r   r3   zFuncOp.__init__&   sQ    >>#d)),, dE"" 	E##47DG#DDD||D!!/9/EJNN3z??+++4 	 	4CTVWWW 	#..00K,, # #T"""# # # # # # # # # # # # # # # # # #	# 	#s   6DDDc                 H    t          | j        d         j                  dk    S r   )lenregionsblocksr   s    r   is_externalzFuncOp.is_externalE   s    4<?)**a//r   c                     | j         d         S r   )r<   r   s    r   bodyzFuncOp.bodyI   s    |Ar   c                 Z    t          t          | j        d                   j                  S )Nfunction_type)r0   r1   
attributesvaluer   s    r   r   zFuncOp.typeM   s"    HT__%EFFLMMMr   c                     | j         d         S )Nr*   )rC   r   s    r   r#   zFuncOp.visibilityQ   s    /00r   returnc                 6    t          | j        d                   S )Nr7   )r+   rC   r   s    r   r6   zFuncOp.nameU   s    $/*5666r   c                 ^    | j         rt          d          | j        d         j        d         S )Nz&External function does not have a bodyr   )r>   
IndexErrorr<   r=   r   s    r   r8   zFuncOp.entry_blockY   s1     	GEFFF|A%a((r   arg_locsc                     | j         st          d           | j        j        j        | j        j        d|i | j        j        d         S )z
        Add an entry block to the function body using the function signature to
        infer block arguments.
        Returns the newly created block
        z(The function already has an entry block!rJ   r   )r>   rI   r@   r=   appendr   r)   )r   rJ   s     r   r4   zFuncOp.add_entry_block_   sQ      	IGHHH	!1EHEEEy""r   c                 @    t          | j        t                             S N)	ArrayAttrrC   ARGUMENT_ATTRIBUTE_NAMEr   s    r   r   zFuncOp.arg_attrsj   s    )@ABBBr   	attributec                     t          |t                    r|| j        t          <   d S t                              || j                  | j        t          <   d S )Ncontext)r.   rO   rC   rP   r,   rT   r   rQ   s     r   r   zFuncOp.arg_attrsn   sU    i++ 	7@DO34447@}}4< 8E 8 8DO3444r   c                     | j         j        S rN   )r8   	argumentsr   s    r   rW   zFuncOp.argumentsw   s    ))r   c                 &    | j         t                   S rN   rC   RESULT_ATTRIBUTE_NAMEr   s    r   result_attrszFuncOp.result_attrs{   s    455r   c                 $    || j         t          <   d S rN   rY   rU   s     r   r[   zFuncOp.result_attrs   s    1:-...r   )r   r6   r)   r   r6   c                      fd}|S )a  Decorator to define an MLIR FuncOp specified as a python function.

        Requires that an `mlir.ir.InsertionPoint` and `mlir.ir.Location` are
        active for the current thread (i.e. established in a `with` block).

        When applied as a decorator to a Python function, an entry block will
        be constructed for the FuncOp with types as specified in `*inputs`. The
        block arguments will be passed positionally to the Python function. In
        addition, if the Python function accepts keyword arguments generally or
        has a corresponding keyword argument, the following will be passed:
          * `func_op`: The `func` op being defined.

        By default, the function name will be the Python function `__name__`. This
        can be overriden by passing the `name` argument to the decorator.

        If `results` is not specified, then the decorator will implicitly
        insert a `ReturnOp` with the `Value`'s returned from the decorated
        function. It will also set the `FuncOp` type with the actual return
        value types. If `results` is specified, then the decorated function
        must return `None` and no implicit `ReturnOp` is added (nor are the result
        types updated). The implicit behavior is intended for simple, single-block
        cases, and users should specify result types explicitly for any complicated
        cases.

        The decorated function can further be called from Python and will insert
        a `CallOp` at the then-current insertion point, returning either None (
        if no return values), a unary Value (for one result), or a list of Values).
        This mechanism cannot be used to emit recursive calls (by construction).
        c                 p   ddl m t          j        |           }d}|j                                        D ]A}|j        |j        k    rd}|j        dk    r"|j        |j	        k    s|j        |j
        k    rd}Bd u }p| j        t                              |rg n          } |          }t          |                                          5  |j        j        }i }|r||d<    | |i |}	|st%                    |	
J d            n|	g }	nt'          |	t(                    rt%          |	          }	ngt'          |	t*                    r|	g}	nNt'          |	t,                    r|	j        j        }	n,t'          |	t2                    r|	j        }	nt%          |	          }	                    |	           d	 |	D             t                                        }t6                              |          |j        d
<   d d d            n# 1 swxY w Y   fd}
|
}| j        |_        ||_        |S )Nr   )funcFTfunc_opr(   )r6   r   zeCapturing a python function with explicit `results=` requires that the wrapped function returns None.c                     g | ]	}|j         
S r    )r   ).0vs     r   
<listcomp>z:FuncOp.from_py_func.<locals>.decorator.<locals>.<listcomp>   s    #B#B#BqAF#B#B#Br   rB   c                                           t                                        |           }d S t                    dk    r|j        S |j        S )Nr   )CallOpFlatSymbolRefAttrr,   r;   resultr   )	call_argscall_opr_   return_typessymbol_names     r   emit_call_opz<FuncOp.from_py_func.<locals>.decorator.<locals>.emit_call_op   s\    ++ "3"7"7"D"Di   '4&&!++">)"?*r   ) r_   inspect	signature
parametersvalueskindVAR_KEYWORDr6   POSITIONAL_OR_KEYWORDKEYWORD_ONLYr   r0   r,   r5   r4   r8   rW   listr.   r/   ValueOpView	operationr   	OperationReturnOpr1   rC   r`   )fsighas_arg_func_opparamimplicit_returnrB   r`   	func_argsfunc_kwargsreturn_valuesrm   wrappedr_   rk   rl   r"   r)   r6   r   s               @@@r   	decoratorz&FuncOp.from_py_func.<locals>.decorator   s    #A&&C#O..00 + +:!222&*O:**J%"===zU%777&*O &oO,!*K(,,_'Irr' -  M f+MBBBG 7 7 9 9:: #V #V#/9	 " 5-4K	* !9 < < <& V#'==L(00K 1000 %,(*#M599 <(,](;(;#M599 
<)6#M6:: <(5(?(G#M9== <(5(=(,](;(;MM-000#B#BM#B#B#BL$0$4$4%| %5 % %M ;C,,}:U:UG&7G#V #V #V #V #V #V #V #V #V #V #V #V #V #V #VJ	+ 	+ 	+ 	+ 	+ 	+ 	+ #G zG%GONs   D,HHHr    )r"   r   r6   r)   r   s   ```` r   from_py_funczFuncOp.from_py_func   s@    JI	 I	 I	 I	 I	 I	 I	 I	V r   rN   )r   r   r   r   r3   r   r>   r@   r   r#   r+   r6   r8   r   r   Locationr4   r   setterr   rO   rw   rW   r[   classmethodTyper-   r   __classcell__r9   s   @r   r"   r"   "   sI       // )-4Td# # # # # # #> 0 0 X0   X N N XN 1 1 X1 7j 7 7 7 X7 ) ) X)
	# 	#(1C(D 	# 	# 	# 	# C C XC 5D#9     * * X* 6 6 X6 ;i ; ; ; ;  -1"	o o oo (4.)o sm	o o o [o o o o or   r"   c            	       v     e Zd ZdZ	 dddddeeee         f         deeee	f         de
e         f fdZ xZS )	rf   z%Specialization for the call op class.Nr%   r&   calleeOrResultsargumentsOrCalleerW   c          	      8   t          |t                    rt          |t                    s"t          ddt	          |           z             |t          d          t                                          |j        j        t          	                    |j
        j        t          |                    |||           dS t          |t                    r"t          ddt	          |           z             t          |t                    r(t                                          |||||           dS t          |t                    rOt                                          |t          	                    |t          |                    |||           dS dS )	a  Creates an call operation.

        The constructor accepts three different forms:

          1. A function op to be called followed by a list of arguments.
          2. A list of result types, followed by the name of the function to be
             called as string, following by a list of arguments.
          3. A list of result types, followed by the name of the function to be
             called as symbol reference attribute, followed by a list of arguments.

        For example

            f = func.FuncOp("foo", ...)
            func.CallOp(f, [args])
            func.CallOp([result_types], "foo", [args])

        In all cases, the location and insertion point may be specified as keyword
        arguments if not provided by the surrounding context managers.
        zewhen constructing a call to a function, expected the second argument to be a list of call arguments, zgot Nz?unexpected third argument when constructing a callto a functionrS   r   zawhen constructing a call to a function by name, expected the second argument to be a string or a zFlatSymbolRefAttr, got )r.   r"   rw   
ValueErrorr   r2   r3   r   rg   r,   r6   rD   _get_default_loc_contextr-   )r   r   r   rW   r%   r&   r9   s         r   r3   zCallOp.__init__   s   > ov.. 	/66  M6T"344667  
 $ &  
 GG$,!%%#(.8PQT8U8U &   "     F'.. 	FED1B,C,CEEF   '):;; 	GG!2I32       )3// 		GG!%%%/G/L/L &         		 		r   rN   )r   r   r   r   r   r"   r
   r   rg   r-   r   r3   r   r   s   @r   rf   rf      s        // %)	K K K KvtDz12K !'8#!=>K D>	K K K K K K K K K Kr   rf   )_func_ops_genr   ir_ods_commonr   r   r   	_ods_cextro   typingr	   r
   r   r   r   ImportErroreRuntimeErrorrP   rZ   register_operationr   r"   r   r_   rf   r    r   r   <module>r      s  
     # # # # # #M       
 NNN;;;;;;;;;;;;;;; M M M
,D
E
E1LM & #  h555$ $ $ $ $ $ $ 65$ h555P P P P PV P P 65Pf  h555N N N N NV N N 65N N Ns   + A<A