tvm_tirx.script.ir_builder.parser_protocol.if_

Contents

tvm_tirx.script.ir_builder.parser_protocol.if_#

tvm_tirx.script.ir_builder.parser_protocol.if_(condition, *, loc=None)#

Create the native conditional frame for a source if statement.

Parameters:
  • condition (Expr or bool) – Already-evaluated predicate; both branch bodies construct IR without testing it in Python.

  • 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.

Returns:

IRBuilderFrame – A native conditional context manager. Relax exposes its same-named merged output as frame.var after exit.

Return type:

IRBuilderFrame

Notes

Requires an active function region. Enter then_/else_ frames inside it; each branch’s lexical helper is defined and called inside that branch frame. TIRx permits a missing else; value-producing Relax branches must agree on their final binding name/type. Invalid context/condition/outputs produce builder diagnostics. Explicit constexpr conditions remain ordinary Python if statements.

# Source
if condition:
    T.evaluate(1)
# Generated builder
with X.if_(condition):
    with X.then_():
        def branch():
            X.emit_(X.evaluate(1))
        branch()