You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/04/10 23:15:16 UTC

[GitHub] [incubator-tvm] icemelon9 commented on a change in pull request #5144: [Relay][VM] Memory planner (part 1)

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
+
+@attr.s(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:
users@infra.apache.org


With regards,
Apache Git Services