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


##########
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:
   > You can probably just use that.
   
   Thanks, I did see that one, but (1). currently it doesn't seem to be 
declared in any header, and (2). the extra `mod` argument is not ergonomic for 
our use case here.
   
   > And it's odd to add this function in pattern_utils.h.
   
   I agree, I did this for consistency because we already have 
[InferType](https://github.com/apache/tvm/blob/main/src/relay/transforms/pattern_utils.h#L113-L121)
 right above from #13275.
   
   I think they should probably both be moved to either `pass_utils.h` or a new 
`transform_utils.h`.
   
   Regardless, I also just found 
[this](https://github.com/apache/tvm/blob/main/src/relay/backend/contrib/constant_transforms.h#L36-L43).
 It's in `contrib`, but if we are okay with using it I'll go ahead.
   
   Let me know what you think, I'll update the PR accordingly:).
   



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