This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch refactor-s0
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit cc061117c039e7bb77ad943b9b035d22d31c2cc1
Author: tqchen <[email protected]>
AuthorDate: Sun Mar 9 19:39:58 2025 -0400

    Pass compile
---
 ffi/include/tvm/ffi/object.h      | 20 ++++++++++++++++++--
 ffi/include/tvm/ffi/reflection.h  |  9 +++++++++
 ffi/src/ffi/object.cc             |  1 +
 include/tvm/ir/attrs.h            |  2 +-
 include/tvm/ir/expr.h             |  1 +
 include/tvm/ir/op.h               |  4 ++--
 include/tvm/relax/block_builder.h |  1 -
 include/tvm/relax/exec_builder.h  |  1 -
 include/tvm/relax/tir_pattern.h   |  2 +-
 include/tvm/target/target_kind.h  |  2 +-
 include/tvm/tir/function.h        |  2 +-
 python/setup.py                   |  3 ++-
 src/target/llvm/llvm_module.cc    |  2 +-
 src/tir/ir/stmt_functor.cc        |  2 +-
 tests/cpp/container_test.cc       |  1 -
 tests/cpp/object_protocol_test.cc |  4 ----
 16 files changed, 39 insertions(+), 18 deletions(-)

diff --git a/ffi/include/tvm/ffi/object.h b/ffi/include/tvm/ffi/object.h
index b9e5df51d1..d4f4544cd6 100644
--- a/ffi/include/tvm/ffi/object.h
+++ b/ffi/include/tvm/ffi/object.h
@@ -127,6 +127,15 @@ class Object {
     return type_info->type_key;
   }
 
+  /*!
+   * \return A hash value of the return of GetTypeKey.
+   */
+  uint64_t GetTypeKeyHash() const {
+    // the function checks that the info exists
+    const TypeInfo* type_info = TVMFFIGetTypeInfo(header_.type_index);
+    return type_info->type_key_hash;
+  }
+
   /*!
    * \brief Get the type key of the corresponding index from runtime.
    * \param tindex The type index.
@@ -137,6 +146,8 @@ class Object {
     return type_info->type_key;
   }
 
+  bool unique() const { return use_count() == 1; }
+
   // Information about the object
   static constexpr const char* _type_key = "object.Object";
 
@@ -148,6 +159,11 @@ class Object {
   static constexpr int32_t _type_index = TypeIndex::kTVMFFIObject;
   // the static type depth of the class
   static constexpr int32_t _type_depth = 0;
+  // extra fields used by plug-ins for attribute visiting
+  // and structural information
+  static constexpr const bool _type_has_method_visit_attrs = true;
+  static constexpr const bool _type_has_method_sequal_reduce = false;
+  static constexpr const bool _type_has_method_shash_reduce = false;
   // The following functions are provided by macro
   // TVM_FFI_DECLARE_BASE_OBJECT_INFO and TVM_DECLARE_FINAL_OBJECT_INFO
   /*!
@@ -449,7 +465,7 @@ struct ObjectPtrEqual {
  */
 #define TVM_FFI_DECLARE_STATIC_OBJECT_INFO(TypeName, ParentType)      \
   static int32_t RuntimeTypeIndex() { return TypeName::_type_index; } \
