icemelon9 commented on a change in pull request #5144: [Relay][VM] Memory planner (part 1) URL: https://github.com/apache/incubator-tvm/pull/5144#discussion_r406963966
########## File path: python/tvm/relay/def_use.py ########## @@ -0,0 +1,42 @@ +from . import expr +from .expr_functor import ExprVisitor +from .analysis import free_vars + +import attr +from typing import List, Dict + [email protected](auto_attribs=True) +class DefUse: + defn: expr.Var + uses: List[expr.Expr] + +class DefUseAnalysis(ExprVisitor): + def __init__(self): + super().__init__() + self.results: Dict[expr.Var, DefUse] = {} + + def visit_function(self, func): + for param in func.params: + self.results[param] = DefUse(param, []) + super().visit_function(func) + + def visit_let(self, let): + while isinstance(let, expr.Let): + du = DefUse(let.var, []) + self.results[let.var] = du + # Find all variables used in RHS. + self.visit(let.value) + used_vars = free_vars(let.value) + for uvar in used_vars: + self.results[uvar].uses.append(let.value) + let = let.body + + # Find all variables used in body. + used_vars = free_vars(let) Review comment: Should this be `free_vars(let.body)`? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
