mlir.dialects.func¶
Attributes¶
Classes¶
The |
|
Specialization for the call op class. |
|
Specialization for the constant op class. |
|
Specialization for the func op class. |
|
The |
|
Specialization for the constant op class. |
|
Specialization for the func op class. |
|
Specialization for the call op class. |
Functions¶
|
|
|
|
|
|
|
Module Contents¶
- class mlir.dialects.func.CallIndirectOp(results_, callee, callee_operands, *, arg_attrs=None, res_attrs=None, loc=None, ip=None)¶
Bases:
_ods_irThe
func.call_indirectoperation represents an indirect call to a value of function type. The operands and result types of the call must match the specified function type.Function values can be created with the
`func.constantoperation <#funcconstant-constantop>`_.Example:
%func = func.constant @my_func : (tensor<16xf32>, tensor<16xf32>) -> tensor<16xf32> %result = func.call_indirect %func(%0, %1) : (tensor<16xf32>, tensor<16xf32>) -> tensor<16xf32>
- OPERATION_NAME = 'func.call_indirect'¶
- _ODS_REGIONS = (0, True)¶
- callee() _ods_ir¶
- callee_operands() _ods_ir¶
- arg_attrs() _ods_ir | None¶
- res_attrs() _ods_ir | None¶
- results_() _ods_ir¶
- mlir.dialects.func.call_indirect(results_, callee, callee_operands, *, arg_attrs=None, res_attrs=None, loc=None, ip=None) _ods_ir | _ods_ir | CallIndirectOp¶
- class mlir.dialects.func.CallOp(result, callee, operands_, *, arg_attrs=None, res_attrs=None, no_inline=None, loc=None, ip=None)¶
Bases:
_ods_irThe
func.calloperation represents a direct call to a function that is within the same symbol scope as the call. The operands and result types of the call must match the specified function type. The callee is encoded as a symbol reference attribute named “callee”.Example:
%2 = func.call @my_add(%0, %1) : (f32, f32) -> f32
- OPERATION_NAME = 'func.call'¶
- _ODS_REGIONS = (0, True)¶
- operands_() _ods_ir¶
- callee() _ods_ir¶
- arg_attrs() _ods_ir | None¶
- res_attrs() _ods_ir | None¶
- no_inline() bool¶
- mlir.dialects.func.call(result, callee, operands_, *, arg_attrs=None, res_attrs=None, no_inline=None, loc=None, ip=None) _ods_ir | _ods_ir | CallOp¶
- class mlir.dialects.func.ConstantOp(result, value, *, loc=None, ip=None)¶
Bases:
_ods_irThe
func.constantoperation produces an SSA value from a symbol reference to afunc.funcoperationExample:
// Reference to function @myfn. %2 = func.constant @myfn : (tensor<16xf32>, f32) -> tensor<16xf32> // Equivalent generic forms %2 = "func.constant"() { value = @myfn } : () -> ((tensor<16xf32>, f32) -> tensor<16xf32>)
MLIR does not allow direct references to functions in SSA operands because the compiler is multithreaded, and disallowing SSA values to directly reference a function simplifies this (rationale).
- OPERATION_NAME = 'func.constant'¶
- _ODS_REGIONS = (0, True)¶
- value() _ods_ir¶
- mlir.dialects.func.constant(result, value, *, loc=None, ip=None) _ods_ir¶
- class mlir.dialects.func.FuncOp(sym_name, function_type, *, sym_visibility=None, arg_attrs=None, res_attrs=None, no_inline=None, loc=None, ip=None)¶
Bases:
_ods_irOperations within the function cannot implicitly capture values defined outside of the function, i.e. Functions are
IsolatedFromAbove. All external references must use function arguments or attributes that establish a symbolic connection (e.g. symbols referenced by name via a string attribute like SymbolRefAttr). An external function declaration (used when referring to a function declared in some other module) has no body. While the MLIR textual form provides a nice inline syntax for function arguments, they are internally represented as “block arguments” to the first block in the region.Only dialect attribute names may be specified in the attribute dictionaries for function arguments, results, or the function itself.
Example:
// External function definitions. func.func private @abort() func.func private @scribble(i32, i64, memref<? x 128 x f32, #layout_map0>) -> f64 // A function that returns its argument twice: func.func @count(%x: i64) -> (i64, i64) attributes {fruit = "banana"} { return %x, %x: i64, i64 } // A function with an argument attribute func.func private @example_fn_arg(%x: i32 {swift.self = unit}) // A function with a result attribute func.func private @example_fn_result() -> (f64 {dialectName.attrName = 0 : i64}) // A function with an attribute func.func private @example_fn_attr() attributes {dialectName.attrName = false}
- OPERATION_NAME = 'func.func'¶
- _ODS_REGIONS = (1, True)¶
- sym_name() _ods_ir¶
- function_type() _ods_ir¶
- sym_visibility() _ods_ir | None¶
- arg_attrs() _ods_ir | None¶
- res_attrs() _ods_ir | None¶
- no_inline() bool¶
- body() _ods_ir¶
- mlir.dialects.func.func(sym_name, function_type, *, sym_visibility=None, arg_attrs=None, res_attrs=None, no_inline=None, loc=None, ip=None) FuncOp¶
- class mlir.dialects.func.ReturnOp(operands_, *, loc=None, ip=None)¶
Bases:
_ods_irThe
func.returnoperation represents a return operation within a function. The operation takes variable number of operands and produces no results. The operand number and types must match the signature of the function that contains the operation.Example:
func.func @foo() -> (i32, f8) { ... return %0, %1 : i32, f8 }
- OPERATION_NAME = 'func.return'¶
- _ODS_REGIONS = (0, True)¶
- operands_() _ods_ir¶
- mlir.dialects.func.ARGUMENT_ATTRIBUTE_NAME = 'arg_attrs'¶
- mlir.dialects.func.RESULT_ATTRIBUTE_NAME = 'res_attrs'¶
- class mlir.dialects.func.ConstantOp(result, value, *, loc=None, ip=None)¶
Bases:
ConstantOpSpecialization for the constant op class.
- property type¶
- class mlir.dialects.func.FuncOp(name, type, *, visibility=None, body_builder=None, loc=None, ip=None)¶
Bases:
FuncOpSpecialization for the func op class.
- property is_external¶
- property body¶
- property type¶
- property visibility¶
- property name: StringAttr¶
- property entry_block¶
- add_entry_block(arg_locs: Sequence[Location] | None = None)¶
Add an entry block to the function body using the function signature to infer block arguments. Returns the newly created block
- property arg_attrs¶
- property arguments¶
- property result_attrs¶
- classmethod from_py_func(*inputs: Type, results: Sequence[Type] | None = None, name: str | None = None)¶
Decorator to define an MLIR FuncOp specified as a python function.
Requires that an
mlir.ir.InsertionPointandmlir.ir.Locationare active for the current thread (i.e. established in awithblock).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: Thefuncop being defined.
By default, the function name will be the Python function
__name__. This can be overriden by passing thenameargument to the decorator.If
resultsis not specified, then the decorator will implicitly insert aReturnOpwith theValue’s returned from the decorated function. It will also set theFuncOptype with the actual return value types. Ifresultsis specified, then the decorated function must returnNoneand no implicitReturnOpis 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
CallOpat 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).
- mlir.dialects.func.func¶
- class mlir.dialects.func.CallOp(calleeOrResults: FuncOp | List[Type], argumentsOrCallee: List | FlatSymbolRefAttr | str, arguments: List | None = None, *, loc=None, ip=None)¶
Bases:
CallOpSpecialization for the call op class.