[TIR] Add VisitBufferDef/VisitBufferUse to base StmtVisitor/StmtMutator#18873
Conversation
Summary of ChangesHello, 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 refactors how buffers are visited and mutated within the TIR (Tensor IR) framework by introducing explicit virtual methods for buffer definition and use sites. This change centralizes the logic for handling buffer fields, such as shape and strides, and ensures that variable scoping is correctly maintained during analysis and transformation passes. The primary impact is a more robust and maintainable IR infrastructure, particularly for analyses like Highlights
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces VisitBufferDef and VisitBufferUse hooks to the base statement visitors and mutators (StmtVisitor, StmtMutator, StmtExprVisitor, StmtExprMutator, TIRVisitorWithPath). This is a significant and beneficial refactoring that centralizes buffer visiting logic, distinguishing between buffer definition sites and use sites. This improves correctness for analyses like UndefinedVars and simplifies many downstream visitors/mutators by removing duplicated boilerplate code. The changes are well-implemented and supported by a comprehensive set of new and updated tests. My only suggestion is to correct a comment in stmt_functor.h to accurately reflect the default behavior of VisitBufferUse.
4a74f6d to
8df19e3
Compare
8df19e3 to
f739761
Compare
…ataTypeRewriter Base StmtMutator now handles these via VisitBufferDef (from upstream PR apache#18873).
Summary
Add virtual
VisitBufferDef/VisitBufferUsehooks toStmtVisitor,StmtMutator,StmtExprVisitor,StmtExprMutator, andTIRVisitorWithPath.These centralize buffer field visiting (shape, strides, elem_offset) at definition
sites only, and distinguish definition vs use sites so analyses like
UndefinedVarscorrectly track variable scoping.
Key Design
VisitBufferDef(buffer, alloc_data)— called at definition sites (AllocBuffer, DeclBuffer, SBlock alloc_buffers). Visits buffer shape, strides, elem_offset.alloc_data=truemeans data var is a new allocation (DEF);falsemeans data references existing allocation (USE).VisitBufferUse(buffer)— called at use sites (BufferLoad, BufferStore, SBlock reads/writes). Default is empty (no field re-visiting).StmtMutator::VisitBufferDefmaintains abuffer_remap_map so mutated buffers propagate to use sites automatically.Removes duplicated buffer field visiting from ~10 subclasses by centralizing it in the base classes.
Test plan
test_tir_analysis_undefined_vars.py— new tests for def/use distinctiontest_tir_transform_convert_ssa.py— 13 teststest_tir_transform_vectorize.py— 72 teststest_tir_transform_simplify.py— new test for buffer simplificationtest_minimal_target_codegen_llvm.py— LLVM codegen smoke testir_functor_test.cc— C++ functor tests