-  TVM_FFI_REGISTER_STATIC_TYPE_INFO(TypeName, ParentType);
+  TVM_FFI_REGISTER_STATIC_TYPE_INFO(TypeName, ParentType)
 
 /*
  * \brief Define object reference methods.
@@ -649,7 +665,7 @@ class ObjectUnsafe {
     return ptr;
   }
 
-  static TVM_FFI_INLINE Object** GetObjectRValueRefValue(ObjectRef* ref) {
+  static TVM_FFI_INLINE Object** GetObjectRValueRefValue(const ObjectRef* ref) 
{
     return const_cast<Object**>(&(ref->data_.data_));
   }
 
diff --git a/ffi/include/tvm/ffi/reflection.h b/ffi/include/tvm/ffi/reflection.h
index b29b3d919f..64a0e21d0e 100644
--- a/ffi/include/tvm/ffi/reflection.h
+++ b/ffi/include/tvm/ffi/reflection.h
@@ -148,6 +148,15 @@ class ReflectionFieldGetter {
 
 }  // namespace details
 
+/*!
+ * \brief helper function to get type index from key
+ */
+inline int32_t TypeKey2Index(const char* type_key) {
+  int32_t type_index;
+  TVM_FFI_CHECK_SAFE_CALL(TVMFFITypeKey2Index(type_key, &type_index));
+  return type_index;
+}
+
 /*!
  * \brief helper macro to declare a base object type that can be inherited.
  * \param TypeName The name of the current type.
diff --git a/ffi/src/ffi/object.cc b/ffi/src/ffi/object.cc
index 1cf37ac448..fbbc1993fd 100644
--- a/ffi/src/ffi/object.cc
+++ b/ffi/src/ffi/object.cc
@@ -259,6 +259,7 @@ int TVMFFITypeKey2Index(const char* type_key, int32_t* 
out_tindex) {
   TVM_FFI_SAFE_CALL_BEGIN();
   out_tindex[0] = tvm::ffi::TypeTable::Global()->TypeKey2Index(type_key);
   TVM_FFI_SAFE_CALL_END();
+
 }
 
 int TVMFFIRegisterTypeField(int32_t type_index, const TVMFFIFieldInfo* info) {
diff --git a/include/tvm/ir/attrs.h b/include/tvm/ir/attrs.h
index d038d5f59a..479cc476bf 100644
--- a/include/tvm/ir/attrs.h
+++ b/include/tvm/ir/attrs.h
@@ -65,7 +65,7 @@ namespace tvm {
  */
 #define TVM_DECLARE_ATTRS(ClassName, TypeKey)                    \
   static constexpr const char* _type_key = TypeKey;              \
-  TVM_DECLARE_FINAL_OBJECT_INFO(ClassName, ::tvm::BaseAttrsNode) \
+  TVM_DECLARE_FINAL_OBJECT_INFO(ClassName, ::tvm::BaseAttrsNode);\
   template <typename FVisit>                                     \
   void _tvm_VisitAttrs(FVisit& _tvm_fvisit)  // NOLINT(*)
 
