Hzfengsy commented on code in PR #14396:
URL: https://github.com/apache/tvm/pull/14396#discussion_r1147589997


##########
src/relax/transform/fuse_ops.cc:
##########
@@ -344,6 +345,42 @@ class GraphCreator : public ExprVisitor {
   std::unordered_set<IndexedForwardGraph::Node*> initialized_nodes_;
 };
 
+/*!
+ * \brief Renew the definition of symbolic vars in Relax.
+ * \details This mutator is used to prevent the same symbolic var from being 
used in different
+ *          functions, which is malformed.
+ */
+class SymbolicVarRenewMutator : public ExprMutator, tir::ExprMutator {
+ public:
+  static Function Renew(const Function& function) {
+    SymbolicVarRenewMutator mutator;
+    return Downcast<Function>(mutator.VisitExpr(function));
+  }
+
+ private:
+  SymbolicVarRenewMutator() = default;
+  using relax::ExprMutator::VisitExpr;
+  using relax::ExprMutator::VisitExpr_;
+  using tir::ExprMutator::VisitExpr_;
+
+  PrimExpr VisitPrimExpr(const PrimExpr& expr) final { return 
tir::ExprMutator::VisitExpr(expr); }
+
+  PrimExpr VisitExpr_(const tir::VarNode* op) final {

Review Comment:
   Thanks TQ, I agree that your approach is safer. However, in this particular 
case, I think both ways are the same. I would leave a TODO here for further 
updates.
   
   BTW, there is not an easy/formal way to visit symbolic var at def side, we 
may add a method to the base visitor/mutator later.



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