gemini-code-assist[bot] commented on code in PR #19856:
URL: https://github.com/apache/tvm/pull/19856#discussion_r3448986905
##########
src/relax/transform/inline_functions.cc:
##########
@@ -215,7 +215,7 @@ Pass InlinePrivateFunctions() {
auto write_ptr = mod.CopyOnWrite();
for (const auto& [key, func] : replacements) {
- write_ptr->Remove(Downcast<GlobalVar>(key));
+ write_ptr->Remove(key.get<GlobalVar>());
Review Comment:

The `key` variable is of type `GlobalVar` (which inherits from `ObjectRef`).
`ObjectRef` and its subclasses do not have a `.get<T>()` member template, so
`key.get<GlobalVar>()` will cause a compilation error. Since `key` is already a
`GlobalVar`, you can pass it directly to `write_ptr->Remove`.
```suggestion
write_ptr->Remove(key);
```
##########
src/tirx/transform/unsupported_dtype_legalize.cc:
##########
@@ -545,7 +545,7 @@ class StorageLegalizer : public StmtExprMutator {
if (buf.same_as(op->buffer)) {
return ffi::GetRef<Stmt>(op);
} else {
- auto node = Downcast<AllocBuffer>(ffi::GetRef<Stmt>(op));
+ auto node = (ffi::GetRef<Stmt>(op)).as_or_throw<AllocBuffer>();
Review Comment:

Since `op` is of type `const AllocBufferNode*`, you can directly use
`ffi::GetRef<AllocBuffer>(op)` to safely obtain the `AllocBuffer` reference
without any runtime type checks.
```suggestion
auto node = ffi::GetRef<AllocBuffer>(op);
```
##########
src/relax/transform/convert_layout.cc:
##########
@@ -358,7 +359,8 @@ Pass ConvertLayout(ffi::Map<ffi::String,
ffi::Array<ffi::String>> desired_layout
LayoutCb layout_cb) {
ffi::TypedFunction<DataflowBlock(DataflowBlock, IRModule, PassContext)>
pass_func =
[=](DataflowBlock df_block, IRModule m, PassContext pc) {
- return Downcast<DataflowBlock>(ConvertLayoutPass(df_block,
desired_layouts, layout_cb));
+ return (ConvertLayoutPass(df_block, desired_layouts, layout_cb))
+ .as_or_throw<DataflowBlock>();
Review Comment:

The `ConvertLayoutPass` function already returns a `DataflowBlock` object.
Calling `.as_or_throw<DataflowBlock>()` on its return value is redundant.
```c
return ConvertLayoutPass(df_block, desired_layouts, layout_cb);
```
##########
src/relax/transform/attach_global_symbol.cc:
##########
@@ -100,7 +100,8 @@ IRModule ReplaceGlobalVarsInModule(IRModule mod,
ffi::Map<GlobalVar, GlobalVar>
} else if (auto* relax_func_node = old_func.as<FunctionNode>()) {
RelaxGvarMutator mutator(replacements);
auto new_relax_func =
-
Downcast<Function>(mutator(Downcast<Function>(ffi::GetRef<Function>(relax_func_node))));
+
(mutator((ffi::GetRef<Function>(relax_func_node)).as_or_throw<Function>()))
+ .as_or_throw<Function>();
Review Comment:

The expression `ffi::GetRef<Function>(relax_func_node)` already returns a
`Function` object. Calling `.as_or_throw<Function>()` on it is completely
redundant.
```c
(mutator(ffi::GetRef<Function>(relax_func_node))).as_or_throw<Function>();
```
##########
src/s_tir/meta_schedule/mutator/mutate_tile_size.cc:
##########
@@ -34,13 +34,14 @@ using s_tir::InstructionKind;
using s_tir::Trace;
/*!
- * \brief Downcast the decision of Sample-Perfect-Tile to an array of integers
+ * \brief Cast the decision of Sample-Perfect-Tile to an array of integers
* \param decision The decision of Sample-Perfect-Tile
* \return The result of downcast
*/
std::vector<int64_t> DowncastTilingDecision(const ffi::ObjectRef& decision) {
const auto* arr = TVM_TYPE_AS(decision, ffi::ArrayObj);
- return support::AsVector<ffi::ObjectRef,
int64_t>(ffi::GetRef<ffi::Array<ffi::ObjectRef>>(arr));
+ return support::AsVector<ffi::ObjectRef, int64_t>(
+
(ffi::GetRef<ffi::ObjectRef>(arr)).as_or_throw<ffi::Array<ffi::ObjectRef>>());
Review Comment:

The `arr` pointer is of type `const ffi::ArrayObj*`.
`ffi::GetRef<ffi::Array<ffi::ObjectRef>>(arr)` already returns
`ffi::Array<ffi::ObjectRef>` directly and safely. Casting it to
`ffi::ObjectRef` first and then calling `as_or_throw` introduces an unnecessary
runtime type check and is less efficient.
```c
return support::AsVector<ffi::ObjectRef,
int64_t>(ffi::GetRef<ffi::Array<ffi::ObjectRef>>(arr));
```
##########
src/relax/transform/call_tir_rewrite.cc:
##########
@@ -50,8 +50,8 @@ class CallTIRMutator : public ExprMutator {
IRModule Run() {
for (const auto& [gv, func] : mod_->functions) {
if (func->IsInstance<FunctionNode>()) {
- auto updated_func = Downcast<Function>(this->VisitExpr(func));
- builder_->UpdateFunction(gv, Downcast<BaseFunc>(updated_func));
+ auto updated_func = (this->VisitExpr(func)).as_or_throw<Function>();
+ builder_->UpdateFunction(gv, updated_func.as_or_throw<BaseFunc>());
Review Comment:

The `updated_func` variable is of type `Function`, which is a subclass of
`BaseFunc`. Therefore, it can be implicitly converted to `BaseFunc` without
calling `.as_or_throw<BaseFunc>()`.
```suggestion
builder_->UpdateFunction(gv, updated_func);
```
--
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]