tvm.tir.analysis

Wrapping existing analysis utils.

tvm.tir.analysis.analysis.expr_deep_equal(lhs: PrimExpr, rhs: PrimExpr) bool

Deeply compare two nested expressions.

Parameters:
Returns:

result – The comparison result

Return type:

bool

Note

This function does not remap variable bindings, it will not return true for (let x = 1 in x + 1) vs (let y = 1 in y + 1), unless x.same_as(y). Use py:func:tvm.ir.structural_equal to handle structural variable remapping.

Due to the restriction of not remapping variables, this function can run faster than StructuralEqual and can be used as a utility function during arithmetic simplifications.

Always consider py:func:tvm.ir.structural_equal first, which handles the structural remapping.

tvm.tir.analysis.analysis.verify_ssa(func: PrimFunc) bool

Verify if the func is in SSA form.

Parameters:

func (tvm.tir.PrimFunc) – The module to be verified.

Returns:

result – The result of verification.

Return type:

bool

tvm.tir.analysis.analysis.verify_memory(func: PrimFunc) bool

Verify if func contains illegal host side direct memory access.

Parameters:

func (tvm.tir.PrimFunc) – The module to be verified.

Returns:

result – The result of verification.

Return type:

bool

tvm.tir.analysis.analysis.undefined_vars(node: Stmt | PrimExpr, defs: list[Var] | None = None) list[Var]

Find undefined vars in a TIR statement or expression.

Parameters:
  • node (Union[Stmt, PrimExpr]) – The TIR statement or expression to be checked.

  • defs (Optional[List[tir.Var]]) – The vars that is defined

Returns:

result – The undefined vars.

Return type:

List[tir.Var]

tvm.tir.analysis.analysis.verify_well_formed(obj: PrimFunc | IRModule, assert_mode: bool = True) bool
Verify if the given TIR is well-formed. The verification includes:
  • Check if expressions not contain vars that is defined outside the block.

Parameters:
  • obj (Union[tvm.tir.PrimFunc, tvm.ir.IRModule]) – The function or module to be verified.

  • assert_mode (bool) – The indicator if it raises an error when the function is not well-formed.

Returns:

result – Whether it is a well-formed TIR function.

Return type:

bool