|
56 | 56 | #define TVM_FFI_DLL_EXPORT __attribute__((visibility("default"))) |
57 | 57 | #endif |
58 | 58 |
|
| 59 | +/*! |
| 60 | + * \brief Marks the API as extra c++ api that is defined in cc files. |
| 61 | + * |
| 62 | + * These APIs are extra features that depend on, but are not required to |
| 63 | + * support essential core functionality, such as function calling and object |
| 64 | + * access. |
| 65 | + * |
| 66 | + * They are implemented in cc files to reduce compile-time overhead. |
| 67 | + * The input/output only uses POD/Any/ObjectRef for ABI stability. |
| 68 | + * However, these extra APIs may have an issue across MSVC/Itanium ABI, |
| 69 | + * |
| 70 | + * Related features are also available through reflection based function |
| 71 | + * that is fully based on C API |
| 72 | + * |
| 73 | + * The project aims to minimize the number of extra C++ APIs and only |
| 74 | + * restrict the use to non-core functionalities. |
| 75 | + */ |
| 76 | +#ifndef TVM_FFI_EXTRA_CXX_API |
| 77 | +#define TVM_FFI_EXTRA_CXX_API TVM_FFI_DLL |
| 78 | +#endif |
| 79 | + |
59 | 80 | #ifdef __cplusplus |
60 | 81 | extern "C" { |
61 | 82 | #endif |
@@ -326,12 +347,89 @@ typedef enum { |
326 | 347 | kTVMFFIFieldFlagBitMaskHasDefault = 1 << 1, |
327 | 348 | /*! \brief The field is a static method. */ |
328 | 349 | kTVMFFIFieldFlagBitMaskIsStaticMethod = 1 << 2, |
| 350 | + /*! |
| 351 | + * \brief The field should be ignored when performing structural eq/hash |
| 352 | + * |
| 353 | + * This is an optional meta-data for structural eq/hash. |
| 354 | + */ |
| 355 | + kTVMFFIFieldFlagBitMaskSEqHashIgnore = 1 << 3, |
| 356 | + /*! |
| 357 | + * \brief The field enters a def region where var can be defined/matched. |
| 358 | + * |
| 359 | + * This is an optional meta-data for structural eq/hash. |
| 360 | + */ |
| 361 | + kTVMFFIFieldFlagBitMaskSEqHashDef = 1 << 4, |
329 | 362 | #ifdef __cplusplus |
330 | 363 | }; |
331 | 364 | #else |
332 | 365 | } TVMFFIFieldFlagBitMask; |
333 | 366 | #endif |
334 | 367 |
|
| 368 | +/*! |
| 369 | + * \brief Optional meta-data for structural eq/hash. |
| 370 | + * |
| 371 | + * This meta-data is only useful when we want to leverage the information |
| 372 | + * to perform richer semantics aware structural comparison and hash. |
| 373 | + * It can be safely ignored if such information is not needed. |
| 374 | + * |
| 375 | + * The meta-data record comparison method in tree node and DAG node. |
| 376 | + * |
| 377 | + * \code |
| 378 | + * x = VarNode() |
| 379 | + * v0 = AddNode(x, 1) |
| 380 | + * v1 = AddNode(x, 1) |
| 381 | + * v2 = AddNode(v0, v0) |
| 382 | + * v3 = AddNode(v1, v0) |
| 383 | + * \endcode |
| 384 | + * |
| 385 | + * Consider the construct sequence of AddNode below, |
| 386 | + * if AddNode is treated as a tree node, then v2 and v3 |
| 387 | + * structural equals to each other, but if AddNode is |
| 388 | + * treated as a DAG node, then v2 and v3 does not |
| 389 | + * structural equals to each other. |
| 390 | + */ |
| 391 | +#ifdef __cplusplus |
| 392 | +enum TVMFFISEqHashKind : int32_t { |
| 393 | +#else |
| 394 | +typedef enum { |
| 395 | +#endif |
| 396 | + /*! \brief Do not support structural eq/hash. */ |
| 397 | + kTVMFFISEqHashKindUnsupported = 0, |
| 398 | + /*! |
| 399 | + * \brief The object be compared as a tree node. |
| 400 | + */ |
| 401 | + kTVMFFISEqHashKindTreeNode = 1, |
| 402 | + /*! |
| 403 | + * \brief The object is treated as a free variable that can be mapped |
| 404 | + * to another free variable in the definition region. |
| 405 | + */ |
| 406 | + kTVMFFISEqHashKindFreeVar = 2, |
| 407 | + /*! |
| 408 | + * \brief The field should be compared as a DAG node. |
| 409 | + */ |
| 410 | + kTVMFFISEqHashKindDAGNode = 3, |
| 411 | + /*! |
| 412 | + * \brief The object is treated as a constant tree node. |
| 413 | + * |
| 414 | + * Same as tree node, but the object does not contain free var |
| 415 | + * as any of its nested children. |
| 416 | + * |
| 417 | + * That means we can use pointer equality for equality. |
| 418 | + */ |
| 419 | + kTVMFFISEqHashKindConstTreeNode = 4, |
| 420 | + /*! |
| 421 | + * \brief One can simply use pointer equality for equality. |
| 422 | + * |
| 423 | + * This is useful for "singleton"-style object that can |
| 424 | + * is only an unique copy of each value. |
| 425 | + */ |
| 426 | + kTVMFFISEqHashKindUniqueInstance = 5, |
| 427 | +#ifdef __cplusplus |
| 428 | +}; |
| 429 | +#else |
| 430 | +} TVMFFISEqHashKind; |
| 431 | +#endif |
| 432 | + |
335 | 433 | /*! |
336 | 434 | * \brief Information support for optional object reflection. |
337 | 435 | */ |
@@ -431,7 +529,11 @@ typedef struct { |
431 | 529 | * |
432 | 530 | * This field is set optional and set to 0 if not registered. |
433 | 531 | */ |
434 | | - int64_t total_size; |
| 532 | + int32_t total_size; |
| 533 | + /*! |
| 534 | + * \brief Optional meta-data for structural eq/hash. |
| 535 | + */ |
| 536 | + TVMFFISEqHashKind structural_eq_hash_kind; |
435 | 537 | } TVMFFITypeExtraInfo; |
436 | 538 |
|
437 | 539 | /*! |
|
0 commit comments