Skip to content

[REFACTOR][TIRX] Add IntImm common scalar ctor and streamline MakeConst#19797

Merged
tqchen merged 1 commit into
apache:mainfrom
tqchen:tvm-add-intimm-common-scalar-constructors-and-migrate-uses
Jun 17, 2026
Merged

[REFACTOR][TIRX] Add IntImm common scalar ctor and streamline MakeConst#19797
tqchen merged 1 commit into
apache:mainfrom
tqchen:tvm-add-intimm-common-scalar-constructors-and-migrate-uses

Conversation

@tqchen

@tqchen tqchen commented Jun 16, 2026

Copy link
Copy Markdown
Member

Summary

Common bool, int32, and int64 scalar constants show up throughout TIRX and related lowering code. Named constructors make these call sites easier to read than repeated DataType spelling, and avoid routing obvious scalar constants through the generic MakeConst helper.

Usage guideline

Prefer direct IntImm or FloatImm construction when dtype is known to be scalar integer or floating point. This makes the compiled code more compact and efficient. Keep MakeConst for generic overload cases where dtype can be integer, floating point, or vector-valued and the caller needs its scalar/vector dispatch.

This PR establishes the scalar-constant construction policy:

  • Prefer IntImm::Bool, IntImm::Int32, and IntImm::Int64 for common known scalar bool, int32, and int64 constants.
  • Prefer direct IntImm or FloatImm construction when dtype is known to be scalar integer or floating point.
  • Keep MakeConst for generic overload cases where dtype can be integer, floating point, or vector-valued and the caller needs its scalar/vector dispatch.
  • Phase out make_zero in favor of explicit scalar constructors, or ConstHandle(0) for null handles.

Changes

  • Add IntImm::Bool, IntImm::Int32, and IntImm::Int64 helpers.
  • Rename make_const to MakeConst and document it as the generic/vector construction helper.
  • Migrate deterministic scalar constant construction to the clearer APIs while keeping generic and vector-aware paths on MakeConst.
  • Remove make_zero, const_true, const_false, and the unused tirx.const_true registry entry.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the codebase to use direct IntImm and FloatImm constructors (such as IntImm::Int32, IntImm::Int64, and IntImm::Bool) instead of the generic make_const or make_zero helpers when the data type is statically known to be a scalar. This change improves compilation efficiency and code compactness. The review feedback identifies several remaining instances across the codebase—specifically in loop vectorization, interval set operations, affine map iterations, double buffer injection, and FFI binding—where make_const is still being used for scalar types, and suggests replacing them with direct IntImm calls to complete the refactoring consistently.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/tirx/transform/vectorize_loop.cc Outdated
Comment thread src/tirx/transform/vectorize_loop.cc Outdated
Comment thread src/arith/int_set.cc Outdated
Comment thread src/arith/int_set.cc Outdated
Comment thread src/arith/iter_affine_map.cc Outdated
Comment thread src/arith/iter_affine_map.cc Outdated
Comment thread src/arith/iter_affine_map.cc Outdated
Comment thread src/s_tir/transform/inject_double_buffer.cc Outdated
Comment thread src/tirx/transform/tvm_ffi_binder.cc Outdated
Comment thread src/tirx/transform/tvm_ffi_binder.cc Outdated
@tqchen tqchen changed the title [REFACTOR][TIR] Add IntImm common scalar constructors [REFACTOR][TIRX] Add IntImm common scalar constructors Jun 16, 2026
@tqchen tqchen force-pushed the tvm-add-intimm-common-scalar-constructors-and-migrate-uses branch 3 times, most recently from 2cc64e5 to ddfe920 Compare June 16, 2026 14:06
@tqchen tqchen changed the title [REFACTOR][TIRX] Add IntImm common scalar constructors [REFACTOR][TIRX] Add IntImm common scalar ctor and streamline MakeConst Jun 16, 2026
@tqchen tqchen force-pushed the tvm-add-intimm-common-scalar-constructors-and-migrate-uses branch 3 times, most recently from bdc150c to 7ab7b0a Compare June 16, 2026 17:31
Common bool, int32, and int64 scalar constants show up throughout TIRX and related lowering code, and named constructors make these call sites easier to read than repeated DataType spelling.

This PR establishes the scalar-constant construction policy and renames make_const to MakeConst to match the public helper naming style.

- Prefer IntImm::Bool, IntImm::Int32, and IntImm::Int64 for common known scalar bool, int32, and int64 constants.

- Prefer direct IntImm or FloatImm construction when dtype is known to be scalar integer or floating point. This makes the compiled code more compact and efficient. Keep MakeConst for generic overload cases where dtype can be integer, floating point, or vector-valued and the caller needs its scalar/vector dispatch.

- Phase out make_zero in favor of explicit scalar constructors, or ConstHandle(0) for null handles.
@tqchen tqchen force-pushed the tvm-add-intimm-common-scalar-constructors-and-migrate-uses branch from 7ab7b0a to 9958ebe Compare June 16, 2026 19:36
@tqchen

tqchen commented Jun 16, 2026

Copy link
Copy Markdown
Member Author

@tvm-bot rerun

MasterJH5574 pushed a commit to MasterJH5574/tvm that referenced this pull request Jun 16, 2026
…st (apache#19797)

Common bool, int32, and int64 scalar constants show up throughout TIRX and related lowering code, and named constructors make these call sites easier to read than repeated DataType spelling.

This PR establishes the scalar-constant construction policy and renames make_const to MakeConst to match the public helper naming style.

- Prefer IntImm::Bool, IntImm::Int32, and IntImm::Int64 for common known scalar bool, int32, and int64 constants.

- Prefer direct IntImm or FloatImm construction when dtype is known to be scalar integer or floating point. This makes the compiled code more compact and efficient. Keep MakeConst for generic overload cases where dtype can be integer, floating point, or vector-valued and the caller needs its scalar/vector dispatch.

- Phase out make_zero in favor of explicit scalar constructors, or ConstHandle(0) for null handles.
@tqchen tqchen merged commit ad58d3e into apache:main Jun 17, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants