This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 46a45c5f57 [FFI] Update tvm-ffi and native Any hooks (#20664)
46a45c5f57 is described below
commit 46a45c5f574360e69e312236cafda7e7eb48b440
Author: Tianqi Chen <[email protected]>
AuthorDate: Sun Oct 11 21:43:02 2026 -0400
[FFI] Update tvm-ffi and native Any hooks (#20664)
Update tvm-ffi to `1cef91429a816cc4ccaeace8db32f45ef1524c29` and
register PrimType hashing and equality through its typed NativeFunction
adapters.
Adapt Optional presence and composition while retaining direct strict
casts, object identity and ownership. Replace null concrete containers
with valid empty containers or explicit absence where appropriate,
preserving all-axis reduction and scheduling behavior.
---
3rdparty/tvm-ffi | 2 +-
include/tvm/ir/op.h | 4 ++--
include/tvm/te/tensor.h | 6 +++---
include/tvm/topi/nn.h | 5 ++---
include/tvm/topi/transform.h | 2 +-
src/backend/cuda/op/target_builtin.cc | 2 +-
src/backend/cuda/transforms/lower_iket.cc | 2 +-
src/backend/trn/codegen/codegen_trn.cc | 6 +++---
src/ir/type.cc | 12 ++++++++----
src/relax/analysis/tir_op_pattern_kind.cc | 4 ++--
src/relax/op/tensor/linear_algebra.cc | 2 +-
src/relax/op/tensor/search.cc | 2 +-
src/relax/op/tensor/set.cc | 4 ++--
src/relax/op/tensor/ternary.cc | 2 +-
src/relax/transform/allocate_workspace.cc | 6 +++---
.../measure_callback/add_to_database.cc | 2 +-
.../schedule_rule/random_compute_location.cc | 4 ++--
.../meta_schedule/search_strategy/replay_trace.cc | 2 +-
src/s_tir/meta_schedule/utils.h | 2 +-
src/s_tir/schedule/primitive/blockize_tensorize.cc | 6 +++---
src/s_tir/schedule/primitive/cache_read_write.cc | 8 ++++----
src/s_tir/schedule/primitive/compute_inline.cc | 12 ++++++------
src/s_tir/schedule/primitive/reduction.cc | 8 ++++----
src/s_tir/schedule/trace.cc | 2 +-
src/s_tir/script/ir_builder/ir.cc | 4 ++--
src/s_tir/transform/lower_cross_thread_reduction.cc | 20 ++++++++++----------
src/script/printer/ir/call.cc | 10 +++++-----
src/script/printer/ir/utils.cc | 2 +-
src/sym/int_set.cc | 2 +-
src/sym/iter_affine_map.cc | 2 +-
src/target/llvm/codegen_aarch64.cc | 2 +-
src/target/llvm/codegen_cpu.cc | 4 ++--
src/target/llvm/llvm_module.cc | 10 +++++-----
src/target/target.cc | 6 ++++--
src/te/operation/create_function.cc | 4 ++--
src/te/operation/graph.cc | 2 +-
src/tirx/ir/layout/tile_canonicalize.cc | 2 +-
src/tirx/ir/layout/tile_tile_ops.cc | 2 +-
src/tirx/op/memory.cc | 4 ++--
src/tirx/script/printer/expr.cc | 8 ++++----
src/tirx/tile/op.cc | 3 ++-
src/tirx/transform/storage_rewrite.cc | 2 +-
src/tirx/transform/vectorize_loop.cc | 4 ++--
43 files changed, 103 insertions(+), 97 deletions(-)
diff --git a/3rdparty/tvm-ffi b/3rdparty/tvm-ffi
index df463f9bd2..1cef91429a 160000
--- a/3rdparty/tvm-ffi
+++ b/3rdparty/tvm-ffi
@@ -1 +1 @@
-Subproject commit df463f9bd269867fc7f4d578d62d80cc2a11d004
+Subproject commit 1cef91429a816cc4ccaeace8db32f45ef1524c29
diff --git a/include/tvm/ir/op.h b/include/tvm/ir/op.h
index 0a4018722b..9d821a2683 100644
--- a/include/tvm/ir/op.h
+++ b/include/tvm/ir/op.h
@@ -424,10 +424,10 @@ struct call_attrs : SignatureTrait {
static bool Validate(ValidateState* state, ffi::Expected<void>* out) {
ffi::AnyView attrs(state->call->attrs);
- if (TVM_FFI_PREDICT_FALSE(!state->call->attrs.defined() ||
+ if (TVM_FFI_PREDICT_FALSE(!state->call->attrs.has_value() ||
!ffi::details::AnyUnsafe::CheckAnyViewStrict<const T*>(attrs))) {
TVMFFIAny raw = attrs.CopyToTVMFFIAny();
- std::string actual = state->call->attrs.defined()
+ std::string actual = state->call->attrs.has_value()
? "`" + ffi::TypeTraits<const
T*>::GetMismatchTypeInfo(&raw) + "`"
: "None";
*out = TVM_FFI_UNEXPECTED(TypeError)
diff --git a/include/tvm/te/tensor.h b/include/tvm/te/tensor.h
index 417f731afd..ec477f337d 100644
--- a/include/tvm/te/tensor.h
+++ b/include/tvm/te/tensor.h
@@ -238,7 +238,7 @@ inline size_t Tensor::ndim() const { return
(*this)->shape.size(); }
inline bool Tensor::operator==(const Tensor& other) const {
if (get() == other.get()) return true;
if (get() == nullptr || other.get() == nullptr) return false;
- if ((*this)->op.defined() || other->op.defined()) {
+ if ((*this)->op.has_value() || other->op.has_value()) {
return (*this)->op == other->op && (*this)->value_index ==
other->value_index;
} else {
return false;
@@ -291,8 +291,8 @@ template <>
struct hash<::tvm::te::Tensor> {
std::size_t operator()(const ::tvm::te::Tensor& k) const {
::tvm::ffi::ObjectPtrHash hasher;
- if (k.defined() && k->op.defined()) {
- return hasher(k->op);
+ if (k.defined() && k->op.has_value()) {
+ return hasher(k->op.value());
} else {
return hasher(k);
}
diff --git a/include/tvm/topi/nn.h b/include/tvm/topi/nn.h
index 73eb3725ae..c79560b974 100644
--- a/include/tvm/topi/nn.h
+++ b/include/tvm/topi/nn.h
@@ -724,10 +724,9 @@ inline Tensor nll_loss(const Tensor& predictions, const
Tensor& targets, const T
tvm::prim::MakeConst(tvm::PrimType(predictions->dtype), 0));
},
name, tag);
- return topi::divide(topi::sum(T, tvm::ffi::Array<int64_t>(nullptr)),
- topi::sum(W, tvm::ffi::Array<int64_t>(nullptr)));
+ return topi::divide(topi::sum(T, std::nullopt), topi::sum(W,
std::nullopt));
} else if (reduction == "sum") {
- return topi::sum(T, tvm::ffi::Array<int64_t>(nullptr));
+ return topi::sum(T, std::nullopt);
} else { // reduction == "none"
return T;
}
diff --git a/include/tvm/topi/transform.h b/include/tvm/topi/transform.h
index d724b49539..57914dd550 100644
--- a/include/tvm/topi/transform.h
+++ b/include/tvm/topi/transform.h
@@ -1852,7 +1852,7 @@ inline Tensor layout_transform(const Tensor& src, const
std::string& src_layout,
<< "cannot convert from/to undefined layout";
auto layout_converter = tirx::SBijectiveLayout::Create(src_layout_struct,
dst_layout_struct);
- TVM_FFI_ICHECK(layout_converter.defined())
+ TVM_FFI_ICHECK(layout_converter.has_value())
<< "cannot convert from " << src_layout << " to " << dst_layout;
ffi::Array<PrimExpr> dst_shape =
layout_converter.value().ForwardShape(src->shape);
diff --git a/src/backend/cuda/op/target_builtin.cc
b/src/backend/cuda/op/target_builtin.cc
index d56e431958..0f893fe6be 100644
--- a/src/backend/cuda/op/target_builtin.cc
+++ b/src/backend/cuda/op/target_builtin.cc
@@ -71,7 +71,7 @@ void ValidateDeclTmem(const CallNode* call) {
Type inferred = InferTypeDeclTmem(call);
TVM_FFI_CHECK(ffi::StructuralEqual()(call->ty, inferred), TypeError)
<< "decl_tmem result must match its TensorType argument";
- TVM_FFI_CHECK(!call->attrs.defined(), ValueError) << "decl_tmem does not
accept attributes";
+ TVM_FFI_CHECK(!call->attrs.has_value(), ValueError) << "decl_tmem does not
accept attributes";
}
Type InferTypeCudaAxis(const CallNode* call) {
diff --git a/src/backend/cuda/transforms/lower_iket.cc
b/src/backend/cuda/transforms/lower_iket.cc
index 006f867ec6..fb40e91a1e 100644
--- a/src/backend/cuda/transforms/lower_iket.cc
+++ b/src/backend/cuda/transforms/lower_iket.cc
@@ -1210,7 +1210,7 @@ IRModule LowerIketImpl(IRModule module) {
strip->Mutate(function->body.value()).ValueOrUnchanged(function->body.value());
Stmt body =
ffi::make_object<RemoveStrippedIketNoOps>()->Mutate(stripped).ValueOrUnchanged(stripped);
- if (!body.same_as(function->body)) {
+ if (!function->body.same_as(body)) {
function.CopyOnWrite()->body = body;
module->Update(global_var, function);
}
diff --git a/src/backend/trn/codegen/codegen_trn.cc
b/src/backend/trn/codegen/codegen_trn.cc
index 87aa5e273e..47f2ded400 100644
--- a/src/backend/trn/codegen/codegen_trn.cc
+++ b/src/backend/trn/codegen/codegen_trn.cc
@@ -450,7 +450,7 @@ void CodeGenTrainium::Dispatch_(const CallNode* op,
std::ostream& os) { // NOLI
TVM_FFI_ICHECK_GE(op->args.size(), 2);
// result, value
os << PrintExpr(op->args[0]) << " = " << PrintExpr(op->args[1]);
- TVM_FFI_ICHECK(!ctx_.mask.defined()) << "memset cannot have mask";
+ TVM_FFI_ICHECK(!ctx_.mask.has_value()) << "memset cannot have mask";
return;
} else if (is_op(nki_tensorreduce_op, "tirx.nki.tensorreduce")) {
TVM_FFI_ICHECK(op->args.size() >= 5)
@@ -538,7 +538,7 @@ void CodeGenTrainium::Dispatch_(const CallNode* op,
std::ostream& os) { // NOLI
} else {
LOG(FATAL) << "Trainium codegen does not support call to " << op->op;
}
- if (ctx_.mask.defined()) {
+ if (ctx_.mask.has_value()) {
auto walk_fn = [&](const Var& var) -> ffi::Expected<ffi::WalkResult> {
const VarNode* v = var.get();
if (ctx_.tensorized_loop_vars.count(v)) {
@@ -709,7 +709,7 @@ ffi::Module BuildTrainium(IRModule mod, Target target) {
void CodeGenTrainium::Dispatch_(const IfNode* op) {
if (ctx_.tensorizing) {
TVM_FFI_ICHECK(!op->else_case.has_value()) << "Else not allowed in
tensorized instruction";
- TVM_FFI_ICHECK(!ctx_.mask.defined()) << "Only one if stmt allowed in
tensorized instruction";
+ TVM_FFI_ICHECK(!ctx_.mask.has_value()) << "Only one if stmt allowed in
tensorized instruction";
ctx_.mask = op->condition;
Dispatch(op->then_case);
return;
diff --git a/src/ir/type.cc b/src/ir/type.cc
index 99c81bb229..4acc73704d 100644
--- a/src/ir/type.cc
+++ b/src/ir/type.cc
@@ -24,6 +24,7 @@
#include <tvm/ffi/extra/structural_mutate.h>
#include <tvm/ffi/extra/structural_visit.h>
#include <tvm/ffi/function.h>
+#include <tvm/ffi/reflection/native_function.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/ir/type.h>
@@ -93,11 +94,11 @@ TVM_FFI_INLINE ffi::Expected<ffi::UnchangedOr<ffi::Any>>
OpaqueTypeMaybeInplaceM
return ffi::Unchanged();
}
-int64_t PrimTypeAnyHash(const ffi::Any& src) {
+TVM_FFI_INLINE int64_t PrimTypeAnyHash(const ffi::Any& src) {
return static_cast<int64_t>(PackDataTypeKey(src.cast<PrimType>()->dtype));
}
-bool PrimTypeAnyEqual(const ffi::Any& lhs, const ffi::Any& rhs) {
+TVM_FFI_INLINE bool PrimTypeAnyEqual(const ffi::Any& lhs, const ffi::Any& rhs)
{
return lhs.cast<PrimType>()->dtype == rhs.cast<PrimType>()->dtype;
}
@@ -341,8 +342,11 @@ TVM_FFI_STATIC_INIT_BLOCK() {
namespace refl = tvm::ffi::reflection;
PrimTypeNode::RegisterReflection();
refl::TypeAttrDef<PrimTypeNode>()
- .attr(refl::type_attr::kAnyHash,
reinterpret_cast<void*>(&PrimTypeAnyHash))
- .attr(refl::type_attr::kAnyEqual,
reinterpret_cast<void*>(&PrimTypeAnyEqual))
+ .attr(refl::type_attr::kAnyHash,
+ refl::NativeFunction<int64_t(const
ffi::Any&)>::FromNative<&PrimTypeAnyHash>())
+ .attr(refl::type_attr::kAnyEqual,
+ refl::NativeFunction<bool(const ffi::Any&,
+ const
ffi::Any&)>::FromNative<&PrimTypeAnyEqual>())
.attr(refl::type_attr::kStructuralVisit,
ffi::FStructuralVisit::FromNative<&PrimTypeVisit>())
.attr(refl::type_attr::kStructuralMutate,
ffi::FStructuralMutate::FromNative<&PrimTypeMutate>())
diff --git a/src/relax/analysis/tir_op_pattern_kind.cc
b/src/relax/analysis/tir_op_pattern_kind.cc
index 41322ea495..81bf6002ac 100644
--- a/src/relax/analysis/tir_op_pattern_kind.cc
+++ b/src/relax/analysis/tir_op_pattern_kind.cc
@@ -491,7 +491,7 @@ bool HasReshapePattern(const tirx::Function& func) {
return true;
};
- ffi::Array<PrimExpr> nontrivial_indices{nullptr};
+ ffi::Array<PrimExpr> nontrivial_indices;
ffi::Optional<TensorVar> nontrivial_tensor;
if (f_is_trivial_indices(dst_tensor_, tensor_store->indices)) {
nontrivial_indices = tensor_load->indices;
@@ -507,7 +507,7 @@ bool HasReshapePattern(const tirx::Function& func) {
return this->ana_->CanProveEqual(v->dom.value()->extent, 0);
});
- if (nontrivial_indices.defined() && !has_zero_extent) {
+ if (nontrivial_tensor.has_value() && !has_zero_extent) {
PrimType dtype =
!block->iter_vars.empty() ? block->iter_vars[0]->var.ty() :
PrimType::Int(64);
PrimVar fused_var("fused", dtype);
diff --git a/src/relax/op/tensor/linear_algebra.cc
b/src/relax/op/tensor/linear_algebra.cc
index 551bd2102e..1782e69836 100644
--- a/src/relax/op/tensor/linear_algebra.cc
+++ b/src/relax/op/tensor/linear_algebra.cc
@@ -227,7 +227,7 @@ Type InferTypeEinsum(const CallNode* call_node) {
vdev = ty->vdevice.value();
} else if (ty->vdevice.value()->target.has_value()) {
// mismatch
- if (ty->vdevice.value() != vdev) {
+ if (ty->vdevice.value() != vdev.value()) {
vdevice_unknown = true;
}
}
diff --git a/src/relax/op/tensor/search.cc b/src/relax/op/tensor/search.cc
index 8d188ddaa2..2a30d65221 100644
--- a/src/relax/op/tensor/search.cc
+++ b/src/relax/op/tensor/search.cc
@@ -141,7 +141,7 @@ Type InferTypeWhere(const Call& call, const BlockBuilder&
ctx) {
vdev = input_ty[i]->vdevice.value();
} else if (input_ty[i]->vdevice.value()->target.has_value()) {
// mismatch
- if (input_ty[i]->vdevice.value() != vdev) {
+ if (input_ty[i]->vdevice.value() != vdev.value()) {
vdev = std::nullopt;
break;
}
diff --git a/src/relax/op/tensor/set.cc b/src/relax/op/tensor/set.cc
index 3d97d69e9e..3f3865b4f9 100644
--- a/src/relax/op/tensor/set.cc
+++ b/src/relax/op/tensor/set.cc
@@ -65,7 +65,7 @@ Type InferTypeUnique(const CallNode* call_node) {
axis = prim_value.value();
}
}
- if (!data_ty->IsUnknownNdim() && axis.defined()) {
+ if (!data_ty->IsUnknownNdim() && axis.has_value()) {
// Normalize the axis for sanity check purpose.
if (const auto* axis_int = axis.as<IntImmNode>()) {
NormalizeAxis(call, data_ty->ndim, axis_int->value.as<int>().value());
@@ -97,7 +97,7 @@ Type InferTypeUnique(const CallNode* call_node) {
if (data_ty->ndim == 0) {
output_ty.push_back(
TensorType(ShapeExpr({IntImm::Int64(/*value=*/1)}), data_ty->dtype,
data_ty->vdevice));
- } else if (axis.defined()) {
+ } else if (axis.has_value()) {
output_ty.push_back(TensorType(data_ty->dtype, data_ty->ndim,
data_ty->vdevice));
} else {
output_ty.push_back(TensorType(data_ty->dtype, /*ndim=*/1,
data_ty->vdevice));
diff --git a/src/relax/op/tensor/ternary.cc b/src/relax/op/tensor/ternary.cc
index 4f34d36843..4ed9c8a2ca 100644
--- a/src/relax/op/tensor/ternary.cc
+++ b/src/relax/op/tensor/ternary.cc
@@ -75,7 +75,7 @@ Type InferTypeEwiseFMA(const Call& call, const BlockBuilder&
ctx) {
vdev = input_ty[i]->vdevice.value();
} else if (input_ty[i]->vdevice.value()->target.has_value()) {
// mismatch
- if (input_ty[i]->vdevice.value() != vdev) {
+ if (input_ty[i]->vdevice.value() != vdev.value()) {
vdev = std::nullopt;
break;
}
diff --git a/src/relax/transform/allocate_workspace.cc
b/src/relax/transform/allocate_workspace.cc
index 939ce8f22f..6c3b186298 100644
--- a/src/relax/transform/allocate_workspace.cc
+++ b/src/relax/transform/allocate_workspace.cc
@@ -88,7 +88,7 @@ class ExternFunctionRewriter : ExprMutator {
// Append the workspace argument to this call. The callee should have
been updated to accept
// a workspace as the last parameter.
auto new_args = call_node->args;
- TVM_FFI_ICHECK(workspace_var_param_.defined());
+ TVM_FFI_ICHECK(workspace_var_param_.has_value());
new_args.push_back(workspace_var_param_.value());
return Call(Type::Missing(), new_op, new_args, call_node->attrs,
call_node->ty_args,
call_node->loc);
@@ -151,7 +151,7 @@ class WorkspaceProvider : ExprMutator {
BindingBlock VisitBindingBlock_(const DataflowBlockNode* block_node) final {
builder_->BeginDataflowBlock();
- if (!workspace_var_main_.defined()) {
+ if (!workspace_var_main_.has_value()) {
auto shape = ShapeExpr({IntImm::Int32(max_workspace_size_)});
auto ty = DataTypeImm((DLDataType{kDLUInt, 8, 1}));
auto workspace = MakeAllocTensor(shape, ty, IntImm::Int64(0));
@@ -176,7 +176,7 @@ class WorkspaceProvider : ExprMutator {
if (auto gv = new_op.as<GlobalVar>()) {
if (new_gvars_.count(gv.value())) {
auto new_args = call_node->args;
- TVM_FFI_ICHECK(workspace_var_main_.defined());
+ TVM_FFI_ICHECK(workspace_var_main_.has_value());
new_args.push_back(workspace_var_main_.value());
return Call(Type::Missing(), new_op, new_args, call_node->attrs,
call_node->ty_args,
call_node->loc);
diff --git a/src/s_tir/meta_schedule/measure_callback/add_to_database.cc
b/src/s_tir/meta_schedule/measure_callback/add_to_database.cc
index 368ce68fcf..c7eac656a3 100644
--- a/src/s_tir/meta_schedule/measure_callback/add_to_database.cc
+++ b/src/s_tir/meta_schedule/measure_callback/add_to_database.cc
@@ -43,7 +43,7 @@ class AddToDatabaseObj : public MeasureCallbackObj {
for (int i = 0; i < n; ++i) {
RunnerResult result = runner_results[i];
MeasureCandidate candidate = measure_candidates[i];
- ffi::Array<FloatImm> run_secs{nullptr};
+ ffi::Array<FloatImm> run_secs;
if (result->run_secs.has_value()) {
run_secs = result->run_secs.value();
} else {
diff --git a/src/s_tir/meta_schedule/schedule_rule/random_compute_location.cc
b/src/s_tir/meta_schedule/schedule_rule/random_compute_location.cc
index 105bea3500..52c9541c14 100644
--- a/src/s_tir/meta_schedule/schedule_rule/random_compute_location.cc
+++ b/src/s_tir/meta_schedule/schedule_rule/random_compute_location.cc
@@ -43,7 +43,7 @@ class RandomComputeLocationObj : public ScheduleRuleObj {
// decision of Sample-Compute-Location is "compute-inline" for the input
block, we can no longer
// access the input block. Hence we collect its producer ahead of time.
// - Note that only single producer is allowed in this case.
- ffi::Array<s_tir::SBlockRV> producers{nullptr};
+ ffi::Array<s_tir::SBlockRV> producers;
if (s_tir::HasAnn(sch->GetSRef(block_rv),
tvm::s_tir::attr::kMetaScheduleRandomComputeProducer,
true)) {
producers = sch->GetProducers(block_rv);
@@ -55,7 +55,7 @@ class RandomComputeLocationObj : public ScheduleRuleObj {
s_tir::Schedule res = RandomlyComputeAt(sch, block_rv);
// Step 3. Transform the producer block if compute-location sampling is
needed.
- if (producers.defined()) {
+ if (!producers.empty()) {
res = RandomlyComputeAt(res, producers[0]);
}
diff --git a/src/s_tir/meta_schedule/search_strategy/replay_trace.cc
b/src/s_tir/meta_schedule/search_strategy/replay_trace.cc
index 3e8a64b3d2..321ac42b69 100644
--- a/src/s_tir/meta_schedule/search_strategy/replay_trace.cc
+++ b/src/s_tir/meta_schedule/search_strategy/replay_trace.cc
@@ -43,7 +43,7 @@ class ReplayTraceObj : public SearchStrategyObj {
int ed;
/*! \brief The module to be tuned. */
- ffi::Array<IRModule> per_thread_mod_{nullptr};
+ ffi::Array<IRModule> per_thread_mod_;
explicit State(ReplayTraceObj* self, ffi::Array<s_tir::Trace>
design_spaces, int max_trials,
int num_trials_per_iter)
diff --git a/src/s_tir/meta_schedule/utils.h b/src/s_tir/meta_schedule/utils.h
index 71c0c40543..b7f0ea92c5 100644
--- a/src/s_tir/meta_schedule/utils.h
+++ b/src/s_tir/meta_schedule/utils.h
@@ -579,7 +579,7 @@ inline bool IsGPUTarget(const std::string& target_name) {
* \return The AutoInline schedule rule for the given target.
*/
inline ScheduleRule GetDefaultAutoInline(const std::string& target_name) {
- ffi::Array<ScheduleRule> rules{nullptr};
+ ffi::Array<ScheduleRule> rules;
if (target_name == "llvm") {
rules = ScheduleRule::DefaultLLVM();
} else if (target_name == "hexagon") {
diff --git a/src/s_tir/schedule/primitive/blockize_tensorize.cc
b/src/s_tir/schedule/primitive/blockize_tensorize.cc
index 56d0cc52e5..e87e0bf2ed 100644
--- a/src/s_tir/schedule/primitive/blockize_tensorize.cc
+++ b/src/s_tir/schedule/primitive/blockize_tensorize.cc
@@ -609,8 +609,8 @@ SBlockRealize BlockizeBlocks(const ScheduleState& self,
const ffi::Array<StmtSRe
bool preserve_unit_iters) {
ffi::Array<Stmt> seq_body;
ffi::Optional<PrimExpr> outer_predicate;
- ffi::Array<IterVar> outer_iter_vars{nullptr};
- ffi::Array<PrimExpr> outer_bindings{nullptr};
+ ffi::Array<IterVar> outer_iter_vars;
+ ffi::Array<PrimExpr> outer_bindings;
ffi::Array<TensorRegion> read_regions;
ffi::Array<TensorRegion> write_regions;
std::string outer_block_name = "outer_";
@@ -636,7 +636,7 @@ SBlockRealize BlockizeBlocks(const ScheduleState& self,
const ffi::Array<StmtSRe
DeriveBlockBinding(block->iter_vars, division, //
&outer_iter_vars, &outer_bindings, //
&inner_iter_vars, &inner_bindings, //
- preserve_unit_iters, outer_iter_vars.defined());
+ preserve_unit_iters, !outer_iter_vars.empty());
// Step 3: Do var substitution to adjust to the new block bindings
for (size_t i = 0; i < outer_iter_vars.size(); ++i) {
if (outer_bindings[i].as<Var>()) {
diff --git a/src/s_tir/schedule/primitive/cache_read_write.cc
b/src/s_tir/schedule/primitive/cache_read_write.cc
index c9ddf02bbd..ec390833ef 100644
--- a/src/s_tir/schedule/primitive/cache_read_write.cc
+++ b/src/s_tir/schedule/primitive/cache_read_write.cc
@@ -412,10 +412,10 @@ SBlock MakeReIndexStage(const SBlock& block,
CacheStageInfo* info,
// Step 3: Create the reindex block
// The src and the dst region and indices of the data copy
- ffi::Array<Range> src_region{nullptr};
- ffi::Array<Range> dst_region{nullptr};
- ffi::Array<PrimExpr> src_indices{nullptr};
- ffi::Array<PrimExpr> dst_indices{nullptr};
+ ffi::Array<Range> src_region;
+ ffi::Array<Range> dst_region;
+ ffi::Array<PrimExpr> src_indices;
+ ffi::Array<PrimExpr> dst_indices;
if (tensor_index_type == TensorIndexType::kWrite) {
src_indices = reindex_indices;
diff --git a/src/s_tir/schedule/primitive/compute_inline.cc
b/src/s_tir/schedule/primitive/compute_inline.cc
index 5a7c37654c..9535a7c0bd 100644
--- a/src/s_tir/schedule/primitive/compute_inline.cc
+++ b/src/s_tir/schedule/primitive/compute_inline.cc
@@ -992,7 +992,7 @@ class ReverseComputeInliner : public BaseInliner {
/*! \brief The indices of the consumer's TensorLoad */
ffi::Array<PrimExpr> tensor_load_indices_;
/*! \brief The IterMap representing the indices of the consumer's TensorLoad
*/
- ffi::Array<sym::IterSumExpr> tensor_load_iter_map_{nullptr};
+ ffi::Array<sym::IterSumExpr> tensor_load_iter_map_;
/*! \brief The producer block */
const SBlockNode* producer_block_{nullptr};
/* \brief The consumer block */
@@ -1184,11 +1184,11 @@ class ReductionEpilogueFuser : public BaseInliner {
ffi::UnsafeInit{}}; // The entire epilogue expression (e.g., temp + C,
max(temp + C, 0))
const TensorLoadNode* reduction_tensor_load_{
nullptr}; // The reduction tensor load in epilogue expression
- TensorVar epilogue_output_tensor_{ffi::UnsafeInit{}}; // Output tensor D
- ffi::Array<PrimExpr> epilogue_output_indices_{nullptr}; // Indices of D[vi,
vj]
- ffi::Optional<TensorRegion> epilogue_output_region_; // Write region of D
- ffi::Optional<TensorVar> epilogue_addend_tensor_; // Additional tensor
(e.g., bias tensor C)
- ffi::Optional<TensorRegion> epilogue_addend_region_; // Read region of
additional tensor
+ TensorVar epilogue_output_tensor_{ffi::UnsafeInit{}}; // Output tensor D
+ ffi::Array<PrimExpr> epilogue_output_indices_; // Indices of D[vi,
vj]
+ ffi::Optional<TensorRegion> epilogue_output_region_; // Write region of D
+ ffi::Optional<TensorVar> epilogue_addend_tensor_; // Additional tensor
(e.g., bias tensor C)
+ ffi::Optional<TensorRegion> epilogue_addend_region_; // Read region of
additional tensor
};
bool ReductionEpilogueFuser::BodyPatternAllowFusion(const SBlockRealize&
epilogue_block_realize) {
diff --git a/src/s_tir/schedule/primitive/reduction.cc
b/src/s_tir/schedule/primitive/reduction.cc
index 48ea0d6f42..21664a0f0a 100644
--- a/src/s_tir/schedule/primitive/reduction.cc
+++ b/src/s_tir/schedule/primitive/reduction.cc
@@ -1407,11 +1407,11 @@ StmtSRef RFactor(ScheduleState self, const StmtSRef&
rf_loop_sref, int factor_ax
// commutative reducer, combiner lhs and combiner rhs from the reduction
identity and the
// reduction combiner. The lhs will be used when constructing the write-back
block, and the rhs
// will be used when constructing the rfactor block.
- ffi::Array<PrimExpr> init_values{nullptr};
- ffi::Array<TensorStore> updates{nullptr};
+ ffi::Array<PrimExpr> init_values;
+ ffi::Array<TensorStore> updates;
te::CommReducer reducer{ffi::UnsafeInit{}};
- ffi::Array<PrimExpr> combiner_lhs{nullptr};
- ffi::Array<PrimExpr> combiner_rhs{nullptr};
+ ffi::Array<PrimExpr> combiner_lhs;
+ ffi::Array<PrimExpr> combiner_rhs;
std::tie(init_values, updates) =
GetInitValuesAndUpdatesFromReductionBlock(self, block);
std::tie(reducer, combiner_lhs, combiner_rhs) =
GetReducerAndCombinerLhsRhs(self, init_values, updates);
diff --git a/src/s_tir/schedule/trace.cc b/src/s_tir/schedule/trace.cc
index ce55106e79..3553c89017 100644
--- a/src/s_tir/schedule/trace.cc
+++ b/src/s_tir/schedule/trace.cc
@@ -554,7 +554,7 @@ void Trace::ApplyJSONToSchedule(ffi::ObjectRef json,
Schedule sch) {
InstructionKind kind{ffi::UnsafeInit{}};
ffi::Array<Any> inputs{nullptr};
ffi::Array<Any> attrs{nullptr};
- ffi::Array<ffi::String> outputs{ffi::ObjectPtr<ffi::Object>{nullptr}};
+ ffi::Array<ffi::String> outputs;
// Parse the entry
try {
const auto* arr = inst_entry.as<ffi::ArrayObj>();
diff --git a/src/s_tir/script/ir_builder/ir.cc
b/src/s_tir/script/ir_builder/ir.cc
index eb56c1df36..c12630d734 100644
--- a/src/s_tir/script/ir_builder/ir.cc
+++ b/src/s_tir/script/ir_builder/ir.cc
@@ -294,12 +294,12 @@ ffi::Array<Var> Remap(ffi::String kinds,
ffi::Array<PrimExpr> bindings, PrimType
break;
}
}
- if (dom.defined()) {
+ if (dom.has_value()) {
break;
}
}
}
- TVM_FFI_ICHECK(dom.defined()) << "TypeError: Variable is not in the loop:
" << v.value();
+ TVM_FFI_ICHECK(dom.has_value()) << "TypeError: Variable is not in the
loop: " << v.value();
PrimType dtype = v.value().ty();
if (c == 'S') {
results.push_back(PushBlockVar(IterVar(/*dom=*/dom,
diff --git a/src/s_tir/transform/lower_cross_thread_reduction.cc
b/src/s_tir/transform/lower_cross_thread_reduction.cc
index bad7176fe3..d8b8a5301e 100644
--- a/src/s_tir/transform/lower_cross_thread_reduction.cc
+++ b/src/s_tir/transform/lower_cross_thread_reduction.cc
@@ -444,9 +444,9 @@ Stmt TransformReductionBlock(const SBlockRealizeNode*
realize,
tvm::Tuple(destinations),
tvm::Tuple(thread_axes)};
// Step 3.2. Create the block and the block-realize.
- ffi::Array<IterVar> iter_vars{nullptr};
- ffi::Array<PrimExpr> bindings{nullptr};
- ffi::Array<TensorRegion> reads{nullptr};
+ ffi::Array<IterVar> iter_vars;
+ ffi::Array<PrimExpr> bindings;
+ ffi::Array<TensorRegion> reads;
if (it_tensors.has_value()) {
iter_vars = ffi::Array<IterVar>{};
bindings = ffi::Array<PrimExpr>{};
@@ -740,11 +740,11 @@ class CrossThreadReductionTransformer : public
StmtExprMutator {
// Condition 3. Get the identity values of the block init and the
TensorStore block combiner
// updates of the reduction. Extract the commutative reducer, combiner lhs
and combiner rhs from
// the reduction identities and the reduction combiner.
- ffi::Array<PrimExpr> init_values{nullptr};
- ffi::Array<TensorStore> updates{nullptr};
+ ffi::Array<PrimExpr> init_values;
+ ffi::Array<TensorStore> updates;
te::CommReducer reducer{ffi::UnsafeInit{}};
- ffi::Array<PrimExpr> combiner_lhs{nullptr};
- ffi::Array<PrimExpr> combiner_rhs{nullptr};
+ ffi::Array<PrimExpr> combiner_lhs;
+ ffi::Array<PrimExpr> combiner_rhs;
std::tie(init_values, updates) =
GetInitValuesAndUpdatesFromReductionBlock(std::nullopt,
ffi::GetRef<SBlock>(block));
std::tie(reducer, combiner_lhs, combiner_rhs) =
@@ -876,9 +876,9 @@ class CrossThreadReductionTransformer : public
StmtExprMutator {
// which condition the block violates.
int n_bound_reduction_loops = 0;
te::CommReducer reducer{ffi::UnsafeInit{}};
- ffi::Array<TensorVar> reduction_tensors{nullptr};
- ffi::Array<PrimExpr> combiner_rhs{nullptr};
- ffi::Array<PrimExpr> wb_indices{nullptr};
+ ffi::Array<TensorVar> reduction_tensors;
+ ffi::Array<PrimExpr> combiner_rhs;
+ ffi::Array<PrimExpr> wb_indices;
std::tie(n_bound_reduction_loops, reducer, reduction_tensors,
combiner_rhs, wb_indices) =
CheckCanApplyCrossThreadReduction(block, reduction_loops);
// Step 2. Before doing the cross-thread reduction, in-thread reduction is
needed when
diff --git a/src/script/printer/ir/call.cc b/src/script/printer/ir/call.cc
index eea3121c7b..d0ee48dfca 100644
--- a/src/script/printer/ir/call.cc
+++ b/src/script/printer/ir/call.cc
@@ -43,8 +43,8 @@ ffi::Optional<ExprDoc>
StandardCallDocTranslate(DocTranslatorObj* d, const CallN
static const auto& names =
Op::GetAttrMap<TScriptPrinterName>(tvm::script::printer::op_attr::kScriptPrinterName);
if (!names.count(op) || names[op].empty()) return std::nullopt;
- if (call->attrs.defined() ? op->attrs_type_key != call->attrs->GetTypeKey()
- : !op->attrs_type_key.empty()) {
+ if (call->attrs.has_value() ? op->attrs_type_key != call->attrs->GetTypeKey()
+ : !op->attrs_type_key.empty()) {
return RawCall(d, call);
}
ffi::Array<ExprDoc> args;
@@ -60,17 +60,17 @@ ffi::Optional<ExprDoc>
StandardCallDocTranslate(DocTranslatorObj* d, const CallN
values.push_back(ListDoc(types));
}
bool default_attrs = false;
- if (call->attrs.defined() && call->attrs.value().as<DictAttrsNode>()) {
+ if (call->attrs.has_value() && call->attrs.value().as<DictAttrsNode>()) {
default_attrs = call->attrs.value().as_or_throw<DictAttrs>()->dict.empty();
if (!default_attrs) {
keys.push_back("attrs");
values.push_back(d->Translate(call->attrs.value()).value());
}
- } else if (call->attrs.defined()) {
+ } else if (call->attrs.has_value()) {
std::vector<std::pair<ffi::String, ffi::Any>> fields;
ffi::reflection::ForEachFieldInfo(
TVMFFIGetTypeInfo(call->attrs->type_index()), [&](const
TVMFFIFieldInfo* field) {
- ffi::Any value = ffi::reflection::FieldGetter(field)(call->attrs);
+ ffi::Any value =
ffi::reflection::FieldGetter(field)(call->attrs.value());
// Factory defaults can have effects or change between constructions.
// Only a reflected literal default is safe to omit here.
if ((field->flags & kTVMFFIFieldFlagBitMaskHasDefault) &&
diff --git a/src/script/printer/ir/utils.cc b/src/script/printer/ir/utils.cc
index 0311002c93..e34fd5d2a9 100644
--- a/src/script/printer/ir/utils.cc
+++ b/src/script/printer/ir/utils.cc
@@ -169,7 +169,7 @@ ExprDoc RawCall(DocTranslatorObj* d, const CallNode* call,
:
d->Translate(call->op).value();
ffi::Array<ffi::String> keys;
ffi::Array<ExprDoc> values;
- if (call->attrs.defined()) {
+ if (call->attrs.has_value()) {
keys.push_back("attrs");
values.push_back(CallAttrsValue(d, call->attrs.value()));
}
diff --git a/src/sym/int_set.cc b/src/sym/int_set.cc
index 6008c57c0c..beb21d9f58 100644
--- a/src/sym/int_set.cc
+++ b/src/sym/int_set.cc
@@ -1169,7 +1169,7 @@ ffi::Optional<ffi::Array<IntSet>>
EstimateRegionStrictBound(const ffi::Array<Ran
}
AnalyzerObj* analyzer_ptr = analyzer.get();
int ndim = region.size();
- ffi::Array<IterSumExpr> iter_sum_exprs{nullptr};
+ ffi::Array<IterSumExpr> iter_sum_exprs;
{
ffi::Array<PrimExpr> affine_indices;
affine_indices.reserve(ndim);
diff --git a/src/sym/iter_affine_map.cc b/src/sym/iter_affine_map.cc
index 657b0e881a..1c1bf7a880 100644
--- a/src/sym/iter_affine_map.cc
+++ b/src/sym/iter_affine_map.cc
@@ -1895,7 +1895,7 @@ std::optional<std::pair<IterSplitExpr, PrimExpr>>
IterMapRewriter::PadDividendTo
<< "The padding factor " << info.padding_factor << " is not divisible by
" << divisor
<< " for the split " << split;
- if (!info.padded.defined()) {
+ if (!info.padded.has_value()) {
// the first time encounter the iter mark to pad, update the padded mark.
PrimExpr mark_left_pad = info.left_pad;
if (CanProveDivisible(mark_left_pad, split->lower_factor)) {
diff --git a/src/target/llvm/codegen_aarch64.cc
b/src/target/llvm/codegen_aarch64.cc
index 4eb15e47ce..49e698e8a2 100644
--- a/src/target/llvm/codegen_aarch64.cc
+++ b/src/target/llvm/codegen_aarch64.cc
@@ -115,7 +115,7 @@ void CodeGenAArch64::SetTargetAttributes(llvm::Function*
func) {
static auto llvm_get_vector_width_fn =
tvm::ffi::Function::GetGlobalRequired("target.llvm_get_vector_width");
unsigned int max_val = 0;
- if (auto target = Target::Current(); target.defined()) {
+ if (auto target = Target::Current(); target.has_value()) {
unsigned int vector_width =
static_cast<unsigned
int>(llvm_get_vector_width_fn(target).cast<int>());
for (unsigned int i = 0;; ++i) {
diff --git a/src/target/llvm/codegen_cpu.cc b/src/target/llvm/codegen_cpu.cc
index 0f0f570429..8675302994 100644
--- a/src/target/llvm/codegen_cpu.cc
+++ b/src/target/llvm/codegen_cpu.cc
@@ -1178,8 +1178,8 @@ void CodeGenCPU::Dispatch_(const ForNode* op) {
std::string("loop_parallel_") +
op->loop_var->name.c_str());
} else {
// already in parallel env.
- TVM_FFI_ICHECK(parallel_env_.task_id.defined());
- TVM_FFI_ICHECK(parallel_env_.num_task.defined());
+ TVM_FFI_ICHECK(parallel_env_.task_id.has_value());
+ TVM_FFI_ICHECK(parallel_env_.num_task.has_value());
TVM_FFI_ICHECK(parallel_env_.penv != nullptr);
PrimType t(op->extent.ty()->dtype);
PrimExpr num_task = cast(t,
parallel_env_.num_task.value().as_or_throw<PrimExpr>());
diff --git a/src/target/llvm/llvm_module.cc b/src/target/llvm/llvm_module.cc
index bc09d60050..15b47b6f7d 100644
--- a/src/target/llvm/llvm_module.cc
+++ b/src/target/llvm/llvm_module.cc
@@ -421,7 +421,7 @@ static void LLVMReflectionRegister() {
[](const ffi::Optional<Target>& target) -> int {
auto use_target = target.has_value() ? target.value() :
Target::Current(false).value();
// ignore non "llvm" target
- if (target.defined()) {
+ if (target.has_value()) {
if (target.value()->kind->name != "llvm") {
return -1;
}
@@ -444,7 +444,7 @@ static void LLVMReflectionRegister() {
[](const ffi::Optional<Target>& target) -> ffi::Array<ffi::String> {
auto use_target = target.has_value() ? target.value() :
Target::Current(false).value();
// ignore non "llvm" target
- if (target.defined()) {
+ if (target.has_value()) {
if (target.value()->kind->name != "llvm") {
return ffi::Array<ffi::String>{};
}
@@ -457,7 +457,7 @@ static void LLVMReflectionRegister() {
[](const ffi::Optional<Target>& target) -> ffi::Map<ffi::String,
ffi::String> {
auto use_target = target.has_value() ? target.value() :
Target::Current(false).value();
// ignore non "llvm" target
- if (target.defined()) {
+ if (target.has_value()) {
if (target.value()->kind->name != "llvm") {
return {};
}
@@ -470,7 +470,7 @@ static void LLVMReflectionRegister() {
[](const ffi::String feature, const ffi::Optional<Target>& target)
-> bool {
auto use_target = target.has_value() ? target.value() :
Target::Current(false).value();
// ignore non "llvm" target
- if (target.defined()) {
+ if (target.has_value()) {
if (target.value()->kind->name != "llvm") {
return false;
}
@@ -485,7 +485,7 @@ static void LLVMReflectionRegister() {
[](const ffi::String feature, const ffi::Optional<Target>& target)
-> bool {
auto use_target = target.has_value() ? target.value() :
Target::Current(false).value();
// ignore non "llvm" target
- if (target.defined()) {
+ if (target.has_value()) {
if (target.value()->kind->name != "llvm") {
return false;
}
diff --git a/src/target/target.cc b/src/target/target.cc
index 9c0052c10e..d1320b4cef 100644
--- a/src/target/target.cc
+++ b/src/target/target.cc
@@ -51,7 +51,8 @@ class TargetInternal {
static void ConstructorDispatcher(ffi::PackedArgs args, ffi::Any* rv);
static Target WithHost(const Target& target, const ffi::Optional<Target>&
target_host) {
ffi::ObjectPtr<TargetObj> n = ffi::make_object<TargetObj>(*target.get());
- n->host = target_host;
+ n->host =
+ target_host.has_value() ?
ffi::Optional<ffi::ObjectRef>(target_host.value()) : std::nullopt;
return Target(ffi::UnsafeInit{}, std::move(n));
}
@@ -126,7 +127,8 @@ Target::Target(const ffi::Map<ffi::String, ffi::Any>&
config) {
Target::Target(Target target, ffi::Optional<Target> host) {
ffi::ObjectPtr<TargetObj> n = ffi::make_object<TargetObj>(*target.get());
- n->host = std::move(host);
+ n->host =
+ host.has_value() ?
ffi::Optional<ffi::ObjectRef>(std::move(host).value()) : std::nullopt;
data_ = std::move(n);
}
diff --git a/src/te/operation/create_function.cc
b/src/te/operation/create_function.cc
index 6a14afe5eb..18e6b9b568 100644
--- a/src/te/operation/create_function.cc
+++ b/src/te/operation/create_function.cc
@@ -109,9 +109,9 @@ class TensorLoadToTensorTransformer : public
s_tir::StmtExprMutator {
}
s_tir::IterVar NormalizeAxisDomain(const s_tir::IterVar& axis) {
- if (!axis->dom.defined()) return axis;
+ if (!axis->dom.has_value()) return axis;
auto domain = Mutate(axis->dom).ValueOrUnchanged(axis->dom).cast<Range>();
- if (domain.same_as(axis->dom)) return axis;
+ if (axis->dom.same_as(domain)) return axis;
auto copy = ffi::make_object<s_tir::IterVarNode>(*axis.get());
copy->dom = std::move(domain);
return s_tir::IterVar(std::move(copy));
diff --git a/src/te/operation/graph.cc b/src/te/operation/graph.cc
index de65f7967b..ea9301cf86 100644
--- a/src/te/operation/graph.cc
+++ b/src/te/operation/graph.cc
@@ -53,7 +53,7 @@ ReadGraph CreateReadGraph(const ffi::Array<Operation>& roots)
{
ffi::Array<Tensor> deps = op->InputTensors();
rmap.Set(op, deps);
for (Tensor t : deps) {
- if (t->op.defined() && visited.count(t->op.value().get()) == 0) {
+ if (t->op.has_value() && visited.count(t->op.value().get()) == 0) {
visited.insert(t->op.value().get());
stack.push_back(t->op.value());
}
diff --git a/src/tirx/ir/layout/tile_canonicalize.cc
b/src/tirx/ir/layout/tile_canonicalize.cc
index b3bd9f437b..c22a118048 100644
--- a/src/tirx/ir/layout/tile_canonicalize.cc
+++ b/src/tirx/ir/layout/tile_canonicalize.cc
@@ -83,7 +83,7 @@ TileLayout FuseAxesByScope(TileLayout layout) {
// Step 1: Get the target and scope information
auto scope_pair_opt = layout->GetScope();
ffi::Optional<Target> target = Target::Current();
- if (!scope_pair_opt.has_value() || !target.defined()) {
+ if (!scope_pair_opt.has_value() || !target.has_value()) {
return layout;
}
auto subscope = scope_pair_opt.value().get<0>()->name();
diff --git a/src/tirx/ir/layout/tile_tile_ops.cc
b/src/tirx/ir/layout/tile_tile_ops.cc
index ad4d35d516..8b23b5de44 100644
--- a/src/tirx/ir/layout/tile_tile_ops.cc
+++ b/src/tirx/ir/layout/tile_tile_ops.cc
@@ -429,7 +429,7 @@ std::vector<int64_t>
EvenSeparatorIndices(std::vector<int64_t> seps) {
// Split axes according to a split scope on the target.
TileLayout SplitAxesByScope(TileLayout layout, const ffi::String& split_scope)
{
ffi::Optional<Target> target = Target::Current();
- if (!target.defined()) {
+ if (!target.has_value()) {
return layout;
}
auto split_iter = [&](const Iter& iter) -> ffi::Array<Iter> {
diff --git a/src/tirx/op/memory.cc b/src/tirx/op/memory.cc
index f61af69314..ed590a2937 100644
--- a/src/tirx/op/memory.cc
+++ b/src/tirx/op/memory.cc
@@ -108,10 +108,10 @@ void ValidateTensorProducer(const CallNode* call) {
TVM_FFI_CHECK(ffi::StructuralEqual()(call->ty, inferred), TypeError)
<< "Tensor producer result must match its TensorType argument";
if constexpr (is_alloc) {
- TVM_FFI_CHECK(!call->attrs.defined() || call->attrs.as<DictAttrsNode>(),
ValueError)
+ TVM_FFI_CHECK(!call->attrs.has_value() || call->attrs.as<DictAttrsNode>(),
ValueError)
<< "alloc_tensor annotations must be DictAttrs";
} else {
- TVM_FFI_CHECK(!call->attrs.defined(), ValueError) << "decl_tensor does not
accept attributes";
+ TVM_FFI_CHECK(!call->attrs.has_value(), ValueError) << "decl_tensor does
not accept attributes";
}
}
diff --git a/src/tirx/script/printer/expr.cc b/src/tirx/script/printer/expr.cc
index 3394d55aef..d218f70f17 100644
--- a/src/tirx/script/printer/expr.cc
+++ b/src/tirx/script/printer/expr.cc
@@ -79,7 +79,7 @@ ffi::Optional<ExprDoc>
LLVMIntrinsicDocTranslate(DocTranslatorObj* d, ffi::AnyVi
const ffi::Object*) {
const auto* call =
ffi::details::AnyUnsafe::RawObjectPtrFromAnyViewAfterCheck<const
CallNode>(input);
- if (call->attrs.defined() || !call->ty_args.empty() || call->args.empty() ||
+ if (call->attrs.has_value() || !call->ty_args.empty() || call->args.empty()
||
!call->ty.as<PrimType>()) {
return RawCall(d, call);
}
@@ -130,7 +130,7 @@ bool IsPTXAddressCall(const CallNode* call) {
}
ffi::Optional<ExprDoc> ConsumedPTXAddressDocTranslate(DocTranslatorObj* d,
const CallNode* call) {
- if (call->args.size() != 2 || call->attrs.defined() ||
!call->ty_args.empty())
+ if (call->args.size() != 2 || call->attrs.has_value() ||
!call->ty_args.empty())
return std::nullopt;
const Expr& base = call->args[0];
const Expr& offset = call->args[1];
@@ -168,7 +168,7 @@ ffi::Optional<ExprDoc>
TensorDataPtrDocTranslate(DocTranslatorObj* d, ffi::AnyVi
const ffi::Object*) {
const auto* call =
ffi::details::AnyUnsafe::RawObjectPtrFromAnyViewAfterCheck<const
CallNode>(input);
- if (call->attrs.defined() || !call->ty_args.empty() || call->args.size() !=
1)
+ if (call->attrs.has_value() || !call->ty_args.empty() || call->args.size()
!= 1)
return RawCall(d, call);
try {
if (!ffi::StructuralEqual()(Call::ReinferType(call), call->ty)) return
RawCall(d, call);
@@ -184,7 +184,7 @@ ffi::Optional<ExprDoc>
PTXCallDocTranslate(DocTranslatorObj* d, ffi::AnyView inp
const ffi::Object*) {
const auto* call =
ffi::details::AnyUnsafe::RawObjectPtrFromAnyViewAfterCheck<const
CallNode>(input);
- if (IsPTXAddressCall(call) || call->attrs.defined() ||
!call->ty_args.empty() ||
+ if (IsPTXAddressCall(call) || call->attrs.has_value() ||
!call->ty_args.empty() ||
!ffi::StructuralEqual()(call->ty, PrimType::Void()))
return RawCall(d, call);
const Op& op = call->op.as_or_throw<Op>();
diff --git a/src/tirx/tile/op.cc b/src/tirx/tile/op.cc
index fabef5688a..f6bb1235e9 100644
--- a/src/tirx/tile/op.cc
+++ b/src/tirx/tile/op.cc
@@ -199,7 +199,8 @@ ffi::Expected<void> ValidateTensorInstruction(const
CallNode* call) noexcept try
<< op->name << " has an invalid operand count";
TVM_FFI_CHECK(call->ty == PrimType::Void(), TypeError) << op->name << " must
return void";
TVM_FFI_CHECK(call->ty_args.empty(), TypeError) << op->name << " does not
take type arguments";
- TVM_FFI_CHECK(call->attrs.defined() && call->attrs->GetTypeKey() ==
op->attrs_type_key, TypeError)
+ TVM_FFI_CHECK(call->attrs.has_value() && call->attrs->GetTypeKey() ==
op->attrs_type_key,
+ TypeError)
<< op->name << " requires its registered static attributes";
static const auto& validators =
Op::GetAttrMap<ffi::Function>(op_attr::kTensorCallValidate);
validators[op](ffi::GetRef<Call>(call));
diff --git a/src/tirx/transform/storage_rewrite.cc
b/src/tirx/transform/storage_rewrite.cc
index 81fbaec14d..4094f7e84d 100644
--- a/src/tirx/transform/storage_rewrite.cc
+++ b/src/tirx/transform/storage_rewrite.cc
@@ -962,7 +962,7 @@ class StoragePlanRewriter : public StmtExprMutator {
}
// transform to bits
auto sz_nbits = sz * nbits;
- if (max_size.defined()) {
+ if (max_size.has_value()) {
max_size = max(max_size.value(), sz_nbits);
} else {
max_size = sz_nbits;
diff --git a/src/tirx/transform/vectorize_loop.cc
b/src/tirx/transform/vectorize_loop.cc
index 51f7c91130..945358218b 100644
--- a/src/tirx/transform/vectorize_loop.cc
+++ b/src/tirx/transform/vectorize_loop.cc
@@ -67,7 +67,7 @@ bool IsVScaleCall(const PrimExpr& expr) {
}
bool TargetHasRVV(ffi::Optional<Target> target) {
- if (!target.defined()) return false;
+ if (!target.has_value()) return false;
static auto target_has_feature_fn =
tvm::ffi::Function::GetGlobal("target.target_has_feature");
return target_has_feature_fn.has_value() && (*target_has_feature_fn)("v",
target).cast<bool>();
}
@@ -75,7 +75,7 @@ bool TargetHasRVV(ffi::Optional<Target> target) {
// File-local helper: true if the target supports Variable-Length Array
extensions
// (AArch64 SVE or RISC-V V).
bool TargetHasVLA(ffi::Optional<Target> target) {
- if (!target.defined()) return false;
+ if (!target.has_value()) return false;
bool has_vla =
target.value()->GetAttr<bool>("feature.has_sve").value_or(false);
if (!has_vla) {
if (auto mattr =
target.value()->GetAttr<ffi::Array<ffi::String>>("mattr")) {