Biubiubiu12 commented on code in PR #15274:
URL: https://github.com/apache/tvm/pull/15274#discussion_r1271697422


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& 
loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& 
block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* 
block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const 
StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* 
outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, 
block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, 
/*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* 
outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {

Review Comment:
   No, it is to ensure that `in_lca` is reinitialized to false after traversing 
lca, preventing `VisitStmt_(const BlockNode* block)` from processing the ir 
behind lca.



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