tvm_tirx.ir.format_tree

Contents

tvm_tirx.ir.format_tree#

tvm_tirx.ir.format_tree(value, *, fold=None, expand=None, hide=None, fold_formatters=None, max_depth=None, show_defaults=False)#

Display an object’s fields as a text tree.

Objects expand into labelled edges, arrays into indexed edges such as seq[0], and scalar fields stay in headers. SeqStmt wrappers remain. Expanded variable definitions display name = Var(...) at each occurrence, even when several definitions refer to the same variable. Variable uses and folded variables display names. Explicit expansion reveals the details of a variable use.

Field selectors are bare names that match every object, or (class, name) pairs that match a class and its subclasses. More-specific classes take precedence. Caller selections replace the default action for the exact same selector; if it appears in multiple caller options, expand wins over fold, which wins over hide. Explicit fold or expand selections also expose default-valued fields. Container keys are not field selectors. None and empty collections retain the standard defaults. Formatting never changes the supplied collections or the shared defaults.

Parameters:
  • value (Any) – IR object, extension object, container, or scalar to inspect.

  • fold (iterable of str or (class, str), optional) – Fields to inline with their parent. Standard fold selections are listed in DEFAULT_FOLD. By default, variable types, source/destination, indices, operation references, and loop bounds are folded. Folding includes the visible subtree; descendants stay folded or hidden even if an inner field requests expansion.

  • expand (iterable of str or (class, str), optional) – Fields to show on separate tree edges. Standard expansion selections are listed in DEFAULT_EXPAND. Objects expand automatically unless another rule folds or hides them. Expanding a variable use shows its declaration.

  • hide (iterable of str or (class, str), optional) – Fields to omit. Standard hide selections are listed in DEFAULT_HIDE: source locations, function attributes/return types, and expression types except variable types.

  • fold_formatters (mapping of class to callable, optional) – Partial overrides of DEFAULT_FOLD_FORMATTERS. The most specific matching callback takes an object and returns single-line text. These callbacks apply only inside folds; expansion shows the object’s fields.

  • max_depth (int, optional) – Maximum number of object/container edges from the root (depth zero). Deeper children display .... Indexed arrays still count toward depth. None means no depth limit. Cycles display <cycle>.

  • show_defaults (bool) – Include fields structurally equal to their declared defaults. Different types and distinct free variables remain distinguishable. By default, matching fields are omitted; fields without declared defaults remain visible. Hidden fields stay hidden. For loops omit default sequential kind, empty annotations, and an int32 unit step; differently typed or nonunit steps remain visible.

Returns:

text (str) – A tree without a trailing newline. Folded text is not width-truncated; expand selected fields to split long headers. Shared children can appear repeatedly. Maps with scalar keys sort by key type and text; other maps show key/value pairs in iteration order. This inspection text is not a serialization format.

Return type:

str

Examples

from tvm_tirx import ir

print(ir.format_tree(ir.Var("i", "int32")))
# i = Var(ty=int32)
print(ir.format_tree(ir.Var("i", "int32"), expand=[(ir.Var, "ty")]))
# i = Var
# └── ty: PrimType(dtype=int32)