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


##########
src/tir/analysis/var_use_def_analysis.h:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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/src/tir/analysis/var_use_def_analyzer.h
+ * \brief Variable definition and usage analysis class.
+ */
+#ifndef TVM_TIR_ANALYSIS_VAR_USE_DEF_ANALYSIS_H_
+#define TVM_TIR_ANALYSIS_VAR_USE_DEF_ANALYSIS_H_
+
+#include <tvm/tir/analysis.h>
+
+#include <unordered_map>
+
+#include "../../runtime/thread_storage_scope.h"
+#include "../transforms/ir_utils.h"
+
+namespace tvm {
+namespace tir {
+
+/*!
+ * \brief Visitor class to perform use/def analysis, also delete unreferenced 
lets.
+ * \param defined_vars Variables that have been defined.
+ * \param visit_thread_extent Whether enters thread extent expressions or not.
+ * \sa UndefinedVars
+ */
+class VarUseDefAnalyzer : public StmtExprVisitor {
+ public:
+  explicit VarUseDefAnalyzer(const Array<Var>& defined_vars, bool 
visit_thread_extent = true);
+  // The fields are publically readible to
+  // be accessible to the users.
+  bool visit_thread_extent_{true};
+  Array<Var> undefined_;
+
+  std::unordered_map<const VarNode*, int> use_count_;

Review Comment:
   The `use_count_` and `def_count_` use `const VarNode*` as the map key, 
whereas `let_binding_` uses `Var`.  I know that they're used somewhat 
interchangeably throughout the codebase, but it seems odd to have different 
usage so clsoe together.  Is there a reason for the different usage, and if so, 
could we add a comment explaining why they were chosen?



##########
include/tvm/tir/analysis.h:
##########
@@ -30,6 +30,7 @@
 #include <tvm/tir/function.h>
 #include <tvm/tir/op_attr_types.h>
 #include <tvm/tir/stmt.h>
+#include <tvm/tir/stmt_functor.h>

Review Comment:
   Is this include file required, now that the visitor/mutator are in a 
separate header file?



##########
src/tir/analysis/var_use_def_analysis.h:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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/src/tir/analysis/var_use_def_analyzer.h
+ * \brief Variable definition and usage analysis class.
+ */
+#ifndef TVM_TIR_ANALYSIS_VAR_USE_DEF_ANALYSIS_H_
+#define TVM_TIR_ANALYSIS_VAR_USE_DEF_ANALYSIS_H_
+
+#include <tvm/tir/analysis.h>
+
+#include <unordered_map>
+
+#include "../../runtime/thread_storage_scope.h"
+#include "../transforms/ir_utils.h"

Review Comment:
   This would probably be a better place for the `stmt_functor.h` include file, 
rather than being included as part of `ir_utils.h`.



##########
src/tir/transforms/split_host_device.cc:
##########
@@ -104,44 +81,42 @@ class VarUseDefAnalysis : public StmtExprMutator {
       dyn_shmem_size_ = dyn_shmem_size_ * (op->dtype.bytes());
       use_dyn_shmem_ = true;
     }
-    return StmtExprMutator::VisitStmt_(op);
+    StmtVisitor::VisitStmt_(op);
   }
 
-  Stmt VisitStmt_(const AllocateConstNode* op) final {
-    this->HandleDef(op->buffer_var.get());
-    return StmtExprMutator::VisitStmt_(op);
-  }
+  // recording what thread axis have been visited.
+  std::unordered_set<const IterVarNode*> defined_thread;
+};
 
-  Stmt VisitStmt_(const StoreNode* op) final {
-    LOG(FATAL) << "Unexpected use of deprecated StoreNode.  Please use 
BufferStoreNode instead.";
-  }
+/*!
+ * \brief Mutator class to remove unrefenced let stmt/expressions.
+ * \param use_count The pre-computed variable to use count map.
+ */
+class UnreferencedLetRemover : public StmtExprMutator {

Review Comment:
   Thank you for making this change, and it really helps in the readability to 
have the analysis/mutation be separated out!



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