slyubomirsky commented on code in PR #15689:
URL: https://github.com/apache/tvm/pull/15689#discussion_r1408647611


##########
include/tvm/relax/analysis.h:
##########
@@ -404,6 +404,18 @@ TVM_DLL Map<Var, Array<Var>> DataflowBlockUseDef(const 
DataflowBlock& dfb);
  */
 std::pair<Map<Var, Array<Var>>, Array<Var>> FunctionUseDef(const Function& fn);
 
+/*!
+ * \brief Perform a liveness analysis on the function, indicating which 
variables
+ * are live at which location in the function.
+ *
+ * \param fn The function to be analyzed.
+ * \return An array of arrays of live variables per binding in the function.
+ *   The array is indexed based on the corresponding control flow graph,
+ *   so use `ExtractCFG` and `GetBindingIndex` to match locations in `fn`
+ *   to indices in the result.
+ */
+Array<Array<Var>> LivenessAnalysis(const Function& fn);

Review Comment:
   I've looked into this and what's tricky is dealing with cases like `SeqExpr` 
body values and `If` conditions and merge/split points. The body does not have 
a var associated with it and in the case of `If`s, there is more than one CFG 
entry associated with one binding. `Var` alone would not be a good key, which 
is why I had the indices in the first place. We could use a `CFGKey` object 
that contains this auxiliary info or otherwise keep a data structure around for 
the reverse mapping, potentially.



-- 
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]

Reply via email to