Skip to content

[REFACTOR][IR] Unify constants with GenericConst and shared StringImm - #20386

Merged
tqchen merged 7 commits into
apache:mainfrom
tqchen:unify-ir-constants
Sep 18, 2026
Merged

tqchen merged 7 commits into
apache:mainfrom
tqchen:unify-ir-constants

Conversation

@tqchen

@tqchen tqchen commented Sep 18, 2026

Copy link
Copy Markdown
Member

Introduce a shared Constant family with IntImm, FloatImm, StringImm, and GenericConst. StringImm carries shared StringType; GenericConst stores tensor and dtype payloads separately from expression types, replacing Relax-specific Constant and DataTypeImm nodes.

Migrate frontends, visitors, structural operations, printers, and consumers to the shared nodes. Preserve existing string-literal argument passing as runtime String objects in Relax and C strings in PrimFunc. Group visitor and mutator hook declarations with non-prim nodes before prim nodes, preserving relative order within each group.

Introduce a shared Constant family with dedicated numeric and string literals. Give StringImm a shared StringType and represent tensor and dtype payloads with GenericConst independently of their expression types.

Migrate frontends, visitors, structural operations, printers, and consumers to the shared nodes. Preserve runtime String objects in Relax and lower PrimFunc strings as C strings at the ABI and codegen boundaries.
Convert temporary C-string views into owned FFI return values and propagate conversion errors through the packed error path. Emit the typed FFI conversion in C hosts and describe StringType parameters as C-string pointers in LLVM debug information.
Keep allocation storage scopes as Expr values when constructing free_nd calls so shared StringImm scopes retain their StringType.
Keep shared StringImm literals in existing CString argument packing and retain Relax String-object constants. Limit codegen adjustments to mechanical node and Expr migrations, preserving existing packed parameter and return lowering.
Shared StringImm values no longer enter the primitive analyzer. Substitute their SSA bindings before numerical simplification so string literal arguments remain constants through host and device lowering.
Keep function-call behavior on GenericConst so primitive constant operands remain non-callable. Use a non-string invalid input in the existing Python-call fixture to match shared StringImm conversion.
@tqchen
tqchen merged commit 5398c27 into apache:main Sep 18, 2026
8 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.

3 participants