tvm_ffi.structural#
TIRx builds on TVM-FFI and supports it as a first-class foundation. Every TIRx IR node is a TVM-FFI object that is shared across languages, so TIRx uses the native TVM-FFI utilities for walking and rewriting IR directly. We list these utilities here for completeness. See the TVM-FFI documentation for more details.
See also
tvm_tirx.tirx.structural provides variants of these utilities that also track constraint information, such as loop ranges and branch conditions, at each node.
Functions#
|
Walk a value structurally and invoke the first matching typed callback. |
|
Structurally map a value using typed replacement callbacks. |
|
Visit a value structurally with callbacks that own child traversal. |
|
Mutate a value with callbacks that own recursive mutation. |
|
Check structural equality between two values. |
|
Compute structural hash of a value. |
|
Like structural_equal(), but returns the AccessPath pair of the first detected mismatch. |
Classes#
|
Low-level structural traversal visitor. |
|
Low-level structural mutator. |
|
Hash-cached structural key wrapper. |
|
Control signal for structural walks. |
|
Callback placement before or after recursively traversing children. |
|
Payload-carrying signal that stops a structural visit. |
|
Def-region state active during structural visiting. |
|
Permission to mutate a value in place along its ownership path. |
Structural Hooks#
An object type tells these utilities how to handle it through structural hooks, which it can register from C++ or Python:
Hook |
Purpose |
|---|---|
|
Visits the object’s children and marks which fields define variables. |
|
Rewrites the object’s children. |
|
Optional. Reuses the object’s storage when it is safe to do so. |
|
Define structural equality and hashing. |
Every TIRx IR node registers compiled hooks; other objects fall back to their reflected fields.
TIRx marks loop and Bind variables as DEF_SIMPLE; it marks function
parameters, including the variables in their types, as DEF_PATTERN.
See Custom Visit and Mutation Hooks in the TVM-FFI documentation for how to write hooks.