Skip to content

Conversation

@Hzfengsy
Copy link
Member

This commit introduces Python interfaces for TIR functors, enabling Python-side customization of expression and statement visiting and mutation operations.

Key changes:

  • Add PyStmtExprVisitorNode and PyStmtExprMutatorNode classes in C++
  • Implement Python bindings for all TIR expression and statement types
  • Support both visitor (read-only) and mutator (transforming) patterns
  • Add comprehensive dispatch mechanisms for Python callbacks
  • Include FFI registrations for Python-C++ interoperability

This enables users to write custom TIR transformations and analysis passes directly in Python while maintaining performance through selective Python callback dispatch.

@Hzfengsy Hzfengsy requested a review from Copilot June 14, 2025 13:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces Python functor support for TIR expressions and statements by adding new C++ classes and corresponding Python bindings for both visitor and mutator patterns. It also updates import paths and macro formatting to align with the new functor dispatch design.

  • Introduces PyStmtExprVisitorNode and PyStmtExprMutatorNode classes in C++ and the necessary Python bindings.
  • Updates module imports in the Python interface to reflect the new functor support.
  • Adjusts macro formatting in the C++ header for clearer block structure.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/tir/analysis/buffer_access_lca_detector.cc Removes an unused lambda capture parameter to simplify the lambda.
python/tvm/tir/init.py Adds imports for the new functor classes.
python/tvm/runtime/support.py Introduces the derived_object decorator for TVM objects.
python/tvm/relax/expr_functor.py Changes the derived_object import and corrects the order of imports.
include/tvm/relax/expr_functor.h Adjusts macro formatting for improved readability.

const PrimExpr& binding) -> const ScopeInfo* {
const ScopeInfo* highest_scope = nullptr;
PostOrderVisit(binding, [this, &itervar, &highest_scope](const ObjectRef& obj) {
PostOrderVisit(binding, [this, &highest_scope](const ObjectRef& obj) {
Copy link

Copilot AI Jun 14, 2025

Choose a reason for hiding this comment

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

The lambda no longer uses the captured variable 'itervar'. Removing it from the capture list improves clarity and avoids potential confusion.

Copilot uses AI. Check for mistakes.
@Hzfengsy
Copy link
Member Author

@tqchen
Copy link
Member

tqchen commented Jun 14, 2025

cc @jinhongyii

@Hzfengsy Hzfengsy force-pushed the tir_py_functor branch 2 times, most recently from 40f6d9f to 14f0261 Compare June 16, 2025 01:55
This commit introduces Python interfaces for TIR functors,
enabling Python-side customization of expression and statement visiting
and mutation operations.

Key changes:
- Add PyStmtExprVisitorNode and PyStmtExprMutatorNode classes in C++
- Implement Python bindings for all TIR expression and statement types
- Support both visitor (read-only) and mutator (transforming) patterns
- Add comprehensive dispatch mechanisms for Python callbacks
- Include FFI registrations for Python-C++ interoperability

This enables users to write custom TIR transformations and analysis
passes directly in Python while maintaining performance through
selective Python callback dispatch.
@jinhongyii jinhongyii merged commit 2ae2aca into apache:main Jun 16, 2025
13 checks passed
@Hzfengsy Hzfengsy deleted the tir_py_functor branch June 17, 2025 13:14
ShiboXing pushed a commit to ShiboXing/tvm that referenced this pull request Aug 10, 2025
…#18060)

This commit introduces Python interfaces for TIR functors,
enabling Python-side customization of expression and statement visiting
and mutation operations.

Key changes:
- Add PyStmtExprVisitorNode and PyStmtExprMutatorNode classes in C++
- Implement Python bindings for all TIR expression and statement types
- Support both visitor (read-only) and mutator (transforming) patterns
- Add comprehensive dispatch mechanisms for Python callbacks
- Include FFI registrations for Python-C++ interoperability

This enables users to write custom TIR transformations and analysis
passes directly in Python while maintaining performance through
selective Python callback dispatch.
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