Lunderberg commented on code in PR #16305:
URL: https://github.com/apache/tvm/pull/16305#discussion_r1440555292


##########
src/relax/transform/update_param_struct_info.cc:
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file tvm/relax/transform/update_param_struct_info.cc
+ * \brief Mutate IRModule to accept new parameters
+ */
+
+#include <tvm/relax/expr.h>
+#include <tvm/relax/expr_functor.h>
+#include <tvm/relax/transform.h>
+
+#include <optional>
+#include <regex>
+#include <unordered_map>
+#include <vector>
+
+#include "utils.h"
+
+namespace tvm {
+namespace relax {
+
+namespace {
+class ParamStructInfoMutator : public ExprMutator {
+ public:
+  explicit ParamStructInfoMutator(TypedPackedFunc<Optional<StructInfo>(Var)> 
sinfo_func)
+      : sinfo_func_(sinfo_func) {}
+
+  using ExprMutator::VisitExpr_;
+  using ExprMutator::VisitVarDef_;
+
+  Var VisitVarDef_(const VarNode* op) override {
+    Var var = ExprMutator::VisitVarDef_(op);
+    if (!inside_expr_) {
+      if (auto new_sinfo = sinfo_func_(var)) {
+        return Var(var->vid, new_sinfo);
+      }
+    }
+    return var;
+  }
+
+  Expr VisitExpr_(const SeqExprNode* op) override {
+    bool cache = inside_expr_;
+    inside_expr_ = true;
+    auto ret = ExprMutator::VisitExpr_(op);
+    inside_expr_ = cache;
+    return ret;
+  }
+
+  TypedPackedFunc<Optional<StructInfo>(Var)> sinfo_func_;
+  bool inside_expr_{false};

Review Comment:
   Good point, it probably would have been better to name it as 
`inside_function_body_`.  It has been removed in the updated implementation.



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