tqchen commented on code in PR #14396:
URL: https://github.com/apache/tvm/pull/14396#discussion_r1147563037
##########
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:
this is the use side, let us update in the def side, then update. the use
side, which is safer. It will also allow us to only renew symbolic vars that
are defined within function scope, and report error for symbolic vars that are
not bound
This is something that is useful in general and we can make it as part of
analysis.
--
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]