Analysis#

Wrapping existing analysis utils.

tvm_tirx.tirx.analysis.analysis.verify_memory(func: Function) → bool#

Verify if func contains illegal host side direct memory access.

Parameters:

func (tvm_tirx.tirx.Function) – The module to be verified.

Returns:

result – The result of verification.

Return type:

bool

tvm_tirx.tirx.analysis.analysis.undefined_vars(node: Stmt | Expr, defs: list[Var] | None = None) → list[Var]#

Find undefined vars in a TIR statement or expression.

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

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

Returns:

result – The undefined vars.

Return type:

List[tvm_tirx.tirx.Var]

tvm_tirx.tirx.analysis.analysis.check_well_formed(obj: Function | IRModule, assert_mode: bool = True) → bool#

Check whether a TIRx function is well formed.

Parameters:
Returns:

result – True for valid IR; False for invalid IR when assert_mode is False.

Return type:

bool

Raises:

RuntimeError – If the IR is invalid and assert_mode is True.

tvm_tirx.tirx.analysis.analysis.detect_linear_equation(expr, var_list)#

Match expr = sum_{i=0}^{n-1} var[i] * coeff[i] + coeff[n]

Where coeff[i] and base are invariant of var[j] for all i and j.

Parameters:
  • expr (Expr) – The expression to be matched.

  • var_list (List[tvm_tirx.ir.Var]) – A list of variables.

Returns:

coeff – A list of co-efficients if the match is successful. An empty list if the match failed.

Return type:

List[Expr]

tvm_tirx.tirx.analysis.analysis.detect_clip_bound(expr, var_list)#

Detect if expression corresponds to clip bound of the vars

Parameters:
  • expr (Expr) – The expression to be matched.

  • var_list (List[tvm_tirx.ir.Var]) – A list of variables.

Returns:

coeff – concat([min_value[i], max_value[i]] for i, v in enumerate(var_list)) An empty list if the match failed.

Return type:

List[Expr]