[REFACTOR][IR] Delete class Bool and class Integer boxed-type wrappers#19636
Merged
spectrometerHBH merged 5 commits intoMay 29, 2026
Merged
Conversation
…tImm/const_true/const_false Bool(true) and Bool(false) in PrimExpr position add no information over IntImm(DataType::Bool(), 1) and IntImm(DataType::Bool(), 0) (which const_true() and const_false() produce). Integer(N) in PrimExpr position adds no information over IntImm(DataType::Int(32), N); both wrap the same IntImmNode. Replace throughout the 62-file IR, arith, relax, s_tir, tirx, topi, and target/cuda call sites.
…hedule and MetaSchedule Schedule trace attrs and MetaSchedule decision payloads boxed ints into Integer() to pass through ffi::Any. IntImm(DataType::Int(32), N) is the correct canonical form for integer constants in IR position; Integer() was a redundant wrapper. Replace across traced_schedule.cc, concrete_schedule, and ~15 MetaSchedule files. Also change MultiLevelTilingWideVector's vector_length_in_bits parameter from Integer to int64_t in both the header declaration and implementation, matching the underlying field type.
…ol callers - Change ffi::Array<Integer> to ffi::Array<int64_t> in topi headers (strided_slice, reduction, transform, nn, utils, nn/group_norm, nn/instance_norm, nn/layer_norm, nn/rms_norm) and corresponding sources; update internal usages (.IntValue(), .defined(), ->value, ->dtype) to plain int64_t arithmetic - Migrate ShardingNode::sharding_dim and CalculateConstantBytes/ CalculateWorkspaceBytes signatures from Integer to int64_t - Migrate codegen_c.h constants_byte_alignment_ field from Integer to int64_t - Replace Downcast<Integer/Bool> with Downcast<IntImm> in schedule primitives, metaschedule helpers, and misc transform passes - Convert remaining Integer/Bool local variables and function return types (clml codegen, make_packed_api, infer_layout_utils, etc.) to IntImm or plain int64_t - Update stale doc-comment "Type: Integer/Bool" annotations in function.h and tirx/function.h to "Type: IntImm" - Fix test files: nested_msg_test.cc (NestedMsg<IntImm>), ir_functor_test.cc, arith_simplify_test.cc
…r/expr.h Remove the Bool and Integer thin-wrapper classes (which were both subclasses of IntImm sharing IntImmNode) along with their TypeTraits<Integer> and TypeTraits<Bool> specializations. All call sites were migrated to IntImm in the preceding three commits. The canonical replacements are: - Integer(N) → IntImm(DataType::Int(32), N) - Bool(b) → IntImm(DataType::Bool(), b) - x.IntValue() → x->value - x operator bool → x->value != 0
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the codebase by replacing the usage of Integer and Bool classes with IntImm or primitive int64_t types across various TVM, Relax, and TOPI components. The review feedback is highly constructive, pointing out a redundant ternary operator in transform.h and suggesting the use of the more idiomatic const_true() helper instead of manually constructing boolean IntImm instances in several files where <tvm/tirx/op.h> is included.
…pply const_true cleanups
After migrating topi container signatures from Array<Integer>, the
strided_slice family lost two features the original Array<Integer>
parameters carried:
1. Nullable entries. begin/end accept None entries meaning "use
stride-direction default". The Array<int64_t> port silently
dropped the !defined() branches.
2. Index dtype propagation. begin[0]->dtype drove the index dtype
for IntImm/PrimExpr construction; hardcoding Int(64) widened
int32 callers.
Restore both features by porting begin/end to
ffi::Array<ffi::Optional<IntImm>> and strides to ffi::Array<IntImm>:
- include/tvm/topi/detail/strided_slice.h: ConvertToVec gets
Optional<IntImm>/IntImm params; reinstates the None branches
for begin and end.
- include/tvm/topi/transform.h: strided_slice / strided_slice_with_axes
/ StridedSliceOutputShape match the new types; index_dtype is
derived from begin[0]->dtype again; max_range uses max_value(dtype);
stride dtype from strides[i]->dtype.
- src/topi/transform.cc: static-path cast now produces
Array<Optional<IntImm>> for begin/end and Array<IntImm> for strides.
- include/tvm/topi/nn.h: the strided_slice caller in spatial_pad_to_batch
builds Array<Optional<IntImm>>/Array<IntImm> instead of Array<int64_t>.
axes remains Array<int64_t> on the C++ side (only host integers are
read). python/tvm/topi/transform.py drops the begin/end/strides
_unbox shim — the FFI now marshals Python ints and IntImm directly —
but keeps a small axes-only IntImm→int conversion for relax legalize
callers that produce IntImm-valued axes lists.
Also apply six mechanical cleanups from review feedback:
- include/tvm/topi/transform.h: remove redundant ternary (Int(64) ? Int(64))
- src/te/operation/create_primfunc.cc: IntImm(Bool(),1) → const_true()
- src/relax/analysis/struct_info_analysis.cc: same
- src/relax/ir/dataflow_matcher.cc: same
- src/relax/transform/adjust_matmul_order.cc: same
- src/relax/transform/fuse_tir.cc: same (no namespace qualifier needed,
already in tvm::tirx; relax-namespace sites use tirx::const_true())
Clang-format and ruff-format reformats from pre-commit included.
69c0900 to
8bb7fd6
Compare
Member
Author
|
@tvm-bot rerun |
spectrometerHBH
approved these changes
May 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
class Integer : public IntImmandclass Bool : public IntImmwere thinwrappers sharing
IntImmNodewith no separate node class and no FFIregistration. They existed to provide implicit int→Integer constructors and
a
.IntValue()/operator bool()accessor, but the same functionality isavailable directly through
IntImm.What this PR does
Migrates all call sites away from
Integer/Booland then deletes theclass definitions. The changes are split into four commits, each
independently buildable:
Commit 1 – [REFACTOR][TIR] Replace IR-position
Integer(N)/Bool(b)constructors with
IntImm(DataType::Int(32), N)/IntImm(DataType::Bool(), b)across ~62 source files (arith, relax analysis, s_tir schedule state, transform
passes, codegen).
Commit 2 – [REFACTOR][SCHEDULE] Migrate
ScheduleandMetaScheduletrace-boxing code:
Integer(N)attrs inTracedSchedule→IntImm(DataType::Int(32), N);ffi::Array<Integer>schedule-rule parameters →int64_t;Bool(b)attrs →IntImm(DataType::Bool(), b).Commit 3 – [REFACTOR][TOPI] Migrate topi container signatures
(
ffi::Array<Integer>→ffi::Array<int64_t>) and update all internalusages (
.IntValue()→ plain int64_t,.defined()→ removed,->value→ direct indexing). Also handles strayInteger/Boolvariables in clml codegen, make_packed_api, infer_layout_utils, and
relax distributed code.
Commit 4 – [REFACTOR][IR] Delete
class Bool,class Integer,TypeTraits<Bool>, andTypeTraits<Integer>frominclude/tvm/ir/expr.h.Canonical replacements
Integer(N)IntImm(DataType::Int(32), N)Bool(b)IntImm(DataType::Bool(), b)x.IntValue()x->valuexas boolx->value != 0ffi::Array<Integer>ffi::Array<int64_t>Testing
./cpptest)tests/python/s_tir/— 1251 passed (14 pre-existing failures unrelated to this change, all in TIR transform tests with annotation-mismatch errors)tests/python/relax/— passes (excluding pre-existing torch/torchvision import failures in frontend tests)