slyubomirsky commented on code in PR #15689:
URL: https://github.com/apache/tvm/pull/15689#discussion_r1393369799
##########
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:
The annoying thing is that there is no (to my knowledge) `Set` in the FFI
classes, unless we use a `Map` with dummy values. The conversion is for
convenience in Python. I guess using a `Map` with dummy values would suffice
though.
--
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]