tvm_tirx.script.ir_builder.parser_protocol.function_

Contents

tvm_tirx.script.ir_builder.parser_protocol.function_#

tvm_tirx.script.ir_builder.parser_protocol.function_(*, decl=False, loc=None, **options)#

Create the native function frame used for signature and body construction.

Parameters:
  • decl (bool, optional) – False (default) constructs a complete function on one entry. True collects a signature on the first entry and retains this frame for body re-entry.

  • loc (LocationEntry, Location or None, optional) – Location for the constructed result. None (the default) leaves explicit location unspecified; active source-call provenance is composed by the builder. Frames retain their location until finalization.

  • options (Any) – Language variant options: primitive function private and persistent default to False. Relax pure defaults to True and private/local to False; local=True requires a declared reference when building its body. See tvm_tirx.tirx.script.ir_builder.function_() and tvm.relax.script.ir_builder.function_() for their concrete options.

Returns:

IRBuilderFrame – The native context manager. It owns params, result type, symbol map, reference and completed result.

Return type:

IRBuilderFrame

Notes

Requires an active IRBuilder; module definitions also require its module frame. Declare every sibling signature before any body for forward references. Re-enter the same frame, define and invoke a zero-argument lexical helper inside it, then exit before validation. Invalid options/context raise builder errors. The frame stores its source location independently of exit-time ambient context.

# Source
@T.function
def f(a: T.int32):
    T.evaluate(a)
# Generated builder
with X.function_() as fn:
    X.func_name_("f")
    a = X.arg_("a", X.int32)
    X.emit_(X.evaluate(a))