diff --git a/include/tvm/ir/expr.h b/include/tvm/ir/expr.h
index b3b4e8ab32..7abd07c547 100644
--- a/include/tvm/ir/expr.h
+++ b/include/tvm/ir/expr.h
@@ -56,6 +56,7 @@ class BaseExprNode : public Object {
   mutable Span span;
 
   static constexpr const char* _type_key = "BaseExpr";
+  static constexpr const bool _type_has_method_visit_attrs = true;
   static constexpr const bool _type_has_method_sequal_reduce = true;
   static constexpr const bool _type_has_method_shash_reduce = true;
   static constexpr const uint32_t _type_child_slots = 62;
diff --git a/include/tvm/ir/op.h b/include/tvm/ir/op.h
index 7fbd1cbb84..b8dd3495cd 100644
--- a/include/tvm/ir/op.h
+++ b/include/tvm/ir/op.h
@@ -160,7 +160,7 @@ class Op : public RelaxExpr {
    */
   TVM_DLL static const Op& Get(const String& op_name);
 
-  TVM_DEFINE_OBJECT_REF_METHODS(Op, RelaxExpr, OpNode)
+  TVM_DEFINE_OBJECT_REF_METHODS(Op, RelaxExpr, OpNode);
 
  private:
   /*!
@@ -359,7 +359,7 @@ inline OpRegEntry& OpRegEntry::set_attrs_type() {  // 
NOLINT(*)
 
 inline OpRegEntry& OpRegEntry::set_attrs_type_key(const String& key) {  // 
NOLINT(*)
   get()->attrs_type_key = key;
-  get()->attrs_type_index = Object::TypeKey2Index(key);
+  get()->attrs_type_index = tvm::ffi::TypeKey2Index(key.c_str());
   return *this;
 }
 
diff --git a/include/tvm/relax/block_builder.h 
b/include/tvm/relax/block_builder.h
index 070aef2fcb..5efe91a5e4 100644
--- a/include/tvm/relax/block_builder.h
+++ b/include/tvm/relax/block_builder.h
@@ -257,7 +257,6 @@ class BlockBuilderNode : public Object {
    */
   virtual arith::Analyzer* GetAnalyzer() = 0;
 
-  static constexpr const uint32_t _type_index = TypeIndex::kDynamic;
   static constexpr const char* _type_key = "relax.BlockBuilder";
   TVM_DECLARE_BASE_OBJECT_INFO(BlockBuilderNode, Object);
 };
diff --git a/include/tvm/relax/exec_builder.h b/include/tvm/relax/exec_builder.h
index 8940408f80..c5103719d0 100644
--- a/include/tvm/relax/exec_builder.h
+++ b/include/tvm/relax/exec_builder.h
@@ -139,7 +139,6 @@ class ExecBuilderNode : public Object {
 
   void VisitAttrs(AttrVisitor* v) {}
 
-  static constexpr const uint32_t _type_index = TypeIndex::kDynamic;
   static constexpr const char* _type_key = "relax.ExecBuilder";
   TVM_DECLARE_FINAL_OBJECT_INFO(ExecBuilderNode, Object);
 
diff --git a/include/tvm/relax/tir_pattern.h b/include/tvm/relax/tir_pattern.h
index 02634dcbbf..1b29cb0358 100644
--- a/include/tvm/relax/tir_pattern.h
+++ b/include/tvm/relax/tir_pattern.h
@@ -66,7 +66,7 @@ class MatchResult : public ObjectRef {
   TVM_DLL explicit MatchResult(TIRPattern pattern, Array<PrimExpr> 
symbol_values,
                                Array<tir::Buffer> matched_buffers);
 
-  TVM_DEFINE_OBJECT_REF_METHODS(MatchResult, ObjectRef, MatchResultNode)
+  TVM_DEFINE_OBJECT_REF_METHODS(MatchResult, ObjectRef, MatchResultNode);
 };
 
 using FCodegen = runtime::TypedPackedFunc<Array<ObjectRef>(Array<MatchResult> 
match_results)>;
diff --git a/include/tvm/target/target_kind.h b/include/tvm/target/target_kind.h
index f398736c73..7cb88251f3 100644
--- a/include/tvm/target/target_kind.h
+++ b/include/tvm/target/target_kind.h
@@ -92,7 +92,7 @@ class TargetKindNode : public Object {
   /*! \brief Stores the required type_key and type_index of a specific attr of 
a target */
   struct ValueTypeInfo {
     String type_key;
-    uint32_t type_index;
+    int32_t type_index;
     std::unique_ptr<ValueTypeInfo> key;
     std::unique_ptr<ValueTypeInfo> val;
   };
diff --git a/include/tvm/tir/function.h b/include/tvm/tir/function.h
index e90c49fc4f..fbd61e7a38 100644
--- a/include/tvm/tir/function.h
+++ b/include/tvm/tir/function.h
@@ -222,7 +222,7 @@ class TensorIntrin : public ObjectRef {
    */
   TVM_DLL static Optional<TensorIntrin> Get(String name, bool allow_missing = 
false);
 
-  TVM_DEFINE_OBJECT_REF_METHODS(TensorIntrin, ObjectRef, TensorIntrinNode)
+  TVM_DEFINE_OBJECT_REF_METHODS(TensorIntrin, ObjectRef, TensorIntrinNode);
 };
 
 /*!
diff --git a/python/setup.py b/python/setup.py
index 30b1e2174d..6f0cb8b47c 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -168,7 +168,8 @@ def config_cython():
                     include_dirs=[
                         "../include/",
                         "../3rdparty/dmlc-core/include",
-                        "../3rdparty/dlpack/include",
+                        "../ffi/include/",
+                        "../ffi/3rdparty/dlpack/include",
                     ],
                     extra_compile_args=extra_compile_args,
                     library_dirs=library_dirs,
diff --git a/src/target/llvm/llvm_module.cc b/src/target/llvm/llvm_module.cc
index d3a1eb1391..4db37149e3 100644
--- a/src/target/llvm/llvm_module.cc
+++ b/src/target/llvm/llvm_module.cc
@@ -196,7 +196,7 @@ PackedFunc LLVMModuleNode::GetFunction(const String& name, 
const ObjectPtr<Objec
     faddr = reinterpret_cast<TVMBackendPackedCFunc>(GetFunctionAddr(name, 
*llvm_target));
   }
   if (faddr == nullptr) return PackedFunc();
-  return WrapPackedFunc(faddr, sptr_to_self);
+  return tvm::runtime::WrapPackedFunc(faddr, sptr_to_self);
 }
 
 namespace {
diff --git a/src/tir/ir/stmt_functor.cc b/src/tir/ir/stmt_functor.cc
index 1c15f95826..9bdcb60407 100644
--- a/src/tir/ir/stmt_functor.cc
+++ b/src/tir/ir/stmt_functor.cc
@@ -638,7 +638,7 @@ Stmt IRTransform(Stmt ir_node, const runtime::PackedFunc& 
f_preorder,
   std::unordered_set<uint32_t> only_type_index;
   if (only_enable.defined()) {
     for (auto s : only_enable.value()) {
-      only_type_index.insert(Object::TypeKey2Index(s.c_str()));
+      only_type_index.insert(ffi::TypeKey2Index(s.c_str()));
     }
   }
   IRTransformer transform(f_preorder, f_postorder, only_type_index);
diff --git a/tests/cpp/container_test.cc b/tests/cpp/container_test.cc
index 6f0c47c0ea..51391c86a0 100644
--- a/tests/cpp/container_test.cc
+++ b/tests/cpp/container_test.cc
@@ -60,7 +60,6 @@ class TestErrorSwitch {
 
 class TestArrayObj : public Object, public InplaceArrayBase<TestArrayObj, 
TestErrorSwitch> {
  public:
-  static constexpr const uint32_t _type_index = TypeIndex::kDynamic;
   static constexpr const char* _type_key = "test.TestArrayObj";
   TVM_DECLARE_FINAL_OBJECT_INFO(TestArrayObj, Object);
   uint32_t size;
diff --git a/tests/cpp/object_protocol_test.cc 
b/tests/cpp/object_protocol_test.cc
index c4c83dcd95..3f76b1d2f1 100644
--- a/tests/cpp/object_protocol_test.cc
+++ b/tests/cpp/object_protocol_test.cc
@@ -30,7 +30,6 @@ using namespace tvm::runtime;
 class ObjBase : public Object {
  public:
   // dynamically allocate slow
-  static constexpr const uint32_t _type_index = TypeIndex::kDynamic;
   static constexpr const uint32_t _type_child_slots = 1;
   static constexpr const char* _type_key = "test.ObjBase";
   TVM_DECLARE_BASE_OBJECT_INFO(ObjBase, Object);
@@ -38,7 +37,6 @@ class ObjBase : public Object {
 
 class ObjA : public ObjBase {
  public:
-  static constexpr const uint32_t _type_index = TypeIndex::kDynamic;
   static constexpr const uint32_t _type_child_slots = 0;
   static constexpr const char* _type_key = "test.ObjA";
   TVM_DECLARE_BASE_OBJECT_INFO(ObjA, ObjBase);
@@ -46,7 +44,6 @@ class ObjA : public ObjBase {
 
 class ObjB : public ObjBase {
  public:
-  static constexpr const uint32_t _type_index = TypeIndex::kDynamic;
   static constexpr const uint32_t _type_child_slots = 0;
   static constexpr const char* _type_key = "test.ObjB";
   TVM_DECLARE_BASE_OBJECT_INFO(ObjB, ObjBase);
@@ -54,7 +51,6 @@ class ObjB : public ObjBase {
 
 class ObjAA : public ObjA {
  public:
-  static constexpr const uint32_t _type_index = TypeIndex::kDynamic;
   static constexpr const char* _type_key = "test.ObjAA";
   TVM_DECLARE_FINAL_OBJECT_INFO(ObjAA, ObjA);
 };

Reply via email to