Beaver.MLIR.Dialect.Func (beaver v0.4.8)

Copy Markdown

This module defines functions for Ops in Func dialect.

Summary

Functions

Return op name func.call as a bitstring.

func.call - call operation

Return op name func.call_indirect as a bitstring.

func.call_indirect - indirect call operation

Return op name func.constant as a bitstring.

func.constant - constant

Return op name func.func as a bitstring.

func.func - An operation with a name containing a single SSACFG region

Syntax sugar for Func.func SSA expression. No need to specify result types.

Syntax sugar for Func.func alike SSA expression. No need to specify result types.

Return op name func.return as a bitstring.

func.return - Function return operation

Functions

call()

Return op name func.call as a bitstring.

call(ssa)

func.call - call operation

Attributes

  • callee - Single, FlatSymbolRefAttr, flat symbol reference attribute
  • arg_attrs - Optional, DictArrayAttr, Array of dictionary attributes
  • res_attrs - Optional, DictArrayAttr, Array of dictionary attributes
  • no_inline - Optional, UnitAttr, unit attribute

Operands

  • operands - Variadic, AnyType, variadic of any non-token type

Results

  • anonymous - Variadic, AnyType, variadic of any non-token type

Description

The func.call operation 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

call_indirect()

Return op name func.call_indirect as a bitstring.

call_indirect(ssa)

func.call_indirect - indirect call operation

Attributes

  • arg_attrs - Optional, DictArrayAttr, Array of dictionary attributes
  • res_attrs - Optional, DictArrayAttr, Array of dictionary attributes

Operands

  • callee - Single, FunctionType, function type
  • callee_operands - Variadic, AnyType, variadic of any non-token type

Results

  • results - Variadic, AnyType, variadic of any non-token type

Description

The func.call_indirect operation 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.constant operation.

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>

constant()

Return op name func.constant as a bitstring.

constant(ssa)

func.constant - constant

Attributes

  • value - Single, FlatSymbolRefAttr, flat symbol reference attribute

Results

  • anonymous - Single, AnyType, any non-token type

Description

The func.constant operation produces an SSA value from a symbol reference to a func.func operation

Example:

// 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).

entry_block(op)

external?(op)

func()

Return op name func.func as a bitstring.

func(ssa)

func.func - An operation with a name containing a single SSACFG region

Attributes

  • sym_name - Single, SymbolNameAttr, string attribute
  • function_type - Single, anonymous/composite constraint, type attribute of function type
  • sym_visibility - Optional, StrAttr, string attribute
  • arg_attrs - Optional, DictArrayAttr, Array of dictionary attributes
  • res_attrs - Optional, DictArrayAttr, Array of dictionary attributes
  • no_inline - Optional, UnitAttr, unit attribute

Description

Operations 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}

func(call, opts)

(macro)

Syntax sugar for Func.func SSA expression. No need to specify result types.

func_like(call, op, list)

(macro)

Syntax sugar for Func.func alike SSA expression. No need to specify result types.

return()

Return op name func.return as a bitstring.

return(ssa)

func.return - Function return operation

Operands

  • operands - Variadic, AnyType, variadic of any non-token type

Description

The func.return operation 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
}