Skip to content

[REFACTOR][NODE] Remove node redirect headers#18829

Open
tqchen wants to merge 9 commits intoapache:mainfrom
tqchen:node-namespace-cleanup
Open

[REFACTOR][NODE] Remove node redirect headers#18829
tqchen wants to merge 9 commits intoapache:mainfrom
tqchen:node-namespace-cleanup

Conversation

@tqchen
Copy link
Member

@tqchen tqchen commented Feb 26, 2026

This PR begins the cleanup of the include/tvm/node/

This PR removes the pure redirect headers from include/tvm/node/ (node.h,
reflection.h) and moves thin wrappers (serialization, structural_equal,
structural_hash) to include/tvm/ir/. Downstream code should use ffi::
directly for core types.

Main changes:

- Delete include/tvm/node/node.h (pure redirect) — update 24 includers
- Delete include/tvm/node/reflection.h (0 includers, unused declaration)
- Move serialization.h/cc, structural_equal.h/cc, structural_hash.h/cc
  to include/tvm/ir/ and src/ir/ — leave forwarding headers at old paths
- Extend include/tvm/runtime/object.h to export Object, ObjectPtrEqual,
  ObjectPtrHash to tvm:: namespace (previously via node.h)
- Add explicit includes for node/cast.h, node/repr_printer.h,
  node/script_printer.h to ir/expr.h (previously transitive via node.h)
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @tqchen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the internal header organization by streamlining the tvm/node/ namespace. It removes redundant aggregation headers and relocates core functionalities like serialization and structural comparison to the tvm/ir/ namespace, where they are more appropriately situated. This change improves modularity and clarity within the codebase, while maintaining backward compatibility through forwarding headers. Additionally, essential object-related types are now directly exposed in the tvm:: namespace for easier access.

