tvm_tirx.script.ir_builder.parser_protocol.for_

Contents

tvm_tirx.script.ir_builder.parser_protocol.for_#

tvm_tirx.script.ir_builder.parser_protocol.for_(iterable, *, names=None, loc=None)#

Configure and return the native iteration frame for a source for loop.

Parameters:
  • iterable (ForFrame or range) – Already-evaluated iteration specification. TIRx converts a Python range to its native serial frame.

  • names (str or sequence of str, optional) – Source target names, including at most one *starred group. None (the default) retains constructor defaults. Native configuration expands/validates them before entry; names never control the entry return shape.

  • 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 – The same configured ForFrame. Entry returns the native variable for one dimension, or the original variable sequence otherwise.

Return type:

IRBuilderFrame

Notes

TIRx requires an active primitive function before entry. Variables already have final names at entry. Simple scalar targets use the entry result; generated tuple, list or starred targets use the stable frame.vars sequence for unpacking. Invalid iterable/names raise TypeError, ValueError or native errors. Relax rejects imperative loops. A frame stores its location before deferred body finalization.

# Source
for i in range(n):
    T.evaluate(i)
# Generated builder
with X.for_(X.range_(n), names=("i",)) as i:
    X.emit_(X.evaluate(i))