masahi commented on code in PR #13343:
URL: https://github.com/apache/tvm/pull/13343#discussion_r1019638394


##########
src/relay/transforms/pattern_utils.h:
##########
@@ -120,6 +120,21 @@ inline Expr InferType(const Expr& expr) {
   }
 }
 
+/*!
+ * \brief Try to apply constant folding over expr:
+ *
+ * Do constant_fold over each node in expr
+ *
+ * \param expr The IR expression
+ * \return resulting expr
+ */
+inline Expr FoldConstantExpr(const Expr& expr) {
+  IRModule const_mod = IRModule::FromExpr(expr);
+  const_mod = transform::FoldConstant()(const_mod);
+  GlobalVar const_main = const_mod->GetGlobalVar("main");
+  return Downcast<Function>(const_mod->functions[const_main])->body;
+}

Review Comment:
   Okay how about this:
   
   * Introduce `fold_constant.h` and declare `FoldConstantExpr(const Expr& 
expr)` and `FoldConstantExpr(const Expr& expr, const IRModule& mod, bool 
fold_qnn)`.
   * Implement the former one in terms of the latter.
   * Replace all duplicated definition of `FoldConstantExpr` with these ones.



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