This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new aaa499ef23 [CLEANUP][IR] Remove redundant functor helpers and CLZ
float handling (#20379)
aaa499ef23 is described below
commit aaa499ef236e4965e0d64b49d26ce21ee4a66dde
Author: Tianqi Chen <[email protected]>
AuthorDate: Thu Sep 17 12:47:23 2026 -0400
[CLEANUP][IR] Remove redundant functor helpers and CLZ float handling
(#20379)
TIRX expression dispatch now uses the shared expression table directly
while retaining its dialect entry point and protected extension hooks.
Schedule transformations call `Array::Map` directly, allowing removal of
the private forwarding helper and its unused includes.
Remove the unused primitive optional-equality helper and the
floating-point promotion branch from integer CLZ construction.
---
include/tvm/tirx/expr_functor.h | 16 +--------
src/ir/prim/deep_equal.cc | 7 ----
src/ir/prim/op.cc | 9 -----
src/relax/transform/fuse_tir.cc | 2 --
.../schedule/primitive/loop_transformation.cc | 4 +--
src/s_tir/schedule/transform.cc | 2 +-
src/s_tir/schedule/transform.h | 1 -
src/s_tir/transform/lower_match_buffer.cc | 1 -
src/s_tir/transform/renew_defs.cc | 2 --
src/te/operation/create_primfunc.cc | 1 -
src/tirx/analysis/verify_tirx_well_formed.cc | 1 -
src/tirx/analysis/verify_well_formed.cc | 1 -
src/tirx/ir/functor_common.h | 39 ----------------------
src/tirx/ir/specialize.cc | 1 -
src/tirx/ir/stmt.cc | 1 -
src/tirx/ir/stmt_functor.cc | 1 -
src/tirx/transform/tile_primitive_dispatch.cc | 1 -
17 files changed, 4 insertions(+), 86 deletions(-)
diff --git a/include/tvm/tirx/expr_functor.h b/include/tvm/tirx/expr_functor.h
index 7b09c6d73a..602376b721 100644
--- a/include/tvm/tirx/expr_functor.h
+++ b/include/tvm/tirx/expr_functor.h
@@ -26,9 +26,6 @@
#define TVM_TIR_EXPR_FUNCTOR_H_
#include <tvm/ir/expr_functor.h>
-#include <tvm/tirx/buffer_region.h>
-
-#include <utility>
namespace tvm {
namespace tirx {
@@ -55,7 +52,7 @@ class ExprFunctor<R(const Expr&, Args...)> : public
tvm::ExprFunctor<R(const Exp
using Parent::Dispatch_;
/*! \brief Construct a functor with the inherited expression hooks. */
- ExprFunctor() : Parent(GlobalVTable()) {}
+ ExprFunctor() = default;
/*! \brief Destroy through the dialect functor base. */
virtual ~ExprFunctor() = default;
@@ -68,17 +65,6 @@ class ExprFunctor<R(const Expr&, Args...)> : public
tvm::ExprFunctor<R(const Exp
/*! \brief Initialize the inherited expression dispatch. */
static void InitVTable(VTable* vtable) { Parent::InitVTable(vtable); }
-
- private:
- static const VTable* GlobalVTable() {
- static const VTable table = [] {
- VTable table;
- InitVTable(&table);
- table.Finalize();
- return table;
- }();
- return &table;
- }
};
} // namespace tirx
diff --git a/src/ir/prim/deep_equal.cc b/src/ir/prim/deep_equal.cc
index 0fe7de4bf7..39819dc9f2 100644
--- a/src/ir/prim/deep_equal.cc
+++ b/src/ir/prim/deep_equal.cc
@@ -117,13 +117,6 @@ class ExprDeepEqualChecker : private
tvm::ExprFunctor<bool(const Expr&, const Pr
return true;
}
- bool OptionalDeepEqual(const ffi::Optional<PrimExpr>& lhs, const
ffi::Optional<PrimExpr>& rhs) {
- if (lhs.same_as(rhs)) return true;
- if (!lhs.has_value() && rhs.has_value()) return false;
- if (lhs.has_value() && !rhs.has_value()) return false;
- return Dispatch(*lhs, *rhs);
- }
-
bool Dispatch_(const VarNode* plhs, const PrimExpr& rhs) final {
// for var, we require pointer equality
return plhs == rhs.get();
diff --git a/src/ir/prim/op.cc b/src/ir/prim/op.cc
index 0b1692bef7..3c4c8e1096 100644
--- a/src/ir/prim/op.cc
+++ b/src/ir/prim/op.cc
@@ -752,15 +752,6 @@ PrimExpr log2(PrimExpr x, Span span) {
PrimExpr prim::clz(PrimExpr x, Span span) {
PrimType x_ty = x.ty();
- if (x_ty.MatchesElementType(DLDataTypeCode::kDLBfloat, 16)) {
- PrimType f32_ty = x_ty.IsScalableVector() ?
PrimType::ScalableVector(DLDataTypeCode::kDLFloat,
- 32,
x_ty.VScaleFactor())
- : PrimType::Float(32,
x_ty.lanes());
- PrimExpr x_fp32 = prim::Cast(f32_ty, x, span);
- PrimExpr result_fp32 =
- Call(f32_ty, prim::builtin::clz(), {x_fp32}, {}, {},
span).as_or_throw<PrimExpr>();
- return prim::Cast(x_ty, result_fp32, span);
- }
return Call(x_ty, prim::builtin::clz(), {x}, {}, {},
span).as_or_throw<PrimExpr>();
}
diff --git a/src/relax/transform/fuse_tir.cc b/src/relax/transform/fuse_tir.cc
index 859512a11a..6b9eabe198 100644
--- a/src/relax/transform/fuse_tir.cc
+++ b/src/relax/transform/fuse_tir.cc
@@ -31,8 +31,6 @@
#include <unordered_map>
#include <unordered_set>
-#include "../../tirx/ir/functor_common.h"
-
namespace tvm {
namespace tirx {
using namespace tvm::prim;
diff --git a/src/s_tir/schedule/primitive/loop_transformation.cc
b/src/s_tir/schedule/primitive/loop_transformation.cc
index 91e165d54e..a7f9cbbec4 100644
--- a/src/s_tir/schedule/primitive/loop_transformation.cc
+++ b/src/s_tir/schedule/primitive/loop_transformation.cc
@@ -552,7 +552,7 @@ ffi::Array<TensorRegion> MutateBufferRegion(
ffi::Map<ffi::String, Range> index_range_map, ffi::Array<TensorRegion>
region_arr) {
// Update the region with new Ranges and return new TensorRegion
ffi::Array<TensorRegion> new_region_arr =
- MutateArray(region_arr, [&buffer_indices_map, &index_range_map](const
TensorRegion& region) {
+ region_arr.Map([&buffer_indices_map, &index_range_map](const
TensorRegion& region) {
TensorRegion new_region = region;
auto it =
buffer_indices_map.find(new_region->source.as_or_throw<tvm::tirx::BufferVar>().name());
@@ -595,7 +595,7 @@ class BlockMutator : public StmtExprMutator {
inner_iter_var_index = -1;
// As we are working on cloned block, we need to create new instances of
iter_var
ffi::Array<IterVar> new_iter_vars =
- MutateArray(new_block->iter_vars, [this, &iter_var_](const IterVar&
iter) {
+ new_block->iter_vars.Map([this, &iter_var_](const IterVar& iter) {
auto dtype = iter->var.ty();
// Create new Var instance for each IterVar
Var new_var = Var(iter->var->name, iter->var.ty());
diff --git a/src/s_tir/schedule/transform.cc b/src/s_tir/schedule/transform.cc
index 8016ff3f16..c962e1f0f8 100644
--- a/src/s_tir/schedule/transform.cc
+++ b/src/s_tir/schedule/transform.cc
@@ -179,7 +179,7 @@ UnchangedOr<Stmt> ReplaceBufferMutator::Mutate_(const
SBlockNode* block, Inplace
return this->VisitMatchBufferRegion(match_buffer);
};
auto f_mutate_read_write_region = [this](const TensorRegion& buffer_region) {
- auto region = MutateArray(buffer_region->region, [this](const Range&
range) {
+ auto region = buffer_region->region.Map([this](const Range& range) {
auto min_result = Mutate(range->min, InplaceMode::kDisallow);
bool min_unchanged = min_result.UnchangedOrSameAs(range->min);
PrimExpr min = std::move(min_result).ValueOrUnchanged(range->min);
diff --git a/src/s_tir/schedule/transform.h b/src/s_tir/schedule/transform.h
index 8e0cd2098a..2392937dd1 100644
--- a/src/s_tir/schedule/transform.h
+++ b/src/s_tir/schedule/transform.h
@@ -27,7 +27,6 @@
#include <unordered_map>
#include <utility>
-#include "../../tirx/ir/functor_common.h"
#include "../../tirx/ir/ir_mutator_with_analyzer.h"
namespace tvm {
diff --git a/src/s_tir/transform/lower_match_buffer.cc
b/src/s_tir/transform/lower_match_buffer.cc
index 61196b2b1d..eecfae6c36 100644
--- a/src/s_tir/transform/lower_match_buffer.cc
+++ b/src/s_tir/transform/lower_match_buffer.cc
@@ -32,7 +32,6 @@
#include <tvm/tirx/op.h>
#include <tvm/tirx/stmt_functor.h>
-#include "../../tirx/ir/functor_common.h"
#include "../../tirx/transform/ir_utils.h"
namespace tvm {
diff --git a/src/s_tir/transform/renew_defs.cc
b/src/s_tir/transform/renew_defs.cc
index 9ddc21bdb9..9740975e11 100644
--- a/src/s_tir/transform/renew_defs.cc
+++ b/src/s_tir/transform/renew_defs.cc
@@ -28,8 +28,6 @@
#include <tvm/s_tir/transform.h>
#include <tvm/tirx/stmt_functor.h>
-#include "../../tirx/ir/functor_common.h"
-
namespace tvm {
namespace s_tir {
using namespace tvm::tirx;
diff --git a/src/te/operation/create_primfunc.cc
b/src/te/operation/create_primfunc.cc
index e5cf5eca5e..67532c035e 100644
--- a/src/te/operation/create_primfunc.cc
+++ b/src/te/operation/create_primfunc.cc
@@ -41,7 +41,6 @@
#include <vector>
#include "../../tirx/ir/data_type_rewriter.h"
-#include "../../tirx/ir/functor_common.h"
#include "graph.h"
namespace tvm {
diff --git a/src/tirx/analysis/verify_tirx_well_formed.cc
b/src/tirx/analysis/verify_tirx_well_formed.cc
index 1fab6449cd..66adcebb0b 100644
--- a/src/tirx/analysis/verify_tirx_well_formed.cc
+++ b/src/tirx/analysis/verify_tirx_well_formed.cc
@@ -37,7 +37,6 @@
#include <tuple>
#include <variant>
-#include "../ir/functor_common.h"
#include "../ir/tir_visitor_with_path.h"
#include "tvm/ir/module.h"
diff --git a/src/tirx/analysis/verify_well_formed.cc
b/src/tirx/analysis/verify_well_formed.cc
index 48a2d2d897..0123c463b6 100644
--- a/src/tirx/analysis/verify_well_formed.cc
+++ b/src/tirx/analysis/verify_well_formed.cc
@@ -33,7 +33,6 @@
#include <tuple>
#include <variant>
-#include "../ir/functor_common.h"
#include "../ir/tir_visitor_with_path.h"
#include "tvm/ir/module.h"
diff --git a/src/tirx/ir/functor_common.h b/src/tirx/ir/functor_common.h
deleted file mode 100644
index e2fad07d67..0000000000
--- a/src/tirx/ir/functor_common.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.
- */
-#include <tvm/ffi/container/array.h>
-
-/*!
- * \file tirx/ir/functor_common.h
- * \brief Common utils for implementing functors
- */
-#ifndef TVM_TIR_IR_FUNCTOR_COMMON_H_
-#define TVM_TIR_IR_FUNCTOR_COMMON_H_
-
-namespace tvm {
-class PrimExpr;
-namespace tirx {
-
-template <typename T, typename F>
-inline ffi::Array<T> MutateArray(ffi::Array<T> arr, F fmutate) {
- return arr.Map(fmutate);
-}
-
-} // namespace tirx
-} // namespace tvm
-#endif // TVM_TIR_IR_FUNCTOR_COMMON_H_
diff --git a/src/tirx/ir/specialize.cc b/src/tirx/ir/specialize.cc
index 1455517378..899b32a3a0 100644
--- a/src/tirx/ir/specialize.cc
+++ b/src/tirx/ir/specialize.cc
@@ -37,7 +37,6 @@
#include <unordered_set>
#include "../transform/ir_utils.h"
-#include "functor_common.h"
namespace tvm {
namespace tirx {
diff --git a/src/tirx/ir/stmt.cc b/src/tirx/ir/stmt.cc
index 03c80413ff..1699a8b686 100644
--- a/src/tirx/ir/stmt.cc
+++ b/src/tirx/ir/stmt.cc
@@ -37,7 +37,6 @@
#include <vector>
#include "buffer_common.h"
-#include "functor_common.h"
#include "seq_stmt_mutate.h"
namespace tvm {
diff --git a/src/tirx/ir/stmt_functor.cc b/src/tirx/ir/stmt_functor.cc
index 3bce83fe86..a0a1fc823c 100644
--- a/src/tirx/ir/stmt_functor.cc
+++ b/src/tirx/ir/stmt_functor.cc
@@ -34,7 +34,6 @@
#include <utility>
#include "data_type_rewriter.h"
-#include "functor_common.h"
#include "seq_stmt_mutate.h"
namespace tvm {
diff --git a/src/tirx/transform/tile_primitive_dispatch.cc
b/src/tirx/transform/tile_primitive_dispatch.cc
index 18e624e2f1..a272c2fb24 100644
--- a/src/tirx/transform/tile_primitive_dispatch.cc
+++ b/src/tirx/transform/tile_primitive_dispatch.cc
@@ -45,7 +45,6 @@
#include <vector>
#include "../analysis/filter_canonical.h"
-#include "../ir/functor_common.h"
#include "../ir/tir_visitor_with_path.h"
namespace tvm {