Highlights

  • Namespace Cleanup: The include/tvm/node/ namespace has been cleaned up by removing pure redirect headers and moving thin wrapper functionalities to the ir/ namespace.
  • Header Removal: The aggregation header node/node.h and the unused node/reflection.h have been removed.
  • Wrapper Relocation: Functionalities related to serialization, structural equality, and structural hashing have been moved from tvm/node/ to tvm/ir/. Corresponding source files in src/node/ were also moved to src/ir/.
  • Forwarding Headers: Forwarding headers have been left in the original tvm/node/ locations for serialization.h, structural_equal.h, and structural_hash.h to maintain downstream compatibility.
  • Namespace Export: Key Object related types (Object, ObjectPtrEqual, ObjectPtrHash) are now explicitly exported to the tvm:: namespace within runtime/object.h.
  • Include Adjustments: Numerous files across the codebase have had their include paths updated to reflect the header relocations and removals, ensuring correct dependencies.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • include/tvm/ir/attrs.h
    • Updated includes for structural equality and hash headers to the new ir/ location.
  • include/tvm/ir/env_func.h
    • Replaced include of tvm/node/node.h with tvm/runtime/object.h.
  • include/tvm/ir/expr.h
    • Replaced include of tvm/node/node.h with more specific tvm/node/cast.h, tvm/node/repr_printer.h, and tvm/node/script_printer.h.
  • include/tvm/ir/instrument.h
    • Replaced include of tvm/node/node.h with tvm/runtime/object.h.
  • include/tvm/ir/module.h
    • Added include for tvm/node/script_printer.h.
  • include/tvm/ir/serialization.h
    • Added as a new file, containing the serialization utility functions previously defined in tvm/node/serialization.h.
  • include/tvm/ir/source_map.h
    • Removed include of tvm/node/node.h and added tvm/ffi/container/array.h.
  • include/tvm/ir/structural_equal.h
    • Added as a new file, containing the structural equality comparison logic previously defined in tvm/node/structural_equal.h.
  • include/tvm/ir/structural_hash.h
    • Added as a new file, containing the structural hash class previously defined in tvm/node/structural_hash.h.
  • include/tvm/node/node.h
    • Removed the file, as it was a pure aggregation header.
  • include/tvm/node/serialization.h
    • Modified to be a forwarding header to tvm/ir/serialization.h.
  • include/tvm/node/structural_equal.h
    • Modified to be a forwarding header to tvm/ir/structural_equal.h.
  • include/tvm/node/structural_hash.h
    • Modified to be a forwarding header to tvm/ir/structural_hash.h.
  • include/tvm/relax/exec_builder.h
    • Updated includes for structural equality and hash headers to the new ir/ location.
  • include/tvm/relax/expr.h
    • Removed include of tvm/node/node.h.
  • include/tvm/relax/struct_info.h
    • Replaced include of tvm/node/node.h with tvm/node/cast.h and tvm/runtime/object.h.
  • include/tvm/runtime/object.h
    • Exported Object, ObjectPtrEqual, and ObjectPtrHash to the tvm:: namespace.
  • include/tvm/s_tir/meta_schedule/arg_info.h
    • Removed include of tvm/node/node.h.
  • include/tvm/script/ir_builder/base.h
    • Replaced include of tvm/node/node.h with tvm/node/cast.h.
  • include/tvm/script/ir_builder/ir/frame.h
    • Removed include of tvm/node/node.h.
  • include/tvm/script/ir_builder/ir/ir.h
    • Removed include of tvm/node/node.h.
  • include/tvm/script/printer/doc.h
    • Removed include of tvm/node/node.h.
  • include/tvm/script/printer/ir_docsifier.h
    • Replaced include of tvm/node/node.h with tvm/node/cast.h.
  • include/tvm/script/printer/ir_docsifier_functor.h
    • Replaced include of tvm/node/node.h with tvm/runtime/object.h.
  • include/tvm/target/tag.h
    • Removed include of tvm/node/node.h.
  • include/tvm/target/target.h
    • Replaced include of tvm/node/node.h with tvm/node/cast.h.
  • include/tvm/target/target_kind.h
    • Replaced include of tvm/node/node.h with tvm/runtime/object.h.
  • include/tvm/tir/expr.h
    • Removed include of tvm/node/node.h.
  • include/tvm/tir/function.h
    • Added include for tvm/node/script_printer.h.
  • include/tvm/tir/stmt.h
    • Added include for tvm/node/script_printer.h.
  • include/tvm/tir/var.h
    • Removed include of tvm/node/node.h.
  • src/ir/module.cc
    • Updated include for structural equality to the new ir/ location.
  • src/ir/serialization.cc
    • Moved from src/node/serialization.cc.
  • src/ir/structural_equal.cc
    • Moved from src/node/structural_equal.cc and updated includes.
  • src/ir/structural_hash.cc
    • Moved from src/node/structural_hash.cc and updated includes.
  • src/ir/transform.cc
    • Updated include for structural hash to the new ir/ location.
  • src/node/reflection.cc
    • Removed include of tvm/node/node.h.
  • src/node/script_printer.cc
    • Added include for tvm/node/cast.h.
  • src/relax/backend/adreno/annotate_custom_storage.cc
    • Updated include for serialization to the new ir/ location.
  • src/relax/backend/adreno/fold_vdevice_scope_change.cc
    • Updated include for serialization to the new ir/ location.
  • src/relax/ir/dataflow_block_rewriter.cc
    • Updated include for structural equality to the new ir/ location.
  • src/relax/ir/dataflow_expr_rewriter.cc
    • Updated include for structural equality to the new ir/ location.
  • src/relax/ir/dataflow_matcher.cc
    • Updated include for structural equality to the new ir/ location.
  • src/relax/transform/alter_op_impl.cc
    • Updated include for serialization to the new ir/ location.
  • src/relax/transform/convert_layout.cc
    • Updated include for serialization to the new ir/ location.
  • src/relax/transform/specialize_primfunc_based_on_callsite.cc
    • Updated include for serialization to the new ir/ location.
  • src/s_tir/meta_schedule/module_equality.cc
    • Updated includes for structural equality and hash to the new ir/ location.
  • src/s_tir/meta_schedule/utils.h
    • Replaced includes of tvm/node/node.h and tvm/node/serialization.h with tvm/ir/serialization.h, tvm/node/cast.h, and tvm/runtime/object.h.
  • src/s_tir/schedule/primitive/layout_transformation.cc
    • Replaced include of tvm/node/node.h with tvm/node/cast.h and tvm/runtime/object.h.
  • src/s_tir/schedule/utils.h
    • Updated include for serialization to the new ir/ location.
  • src/script/printer/utils.h
    • Updated include for serialization to the new ir/ location.
  • src/support/scalars.h
    • Added <cmath> include.
  • tests/cpp/expr_test.cc
    • Updated include for structural equality to the new ir/ location.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 include/tvm/node/ namespace by removing aggregation headers and moving several node-related utilities to include/tvm/ir/. The changes are extensive but appear to be consistently applied across the codebase. Forwarding headers are added for backward compatibility. I have reviewed the changes and found no issues.

- Phase out BaseValueEqual: inline all operator() methods directly
  into StructuralEqual, removing the unnecessary base class
- Fix clang-format lint: correct include ordering in structural_equal.cc
  and structural_hash.cc
@tqchen tqchen changed the title [REFACTOR][NODE] Remove node redirect headers, move wrappers to ir/ [REFACTOR][NODE] Remove node redirect headers Feb 26, 2026
… directly

- Replace tvm::StructuralEqual with using ffi::StructuralEqual
- Replace tvm::StructuralHash (and BaseValueHash) with using ffi::StructuralHash
- Make tvm/ir/serialization.h a thin forwarding header to ffi/extra/serialization.h
- Remove tvm::StructuralEqual::operator() and tvm::StructuralHash::operator()
  implementations that were just forwarding to ffi
- Fix one 3-arg StructuralEqual call to use ffi::StructuralEqual::Equal directly
- Add missing transitive includes (cmath, runtime/tensor.h, device_api.h)
  that were previously pulled in through the removed headers
Tests need the fully-qualified namespace since they may not
have `using namespace tvm;` in scope.
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