tvm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-tvm] zhiics commented on a change in pull request #5144: [Relay][VM] Memory planner (part 1)
Date Fri, 10 Apr 2020 23:54:22 GMT
zhiics commented on a change in pull request #5144: [Relay][VM] Memory planner (part 1)
URL: https://github.com/apache/incubator-tvm/pull/5144#discussion_r406983327
 
 

 ##########
 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:
   let here is actually the 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

Mime
View raw message