14  Function

A function is usually a symbol operation with a callable type and a region that contains its body. The standard function dialect represents this with func.func, but generic compiler code should use function and call interfaces when it must support dialect-specific callable operations.

14.1 One Operation, Three Roles

A function is a symbol named with an at-sign, a callable interface with input and result types, and a region-owning operation. Its entry block arguments must match the input part of the function type; every return must match the result part. Changing a signature therefore requires coordinated edits to calls, block arguments, returns, symbol references, and often ABI lowering.

func.func @add_one(%x: i32) -> i32 {
  %one = arith.constant 1 : i32
  %result = arith.addi %x, %one : i32
  return %result : i32
}

14.2 Declarations, Definitions, And Calls

A declaration has a symbol and type but no body, supporting external runtime functions and separate compilation. A definition owns a CFG-capable region. Direct calls reference the callee by symbol, enabling forward declarations and recursion. Indirect calls and custom calling conventions use other operations or interfaces, so a pass that only recognizes direct function calls is not a general call analysis.

14.3 Transforming Functions

Inlining maps a callee entry argument to each call operand, remaps internal values, and replaces result uses while preserving control flow. Outlining does the inverse: captures become parameters and escaping values become results. Cloning needs a unique symbol name and a decision about internal recursive references. These are symbol and region transformations, not text substitution.