You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "tqchen (via GitHub)" <gi...@apache.org> on 2026/07/16 13:51:09 UTC
[PR] [TIRx] Introduce first-class Return statement [tvm]
tqchen opened a new pull request, #20018:
URL: https://github.com/apache/tvm/pull/20018
Return is control flow, but TIRx currently represents it as an Evaluate-wrapped intrinsic call. This prevents return values from participating naturally in statement traversal and requires special-case handling across the pipeline.
This change introduces a reflected tirx.Return statement carrying an Expr, wires it through TVMScript, statement visitors and mutators, lowering, storage planning, and C/LLVM code generation, and removes the legacy tirx.ret and T.ret surfaces.
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [TIRx] Introduce first-class Return statement [tvm]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on PR #20018:
URL: https://github.com/apache/tvm/pull/20018#issuecomment-4995628129
@tvm-bot rerun
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [TIRx] Introduce first-class Return statement [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #20018:
URL: https://github.com/apache/tvm/pull/20018#discussion_r3596038250
##########
src/tirx/ir/stmt_functor.cc:
##########
@@ -59,6 +59,8 @@ void StmtVisitor::VisitStmt_(const WhileNode* op) {
this->VisitStmt(op->body);
}
+void StmtVisitor::VisitStmt_(const ReturnNode* op) { this->VisitExpr(op->value); }
Review Comment:

In TVM/TIRx, `StmtVisitor` is designed to only traverse statement nodes and does not define or inherit a `VisitExpr` method (unlike `StmtExprVisitor`). Calling `this->VisitExpr(op->value)` here will result in a compilation error.
To fix this, `StmtVisitor::VisitStmt_(const ReturnNode* op)` should be empty, similar to `VisitStmt_(const EvaluateNode* op)`.
Additionally, to ensure that expressions inside `Return` statements are correctly visited and mutated during IR passes, you must explicitly override `VisitStmt_(const ReturnNode* op)` in `StmtExprVisitor` and `StmtExprMutator` (defined in `include/tvm/tirx/stmt_functor.h` and implemented in `src/tirx/ir/stmt_functor.cc`) to call `this->VisitExpr(op->value)` and mutate `op->value` respectively. Without these overrides, passes like `LinearAccessPatternFinder` (in `storage_rewrite.cc`) will fail to detect buffer/variable accesses within `Return` statements, leading to critical correctness bugs.
```suggestion
void StmtVisitor::VisitStmt_(const ReturnNode* op) {}
```
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [TIRx] Introduce first-class Return statement [tvm]
Posted by "spectrometerHBH (via GitHub)" <gi...@apache.org>.
spectrometerHBH merged PR #20018:
URL: https://github.com/apache/tvm/pull/20018
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [TIRx] Introduce first-class Return statement [tvm]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #20018:
URL: https://github.com/apache/tvm/pull/20018#discussion_r3596091334
##########
src/tirx/ir/stmt_functor.cc:
##########
@@ -59,6 +59,8 @@ void StmtVisitor::VisitStmt_(const WhileNode* op) {
this->VisitStmt(op->body);
}
+void StmtVisitor::VisitStmt_(const ReturnNode* op) { this->VisitExpr(op->value); }
Review Comment:
Thanks for flagging this. In TIRx, StmtVisitor does define the protected virtual VisitExpr(const Expr&) hook in include/tvm/tirx/stmt_functor.h, and StmtExprVisitor overrides it to delegate to ExprVisitor. StmtMutator likewise defines VisitExpr, while StmtExprMutator overrides it to delegate to ExprMutator. The Return handlers therefore belong in StmtVisitor and StmtMutator, matching Evaluate and the other expression-bearing statements; recursive StmtExpr traversal and mutation reach Return.value through those hooks. The exact PR head builds successfully, the focused Return functor tests pass (19/19), and the complete storage-rewrite suite passes (14/14), so no code change is needed here.
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org