|
39 | 39 | #include "./type.h" |
40 | 40 |
|
41 | 41 | namespace tvm { |
| 42 | + |
| 43 | +/*! |
| 44 | + * \brief Returns \p global_var with the given properties. A null property denotes 'no change'. |
| 45 | + * Returns \p global_var if all properties are unchanged. Otherwise, returns a copy with the new |
| 46 | + * fields. |
| 47 | + */ |
| 48 | +GlobalVar WithFields(GlobalVar global_var, Optional<String> opt_name_hint = {}, |
| 49 | + Optional<Type> opt_type = {}, Optional<VirtualDevice> opt_virtual_device = {}, |
| 50 | + Optional<Span> opt_span = {}); |
| 51 | + |
42 | 52 | namespace relay { |
43 | 53 |
|
44 | 54 | using Expr = tvm::RelayExpr; |
@@ -97,8 +107,17 @@ class Constant : public Expr { |
97 | 107 | TVM_DLL explicit Constant(runtime::NDArray data, Span span = Span()); |
98 | 108 |
|
99 | 109 | TVM_DEFINE_OBJECT_REF_METHODS(Constant, RelayExpr, ConstantNode); |
| 110 | + TVM_DEFINE_OBJECT_REF_COW_METHOD(ConstantNode); |
100 | 111 | }; |
101 | 112 |
|
| 113 | +/*! |
| 114 | + * \brief Returns \p constant with the given properties. A null property denotes 'no change'. |
| 115 | + * Returns \p constant if all properties are unchanged. Otherwise, returns a copy with the new |
| 116 | + * fields. |
| 117 | + */ |
| 118 | +Constant WithFields(Constant constant, Optional<runtime::NDArray> opt_data = {}, |
| 119 | + Optional<VirtualDevice> opt_virtual_device = {}, Optional<Span> opt_span = {}); |
| 120 | + |
102 | 121 | /*! \brief Tuple of multiple Exprs */ |
103 | 122 | class Tuple; |
104 | 123 | /*! \brief Tuple container */ |
@@ -149,15 +168,9 @@ class Tuple : public Expr { |
149 | 168 | }; |
150 | 169 |
|
151 | 170 | /*! |
152 | | - * \brief Returns the tuple with given properties. A null property denotes 'no change'. |
153 | | - * Returns this if all properties are unchanged. Otherwise, returns a copy with the new fields. |
154 | | - * \param tuple The tuple to copy |
155 | | - * \param opt_fields The (optional) fields for the copied tuple. If none, ret_tuple->fields = |
156 | | - * tuple->fields. |
157 | | - * \param opt_virtual_device The (optional) virtual_device for the copied tuple. If none, |
158 | | - * ret_tuple->virtual_device = tuple->virtual_device. |
159 | | - * \param opt_span The (optional) span for the copied tuple. If none, |
160 | | - * ret_tuple->span = tuple->span. |
| 171 | + * \brief Returns \p tuple with the given properties. A null property denotes 'no change'. |
| 172 | + * Returns \p tuple if all properties are unchanged. Otherwise, returns a copy with the new |
| 173 | + * fields. |
161 | 174 | */ |
162 | 175 | Tuple WithFields(Tuple tuple, Optional<Array<Expr>> opt_fields = Optional<Array<Expr>>(), |
163 | 176 | Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(), |
@@ -251,19 +264,9 @@ class Var : public Expr { |
251 | 264 | }; |
252 | 265 |
|
253 | 266 | /*! |
254 | | - * \brief Returns the var with given properties. A null property denotes 'no change'. |
255 | | - * Returns var if all properties are unchanged. Otherwise, returns a copy with the new fields. |
256 | | - * \param var The var to copy. |
257 | | - * \param opt_vid The (optional) vid for the copied var. If none, ret_var->vid = var->vid. |
258 | | - * \param opt_type_annotation The (optional) type_annotation for the copied var. If none, |
259 | | - * ret_var->type_annotation = var->type_annotation. |
260 | | - * \param opt_virtual_device The (optional) virtual_device for the copied tuple. If none, |
261 | | - * ret_tuple->virtual_device = tuple->virtual_device. |
262 | | - * \param opt_span The (optional) span for the copied var. If none, ret_var->span = var->span. |
263 | | - * \return If all properties are null or the same as the property in the input var (i.e., opt_vid is |
264 | | - * null or opt_vid.value() == var->vid, etc.), then we return var. Otherwise, we return a copy of |
265 | | - * call with the different fields overwritten. (i.e., if opt_vid.value() != var->vid, then |
266 | | - * ret_var->vid = opt_.value()). |
| 267 | + * \brief Returns \p vor with the given properties. A null property denotes 'no change'. |
| 268 | + * Returns \p var if all properties are unchanged. Otherwise, returns a copy with the new |
| 269 | + * fields. |
267 | 270 | */ |
268 | 271 | Var WithFields(Var var, Optional<Id> opt_vid = Optional<Id>(), |
269 | 272 | Optional<Type> opt_type_annotation = Optional<Type>(), |
@@ -374,22 +377,9 @@ class Call : public Expr { |
374 | 377 | }; |
375 | 378 |
|
376 | 379 | /*! |
377 | | - * \brief Returns the call with given properties. A null property denotes 'no change'. |
378 | | - * Returns call if all properties are unchanged. Otherwise, returns a copy with the new fields. |
379 | | - * \param call The call to copy. |
380 | | - * \param opt_op The (optional) op for the copied call. If none, ret_call->op = call->op. |
381 | | - * \param opt_args The (optional) args for the copied call. If none, ret_call->args = call->args. |
382 | | - * \param opt_attrs The (optional) attrs for the copied call. If none, ret_call->attrs = |
383 | | - * call->attrs. |
384 | | - * \param opt_type_args The (optional) type args for the copied call. If none, |
385 | | - * ret_call->type_args = call->type_args. |
386 | | - * \param opt_virtual_device The (optional) virtual_device for the copied call. If none, |
387 | | - * ret_call->virtual_device = call->virtual_device. |
388 | | - * \param opt_span The (optional) span for the copied call. If none, ret_call->span = call->span. |
389 | | - * \return If all properties are null or the same as the property in the input call (i.e., opt_op is |
390 | | - * null or opt_op.value() == call->op, etc.), then we return call. Otherwise, we return a copy of |
391 | | - * call with the different fields overwritten. (i.e., if opt_op.value() != call->op, then |
392 | | - * ret_call->op = opt_op.value()). |
| 380 | + * \brief Returns \p call with the given properties. A null property denotes 'no change'. |
| 381 | + * Returns \p call if all properties are unchanged. Otherwise, returns a copy with the new |
| 382 | + * fields. |
393 | 383 | */ |
394 | 384 | Call WithFields(Call call, Optional<Expr> opt_op = Optional<Expr>(), |
395 | 385 | Optional<Array<Expr>> opt_args = Optional<Array<Expr>>(), |
@@ -475,19 +465,9 @@ class Let : public Expr { |
475 | 465 | }; |
476 | 466 |
|
477 | 467 | /*! |
478 | | - * \brief Returns the let with given properties. A null property denotes 'no change'. |
479 | | - * Returns let if all properties are unchanged. Otherwise, returns a copy with the new fields. |
480 | | - * \param let The let to copy. |
481 | | - * \param opt_var The (optional) var for the copied let. If none, ret_let->op = let->op. |
482 | | - * \param opt_value The (optional) value for the copied let. If none, ret_let->args = let->args. |
483 | | - * \param opt_body The (optional) body for the copied let. If none, ret_let->attrs = let->attrs. |
484 | | - * \param opt_virtual_device The (optional) virtual_device for the copied let. If none, |
485 | | - * ret_let->virtual_device = let->virtual_device. |
486 | | - * \param opt_span The (optional) span for the copied let. If none, ret_let->span = let->span. |
487 | | - * \return If all properties are null or the same as the property in the input let (i.e., opt_var is |
488 | | - * null or opt_var.value() == let->var, etc.), then we return let. Otherwise, we return a copy of |
489 | | - * let with the different fields overwritten. (i.e., if opt_var.value() != let->var, then |
490 | | - * ret_let->var = opt_var.value()). |
| 468 | + * \brief Returns \p let with the given properties. A null property denotes 'no change'. |
| 469 | + * Returns \p let if all properties are unchanged. Otherwise, returns a copy with the new |
| 470 | + * fields. |
491 | 471 | */ |
492 | 472 | Let WithFields(Let let, Optional<Var> opt_var = Optional<Var>(), |
493 | 473 | Optional<Expr> opt_value = Optional<Expr>(), |
@@ -559,23 +539,9 @@ class If : public Expr { |
559 | 539 | }; |
560 | 540 |
|
561 | 541 | /*! |
562 | | - * \brief Returns the if_expr with given properties. A null property denotes 'no change'. |
563 | | - * Returns if_expr if all properties are unchanged. Otherwise, returns a copy with the new fields. |
564 | | - * \param if_expr The if expression to copy. |
565 | | - * \param opt_cond The (optional) cond for the copied if_expr. If none, ret_if->cond = |
566 | | - * if_expr->cond. |
567 | | - * \param opt_true_branch The (optional) true_branch for the copied if_expr. If none, |
568 | | - * ret_if->true_branch = ret_if->false_branch. |
569 | | - * \param opt_false_branch The (optional) false_branch |
570 | | - * for the copied if_expr. If none, ret_if->false_branch = if_expr->false_branch. |
571 | | - * \param opt_virtual_device The (optional) virtual_device for the copied if_expr. If none, |
572 | | - * ret_if->virtual_device = if_expr->virtual_device. |
573 | | - * \param opt_span The (optional) span for the copied if_expr. If none, |
574 | | - * ret_if->span = if_expr->span. |
575 | | - * \return If all properties are null or the same as the property in |
576 | | - * the input if_expr (i.e., opt_cond is null or opt_cond.value() == if_expr->cond, etc.), then we |
577 | | - * return if_expr. Otherwise, we return a copy of if_expr with the different fields overwritten. |
578 | | - * (i.e., if opt_cond.value() != if_expr->cond, then ret_if->cond = opt_cond.value()). |
| 542 | + * \brief Returns \p if_expr with the given properties. A null property denotes 'no change'. |
| 543 | + * Returns \p if_expr if all properties are unchanged. Otherwise, returns a copy with the new |
| 544 | + * fields. |
579 | 545 | */ |
580 | 546 | If WithFields(If if_expr, Optional<Expr> opt_cond = Optional<Expr>(), |
581 | 547 | Optional<Expr> opt_true_branch = Optional<Expr>(), |
@@ -628,22 +594,9 @@ class TupleGetItem : public Expr { |
628 | 594 | }; |
629 | 595 |
|
630 | 596 | /*! |
631 | | - * \brief Returns the tuple_get_item with given properties. A null property denotes 'no change'. |
632 | | - * Returns if_expr if all properties are unchanged. Otherwise, returns a copy with the new fields. |
633 | | - * \param tuple_get_item The tuple_get_item to copy. |
634 | | - * \param opt_tuple The (optional) tuple for the copied tuple_get_item. If none, |
635 | | - * ret_tuple_get_item->tuple = tuple_get_item->tuple. |
636 | | - * \param opt_index The (optional) index for the copied tuple_get_item. If none, |
637 | | - * ret_tuple_get_item->index = tuple_get_item->index. |
638 | | - * \param opt_virtual_device The (optional) virtual_device for the copied tuple_get_item. |
639 | | - * If none, ret_tuple_get_item->virtual_device = tuple_get_item->virtual_device. |
640 | | - * \param opt_span The (optional) span for the copied tuple_get_item. If none, |
641 | | - * ret_tuple_get_item->span = tuple_get_item->span. |
642 | | - * \return If all properties are null or the same as the property in the input tuple_get_item |
643 | | - * (i.e., opt_tuple is null or opt_tuple.value() == tuple_get_item->tuple, etc.), then we return |
644 | | - * tuple_get_item. Otherwise, we return a copy of tuple_get_item with the different fields |
645 | | - * overwritten. (i.e., if opt_tuple.value() != tuple_get_item->tuple, then |
646 | | - * ret_tuple_get_item->tuple = opt_tuple.value()). |
| 597 | + * \brief Returns \p tuple_get_item with the given properties. A null property denotes 'no change'. |
| 598 | + * Returns \p tuple_get_item if all properties are unchanged. Otherwise, returns a copy with the new |
| 599 | + * fields. |
647 | 600 | */ |
648 | 601 | TupleGetItem WithFields(TupleGetItem tuple_get_item, Optional<Expr> opt_tuple = Optional<Expr>(), |
649 | 602 | Optional<Integer> opt_index = Optional<Integer>(), |
@@ -692,21 +645,9 @@ class RefCreate : public Expr { |
692 | 645 | }; |
693 | 646 |
|
694 | 647 | /*! |
695 | | - * \brief Returns the ref create with given properties. A null property denotes 'no change'. |
696 | | - * Returns ref_create if all properties are unchanged. Otherwise, returns a copy with the new |
| 648 | + * \brief Returns \p ref_create with the given properties. A null property denotes 'no change'. |
| 649 | + * Returns \p ref_crete if all properties are unchanged. Otherwise, returns a copy with the new |
697 | 650 | * fields. |
698 | | - * \param ref_create The ref_create to copy. |
699 | | - * \param opt_value The (optional) value for the copied ref_create. If none, |
700 | | - * ret_ref_create->value = ref_create->value. |
701 | | - * \param opt_virtual_device The (optional) virtual_device for the copied ref_create. If none, |
702 | | - * ret_ref_create->virtual_device = ref_create->virtual_device. |
703 | | - * \param opt_span The (optional) span for the copied ref_create. If none, |
704 | | - * ret_ref_create->span = ref_create->span. |
705 | | - * \return If all properties are null or the same as the property in the input ref_create |
706 | | - * (i.e., opt_value is null or opt_value.value() == ref_create->value, etc.), then we return |
707 | | - * ref_create. Otherwise, we return a copy of ref_create with the different fields overwritten. |
708 | | - * (i.e., if opt_value.value() != ref_create->value, then |
709 | | - * ret_ref_create->value = opt_value.value()). |
710 | 651 | */ |
711 | 652 | RefCreate WithFields(RefCreate ref_create, Optional<Expr> opt_value = Optional<Expr>(), |
712 | 653 | Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(), |
@@ -754,20 +695,9 @@ class RefRead : public Expr { |
754 | 695 | }; |
755 | 696 |
|
756 | 697 | /*! |
757 | | - * \brief Returns the ref read with given properties. A null property denotes 'no change'. |
758 | | - * Returns ref_read if all properties are unchanged. Otherwise, returns a copy with the new fields. |
759 | | - * \param ref_read The ref_read to copy. |
760 | | - * \param opt_ref The (optional) ref for the copied ref_read. If none, ret_ref_read->ref = |
761 | | - * ref_read->ref. |
762 | | - * \param opt_virtual_device |
763 | | - * The (optional) virtual_device for the copied ref_read. If none, ret_ref_read->virtual_device = |
764 | | - * ref_read->virtual_device. |
765 | | - * \param opt_span The (optional) span for the copied ref_read. If none, ret_ref_read->span = |
766 | | - * ref_read->span. |
767 | | - * \return If all properties are null or the same as the property in the input |
768 | | - * ref_read (i.e., opt_ref is null or opt_ref.value() == ref_read->ref, etc.), then we return |
769 | | - * ref_read. Otherwise, we return a copy of ref_read with the different fields overwritten. (i.e., |
770 | | - * if opt_ref.value() != ref_read->ref, then ret_ref_read->ref = opt_ref.value()). |
| 698 | + * \brief Returns \p ref_read with the given properties. A null property denotes 'no change'. |
| 699 | + * Returns \p ref_read if all properties are unchanged. Otherwise, returns a copy with the new |
| 700 | + * fields. |
771 | 701 | */ |
772 | 702 | RefRead WithFields(RefRead ref_read, Optional<Expr> opt_ref = Optional<Expr>(), |
773 | 703 | Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(), |
@@ -820,22 +750,9 @@ class RefWrite : public Expr { |
820 | 750 | }; |
821 | 751 |
|
822 | 752 | /*! |
823 | | - * \brief Returns the ref write with given properties. A null property denotes 'no change'. |
824 | | - * Returns ref_write if all properties are unchanged. Otherwise, returns a copy with the new fields. |
825 | | - * \param ref_write The ref_write to copy. |
826 | | - * \param opt_ref The (optional) ref for the copied ref_write. If none, |
827 | | - * ret_ref_write->ref = ref_write->ref. |
828 | | - * \param opt_value The (optional) value for the copied ref_write. If none, |
829 | | - * ret_ref_write->value = ref_write->value. |
830 | | - * \param opt_virtual_device |
831 | | - * The (optional) virtual_device for the copied ref_write. If none, ret_ref_write->virtual_device = |
832 | | - * ref_write->virtual_device. |
833 | | - * \param opt_span The (optional) span for the copied ref_write. If none, ret_ref_write->span = |
834 | | - * ref_write->span. |
835 | | - * \return If all properties are null or the same as the property in the input ref_write (i.e., |
836 | | - * opt_ref is null or opt_ref.value() == ref_write->ref, etc.), then we return ref_write. Otherwise, |
837 | | - * we return a copy of ref_write with the different fields overwritten. (i.e., if ref_write.value() |
838 | | - * != ref_write->ref, then ret_ref_write->ref = opt_ref.value()). |
| 753 | + * \brief Returns \p ref_write with the given properties. A null property denotes 'no change'. |
| 754 | + * Returns \p ref_write if all properties are unchanged. Otherwise, returns a copy with the new |
| 755 | + * fields. |
839 | 756 | */ |
840 | 757 | RefWrite WithFields(RefWrite ref_write, Optional<Expr> opt_ref = Optional<Expr>(), |
841 | 758 | Optional<Expr> opt_value = Optional<Expr>(), |
|
0 commit comments