tqchen opened a new issue, #18872:
URL: https://github.com/apache/tvm/issues/18872
## Summary
Add virtual `VisitBufferDef`/`VisitBufferUse` hooks to `StmtVisitor`,
`StmtMutator`,
`StmtExprVisitor`, `StmtExprMutator`, and `TIRVisitorWithPath`. These allow
subclasses to customize buffer handling at definition vs use sites.
## Motivation
Currently, buffer field visiting (shape, strides, elem_offset) is duplicated
across
many visitor/mutator subclasses. Each one reimplements buffer field
traversal in
`VisitStmt_(const AllocBufferNode*)`, `VisitStmt_(const DeclBufferNode*)`,
etc.
More importantly, there is a semantic distinction between buffer
**definition** sites
(AllocBuffer, DeclBuffer, SBlock alloc_buffers) and buffer **use** sites
(BufferLoad,
BufferStore, SBlock reads/writes) that is not captured by the base visitor
API:
- At **definition** sites, buffer fields (shape, strides, elem_offset)
should be visited
because the defining scope owns those expressions.
- At **use** sites, buffer fields should NOT be re-visited, because the use
may occur
in a different scope where the buffer's shape variables are not defined.
Without this distinction, analyses like `UndefinedVars` can miss variables or
visit them in the wrong scope.
## Design
- `VisitBufferDef(buffer, alloc_data)` — called at definition sites. Visits
buffer
shape, strides, elem_offset. The `alloc_data` flag distinguishes:
- `true` (AllocBuffer, SBlock): data var is a new allocation (DEF)
- `false` (DeclBuffer): data var references existing allocation (USE)
- `VisitBufferUse(buffer)` — called at use sites (BufferLoad, BufferStore,
reads/writes).
Default is empty (no field re-visiting). Subclasses can override to track
data pointer uses.
- Buffer fields are visited at definition sites only. The base
`StmtMutator::VisitBufferDef`
also maintains a `buffer_remap_` map so mutated buffers propagate to use
sites automatically.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]