Lunderberg commented on code in PR #15689:
URL: https://github.com/apache/tvm/pull/15689#discussion_r1397544776
##########
python/tvm/relax/analysis/analysis.py:
##########
@@ -389,6 +389,29 @@ def udchain(dfb: DataflowBlock) -> Dict[Var, List[Var]]:
return _ffi_api.udchain(dfb) # type: ignore
+def liveness_analysis(func: Function) -> List[Set[Var]]:
+ """
+ Perform a liveness analysis on the given function, returning a set of
+ the variables live in the given program location.
+
+ Parameters
+ ----------
+ func: Function
+ The function to be analyzed
+
+ Returns
+ -------
+ ret: List[Set[Var]]
+ The set of live variables for each binding in the function.
+ The indexing is determined by the control flow graph, so
+ use `extract_cfg` and `get_binding_index` to find the index
+ for a given program location in the list.
+ """
+ live_lists = _ffi_api.LivenessAnalysis(func)
+ # convert the lists to sets
+ return [set(live_list) for live_list in live_lists]
Review Comment:
Definitely agreed on that lack. The convention I've seen elsewhere (e.g.
[`TIRVarsInStructInfo`](https://github.com/apache/tvm/blob/unity/include/tvm/relax/analysis.h#L269))
is to return a de-duplicated `Array` from the C++ API. If there's some
default ordering (e.g. first appearance in a Function), the
[`tvm::support::OrderedSet`](https://github.com/apache/tvm/blob/unity/src/support/ordered_set.h)
can be useful for the implementation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]