[REFACTOR][IR] Unify constants with GenericConst and shared StringImm - #20386
Merged
Merged
Conversation
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.
tlopex
approved these changes
Sep 18, 2026
spectrometerHBH
approved these changes
Sep 18, 2026
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.
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.
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.