tvm
Loading...
Searching...
No Matches
doc.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19#ifndef TVM_SCRIPT_PRINTER_DOC_H_
20#define TVM_SCRIPT_PRINTER_DOC_H_
21
22#include <tvm/ffi/dtype.h>
23#include <tvm/ffi/reflection/access_path.h>
24#include <tvm/ffi/reflection/registry.h>
25#include <tvm/ir/expr.h>
26#include <tvm/ir/type.h>
28
29#include <string>
30
31namespace tvm {
32namespace script {
33namespace printer {
34
35using AccessPath = ffi::reflection::AccessPath;
36
48class DocNode : public ffi::Object {
49 public:
57 mutable ffi::Array<AccessPath> source_paths;
58
59 static void RegisterReflection() {
60 namespace refl = tvm::ffi::reflection;
61 refl::ObjectDef<DocNode>().def_rw("source_paths", &DocNode::source_paths);
62 }
63
64 static constexpr bool _type_mutable = true;
65
66 TVM_FFI_DECLARE_OBJECT_INFO("script.printer.Doc", DocNode, ffi::Object);
67
68 public:
69 virtual ~DocNode() = default;
70};
71
77class Doc : public ffi::ObjectRef {
78 protected:
79 Doc() = default;
80
81 public:
83};
84
85class ExprDoc;
86
92class ExprDocNode : public DocNode {
93 public:
98 TVM_TIRX_DLL ExprDoc Attr(ffi::String attr) const;
99
104 TVM_TIRX_DLL ExprDoc operator[](ffi::Array<Doc> indices) const;
105
110 TVM_TIRX_DLL ExprDoc Call(ffi::Array<ExprDoc, void> args) const;
111
118 TVM_TIRX_DLL ExprDoc Call(ffi::Array<ExprDoc, void> args, //
119 ffi::Array<ffi::String> kwargs_keys, //
120 ffi::Array<ExprDoc, void> kwargs_values) const;
121
122 static void RegisterReflection() {
123 namespace refl = tvm::ffi::reflection;
124 refl::ObjectDef<ExprDocNode>();
125 }
127};
128
134class ExprDoc : public Doc {
135 protected:
136 ExprDoc() = default;
137
138 public:
143 TVM_TIRX_DLL ExprDoc operator[](ffi::Array<Doc> indices) const;
144
145 explicit ExprDoc(ffi::ObjectPtr<ExprDocNode> data) : Doc(ffi::UnsafeInit{}) {
146 TVM_FFI_ICHECK(data != nullptr);
147 data_ = std::move(data);
148 }
149
151};
152
158class StmtDocNode : public DocNode {
159 public:
168 mutable ffi::Optional<ffi::String> comment{std::nullopt};
169
170 static void RegisterReflection() {
171 namespace refl = tvm::ffi::reflection;
172 refl::ObjectDef<StmtDocNode>().def_rw("comment", &StmtDocNode::comment);
173 }
175};
176
182class StmtDoc : public Doc {
183 protected:
184 StmtDoc() = default;
185
186 public:
188};
189
196class StmtBlockDocNode : public DocNode {
197 public:
199 ffi::Array<StmtDoc> stmts;
200
201 static void RegisterReflection() {
202 namespace refl = tvm::ffi::reflection;
203 refl::ObjectDef<StmtBlockDocNode>().def_ro("stmts", &StmtBlockDocNode::stmts);
204 }
206};
207
221
228 public:
238 ffi::Any value;
239
240 static void RegisterReflection() {
241 namespace refl = tvm::ffi::reflection;
242 refl::ObjectDef<LiteralDocNode>().def_ro("value", &LiteralDocNode::value);
243 }
245};
246
252class LiteralDoc : public ExprDoc {
253 protected:
254 TVM_TIRX_DLL explicit LiteralDoc(ffi::Any value, const ffi::Optional<AccessPath>& object_path);
255
256 public:
261 static LiteralDoc None(const ffi::Optional<AccessPath>& p) {
262 return LiteralDoc(ffi::Any(nullptr), p);
263 }
269 static LiteralDoc Int(int64_t v, const ffi::Optional<AccessPath>& p) {
270 return LiteralDoc(IntImm::Int64(v), p);
271 }
272
279 static LiteralDoc Int(IntImm v, const ffi::Optional<AccessPath>& p) {
280 return LiteralDoc(std::move(v), p);
281 }
287 static LiteralDoc Boolean(bool v, const ffi::Optional<AccessPath>& p) {
288 return LiteralDoc(IntImm::Bool(v), p);
289 }
295 static LiteralDoc Float(double v, const ffi::Optional<AccessPath>& p) {
296 return LiteralDoc(FloatImm(PrimType::Float(64), v), p);
297 }
303 static LiteralDoc Str(const ffi::String& v, const ffi::Optional<AccessPath>& p) {
304 return LiteralDoc(v, p);
305 }
311 static LiteralDoc DataType(DLDataType v, const ffi::Optional<AccessPath>& p) {
312 std::string dtype =
313 v == DLDataType{kDLOpaqueHandle, 0, 0} ? "void" : ffi::DLDataTypeToString(v);
314 return LiteralDoc::Str(dtype, p);
315 }
321 static LiteralDoc Device(const DLDevice& v, const ffi::Optional<AccessPath>& p) {
322 std::ostringstream os;
323 runtime::operator<<(os, v);
324 return LiteralDoc::Str(os.str(), p);
325 }
326
328};
329
336 public:
338 ExprDoc value{ffi::UnsafeInit()};
339
340 static void RegisterReflection() {
341 namespace refl = tvm::ffi::reflection;
342 refl::ObjectDef<ExprStringDocNode>().def_ro("value", &ExprStringDocNode::value);
343 }
345};
346
352class ExprStringDoc : public ExprDoc {
353 public:
359 TVM_TIRX_DLL explicit ExprStringDoc(ExprDoc value, const ffi::Optional<AccessPath>& object_path);
360
362};
363
369class IdDocNode : public ExprDocNode {
370 public:
372 ffi::String name;
373
374 static void RegisterReflection() {
375 namespace refl = tvm::ffi::reflection;
376 refl::ObjectDef<IdDocNode>().def_ro("name", &IdDocNode::name);
377 }
379};
380
386class IdDoc : public ExprDoc {
387 public:
392 TVM_TIRX_DLL explicit IdDoc(ffi::String name);
393 explicit IdDoc(std::nullptr_t) : ExprDoc(nullptr) {}
395};
396
403 public:
405 ExprDoc value{ffi::UnsafeInit()};
407 ffi::String name;
408
409 static void RegisterReflection() {
410 namespace refl = tvm::ffi::reflection;
411 refl::ObjectDef<AttrAccessDocNode>()
412 .def_ro("value", &AttrAccessDocNode::value)
413 .def_ro("name", &AttrAccessDocNode::name);
414 }
416};
417
433
439class IndexDocNode : public ExprDocNode {
440 public:
442 ExprDoc value{ffi::UnsafeInit()};
450 ffi::Array<Doc> indices; // Each element is union of: Slice / ExprDoc
451
452 static void RegisterReflection() {
453 namespace refl = tvm::ffi::reflection;
454 refl::ObjectDef<IndexDocNode>()
455 .def_ro("value", &IndexDocNode::value)
456 .def_ro("indices", &IndexDocNode::indices);
457 }
459};
460
466class IndexDoc : public ExprDoc {
467 public:
473 TVM_TIRX_DLL explicit IndexDoc(ExprDoc value, ffi::Array<Doc> indices);
475};
476
482class CallDocNode : public ExprDocNode {
483 public:
485 ExprDoc callee{ffi::UnsafeInit()};
487 ffi::Array<ExprDoc> args;
489 ffi::Array<ffi::String> kwargs_keys;
496 ffi::Array<ExprDoc> kwargs_values;
497
498 static void RegisterReflection() {
499 namespace refl = tvm::ffi::reflection;
500 refl::ObjectDef<CallDocNode>()
501 .def_ro("callee", &CallDocNode::callee)
502 .def_ro("args", &CallDocNode::args)
503 .def_ro("kwargs_keys", &CallDocNode::kwargs_keys)
504 .def_ro("kwargs_values", &CallDocNode::kwargs_values);
505 }
507};
508
514class CallDoc : public ExprDoc {
515 public:
523 TVM_TIRX_DLL CallDoc(ExprDoc callee, ffi::Array<ExprDoc> args,
524 ffi::Array<ffi::String> kwargs_keys, ffi::Array<ExprDoc> kwargs_values);
526};
527
537 public:
538 enum class Kind : int32_t {
539 // Unary operators
540 kUnaryStart = 0,
541 kUSub = 1, // -x
542 kInvert = 2, // ~x
543 kNot = 3, // not x
544 kUnaryEnd = 4,
545
546 // Binary operators
547 kBinaryStart = 5,
548 kAdd = 6, // +
549 kSub = 7, // -
550 kMult = 8, // *
551 kDiv = 9, // /
552 kFloorDiv = 10, // // in Python
553 kMod = 11, // % in Python
554 kPow = 12, // ** in Python
555 kLShift = 13, // <<
556 kRShift = 14, // >>
557 kBitAnd = 15, // &
558 kBitOr = 16, // |
559 kBitXor = 17, // ^
560 kLt = 18, // <
561 kLtE = 19, // <=
562 kEq = 20, // ==
563 kNotEq = 21, // !=
564 kGt = 22, // >
565 kGtE = 23, // >=
566 kAnd = 24, // and
567 kOr = 25, // or
568 kMatMul = 26, // @
569 kBinaryEnd = 27,
570
571 // Special
572 kSpecialStart = 28,
573 kIfThenElse = 29, // <operands[1]> if <operands[0]> else <operands[2]>
574 kSpecialEnd = 30
575 };
576
580 ffi::Array<ExprDoc> operands;
581
582 static void RegisterReflection() {
583 namespace refl = tvm::ffi::reflection;
584 refl::ObjectDef<OperationDocNode>()
585 .def_ro("kind", &OperationDocNode::kind)
586 .def_ro("operands", &OperationDocNode::operands);
587 }
589};
590
606
616 public:
618 ffi::Array<IdDoc> args;
620 ExprDoc body{ffi::UnsafeInit()};
621
622 static void RegisterReflection() {
623 namespace refl = tvm::ffi::reflection;
624 refl::ObjectDef<LambdaDocNode>()
625 .def_ro("args", &LambdaDocNode::args)
626 .def_ro("body", &LambdaDocNode::body);
627 }
629};
630
636class LambdaDoc : public ExprDoc {
637 public:
643 TVM_TIRX_DLL explicit LambdaDoc(ffi::Array<IdDoc> args, ExprDoc body);
645};
646
652class TupleDocNode : public ExprDocNode {
653 public:
655 ffi::Array<ExprDoc> elements;
656
657 static void RegisterReflection() {
658 namespace refl = tvm::ffi::reflection;
659 refl::ObjectDef<TupleDocNode>().def_ro("elements", &TupleDocNode::elements);
660 }
662};
663
669class TupleDoc : public ExprDoc {
670 public:
674 TupleDoc() : ExprDoc(ffi::make_object<TupleDocNode>()) {}
679 TVM_TIRX_DLL explicit TupleDoc(ffi::Array<ExprDoc> elements);
681};
682
688class ListDocNode : public ExprDocNode {
689 public:
691 ffi::Array<ExprDoc> elements;
692
693 static void RegisterReflection() {
694 namespace refl = tvm::ffi::reflection;
695 refl::ObjectDef<ListDocNode>().def_ro("elements", &ListDocNode::elements);
696 }
698};
699
705class ListDoc : public ExprDoc {
706 public:
710 ListDoc() : ExprDoc(ffi::make_object<ListDocNode>()) {}
715 TVM_TIRX_DLL explicit ListDoc(ffi::Array<ExprDoc> elements);
717};
718
724class DictDocNode : public ExprDocNode {
725 public:
727 ffi::Array<ExprDoc> keys;
734 ffi::Array<ExprDoc> values;
735
736 static void RegisterReflection() {
737 namespace refl = tvm::ffi::reflection;
738 refl::ObjectDef<DictDocNode>()
739 .def_ro("keys", &DictDocNode::keys)
740 .def_ro("values", &DictDocNode::values);
741 }
743};
744
750class DictDoc : public ExprDoc {
751 public:
755 DictDoc() : ExprDoc(ffi::make_object<DictDocNode>()) {}
761 TVM_TIRX_DLL explicit DictDoc(ffi::Array<ExprDoc> keys, ffi::Array<ExprDoc> values);
763};
764
772class SliceDocNode : public DocNode {
773 public:
775 ffi::Optional<ExprDoc> start;
777 ffi::Optional<ExprDoc> stop;
779 ffi::Optional<ExprDoc> step;
780
781 static void RegisterReflection() {
782 namespace refl = tvm::ffi::reflection;
783 refl::ObjectDef<SliceDocNode>()
784 .def_ro("start", &SliceDocNode::start)
785 .def_ro("stop", &SliceDocNode::stop)
786 .def_ro("step", &SliceDocNode::step);
787 }
789};
790
796class SliceDoc : public Doc {
797 public:
804 TVM_TIRX_DLL explicit SliceDoc(ffi::Optional<ExprDoc> start, ffi::Optional<ExprDoc> stop,
805 ffi::Optional<ExprDoc> step);
807};
808
815 public:
817 ExprDoc lhs{ffi::UnsafeInit()};
823 ffi::Optional<ExprDoc> rhs;
825 ffi::Optional<ExprDoc> annotation;
826
827 static void RegisterReflection() {
828 namespace refl = tvm::ffi::reflection;
829 refl::ObjectDef<AssignDocNode>()
830 .def_ro("lhs", &AssignDocNode::lhs)
831 .def_ro("rhs", &AssignDocNode::rhs)
832 .def_ro("annotation", &AssignDocNode::annotation);
833 }
835};
836
842class AssignDoc : public StmtDoc {
843 public:
850 TVM_TIRX_DLL explicit AssignDoc(ExprDoc lhs, ffi::Optional<ExprDoc> rhs,
851 ffi::Optional<ExprDoc> annotation);
853};
854
860class IfDocNode : public StmtDocNode {
861 public:
863 ExprDoc predicate{ffi::UnsafeInit()};
865 ffi::Array<StmtDoc> then_branch;
867 ffi::Optional<ffi::Array<StmtDoc>> else_branch;
868
869 static void RegisterReflection() {
870 namespace refl = tvm::ffi::reflection;
871 refl::ObjectDef<IfDocNode>()
872 .def_ro("predicate", &IfDocNode::predicate)
873 .def_ro("then_branch", &IfDocNode::then_branch)
874 .def_ro("else_branch", &IfDocNode::else_branch);
875 }
877};
878
884class IfDoc : public StmtDoc {
885 public:
892 TVM_TIRX_DLL explicit IfDoc(ExprDoc predicate, ffi::Array<StmtDoc> then_branch,
893 ffi::Optional<ffi::Array<StmtDoc>> else_branch);
895};
896
902class WhileDocNode : public StmtDocNode {
903 public:
905 ExprDoc predicate{ffi::UnsafeInit()};
907 ffi::Array<StmtDoc> body;
908
909 static void RegisterReflection() {
910 namespace refl = tvm::ffi::reflection;
911 refl::ObjectDef<WhileDocNode>()
912 .def_ro("predicate", &WhileDocNode::predicate)
913 .def_ro("body", &WhileDocNode::body);
914 }
916};
917
923class WhileDoc : public StmtDoc {
924 public:
930 TVM_TIRX_DLL explicit WhileDoc(ExprDoc predicate, ffi::Array<StmtDoc> body);
932};
933
939class BreakDocNode : public StmtDocNode {
940 public:
941 static void RegisterReflection() {
942 namespace refl = tvm::ffi::reflection;
943 refl::ObjectDef<BreakDocNode>();
944 }
945
947};
948
962
969 public:
970 static void RegisterReflection() {
971 namespace refl = tvm::ffi::reflection;
972 refl::ObjectDef<ContinueDocNode>();
973 }
974
976};
977
991
1001class ForDocNode : public StmtDocNode {
1002 public:
1004 ExprDoc lhs{ffi::UnsafeInit()};
1006 ExprDoc rhs{ffi::UnsafeInit()};
1008 ffi::Array<StmtDoc> body;
1009
1010 static void RegisterReflection() {
1011 namespace refl = tvm::ffi::reflection;
1012 refl::ObjectDef<ForDocNode>()
1013 .def_ro("lhs", &ForDocNode::lhs)
1014 .def_ro("rhs", &ForDocNode::rhs)
1015 .def_ro("body", &ForDocNode::body);
1016 }
1018};
1019
1025class ForDoc : public StmtDoc {
1026 public:
1033 TVM_TIRX_DLL explicit ForDoc(ExprDoc lhs, ExprDoc rhs, ffi::Array<StmtDoc> body);
1035};
1036
1048 public:
1050 ffi::Optional<ExprDoc> lhs{std::nullopt};
1052 ExprDoc rhs{ffi::UnsafeInit()};
1054 ffi::Array<StmtDoc> body;
1057
1058 static void RegisterReflection() {
1059 namespace refl = tvm::ffi::reflection;
1060 refl::ObjectDef<ScopeDocNode>()
1061 .def_ro("lhs", &ScopeDocNode::lhs)
1062 .def_ro("rhs", &ScopeDocNode::rhs)
1063 .def_ro("body", &ScopeDocNode::body)
1064 .def_ro("allow_concise_scoping", &ScopeDocNode::allow_concise_scoping);
1065 }
1067};
1068
1074class ScopeDoc : public StmtDoc {
1075 public:
1083 TVM_TIRX_DLL explicit ScopeDoc(ffi::Optional<ExprDoc> lhs, ExprDoc rhs, ffi::Array<StmtDoc> body,
1084 bool allow_concise_scoping = false);
1085
1091 TVM_TIRX_DLL explicit ScopeDoc(ExprDoc rhs, ffi::Array<StmtDoc> body);
1092
1094};
1095
1102 public:
1104 ExprDoc expr{ffi::UnsafeInit()};
1105
1106 static void RegisterReflection() {
1107 namespace refl = tvm::ffi::reflection;
1108 refl::ObjectDef<ExprStmtDocNode>().def_ro("expr", &ExprStmtDocNode::expr);
1109 }
1111};
1112
1127
1134 public:
1136 ExprDoc test{ffi::UnsafeInit()};
1138 ffi::Optional<ExprDoc> msg{std::nullopt};
1139
1140 static void RegisterReflection() {
1141 namespace refl = tvm::ffi::reflection;
1142 refl::ObjectDef<AssertDocNode>()
1143 .def_ro("test", &AssertDocNode::test)
1144 .def_ro("msg", &AssertDocNode::msg);
1145 }
1147};
1148
1154class AssertDoc : public StmtDoc {
1155 public:
1161 TVM_TIRX_DLL explicit AssertDoc(ExprDoc test, ffi::Optional<ExprDoc> msg = std::nullopt);
1163};
1164
1171 public:
1173 ExprDoc value{ffi::UnsafeInit()};
1174
1175 static void RegisterReflection() {
1176 namespace refl = tvm::ffi::reflection;
1177 refl::ObjectDef<ReturnDocNode>().def_ro("value", &ReturnDocNode::value);
1178 }
1180};
1181
1196
1203 public:
1205 IdDoc name{ffi::UnsafeInit{}};
1213 ffi::Array<AssignDoc> args;
1215 ffi::Array<ExprDoc> decorators;
1217 ffi::Optional<ExprDoc> return_type{std::nullopt};
1219 ffi::Array<StmtDoc> body;
1227 ffi::Array<Doc> type_params;
1228
1229 static void RegisterReflection() {
1230 namespace refl = tvm::ffi::reflection;
1231 refl::ObjectDef<FunctionDocNode>()
1232 .def_ro("name", &FunctionDocNode::name)
1233 .def_ro("args", &FunctionDocNode::args)
1234 .def_ro("decorators", &FunctionDocNode::decorators)
1235 .def_ro("return_type", &FunctionDocNode::return_type)
1236 .def_ro("body", &FunctionDocNode::body)
1237 .def_ro("type_params", &FunctionDocNode::type_params);
1238 }
1240};
1241
1247class FunctionDoc : public StmtDoc {
1248 public:
1258 TVM_TIRX_DLL explicit FunctionDoc(IdDoc name, ffi::Array<AssignDoc> args,
1259 ffi::Array<ExprDoc> decorators,
1260 ffi::Optional<ExprDoc> return_type, ffi::Array<StmtDoc> body,
1261 ffi::Array<Doc> type_params = {});
1263};
1264
1271 public:
1273 IdDoc name{ffi::UnsafeInit{}};
1275 ffi::Array<ExprDoc> decorators;
1277 ffi::Array<StmtDoc> body;
1278
1279 static void RegisterReflection() {
1280 namespace refl = tvm::ffi::reflection;
1281 refl::ObjectDef<ClassDocNode>()
1282 .def_ro("name", &ClassDocNode::name)
1283 .def_ro("decorators", &ClassDocNode::decorators)
1284 .def_ro("body", &ClassDocNode::body);
1285 }
1287};
1288
1294class ClassDoc : public StmtDoc {
1295 public:
1302 TVM_TIRX_DLL explicit ClassDoc(IdDoc name, ffi::Array<ExprDoc> decorators,
1303 ffi::Array<StmtDoc> body);
1305};
1306
1313 public:
1314 static void RegisterReflection() {
1315 namespace refl = tvm::ffi::reflection;
1316 refl::ObjectDef<CommentDocNode>();
1317 }
1319};
1320
1331
1338 public:
1339 static void RegisterReflection() {
1340 namespace refl = tvm::ffi::reflection;
1341 refl::ObjectDef<DocStringDocNode>();
1342 }
1344};
1345
1356
1363 public:
1365 ffi::String canonical_name;
1366
1367 static void RegisterReflection() {
1368 ffi::reflection::ObjectDef<NamespaceDocNode>().def_ro("canonical_name",
1370 }
1372};
1373
1386
1387} // namespace printer
1388} // namespace script
1389} // namespace tvm
1390
1391#endif // TVM_SCRIPT_PRINTER_DOC_H_
Managed reference class to FloatImmNode.
Definition expr.h:232
Managed reference class to IntImmNode.
Definition expr.h:152
static IntImm Int64(ffi::BigInt value, Location loc=UnknownLoc())
Construct a scalar int64 constant.
Definition expr.h:195
static IntImm Bool(bool value, Location loc=UnknownLoc())
Construct a scalar boolean constant.
Definition expr.h:172
static TVM_TIRX_DLL PrimType Float(int bits, int lanes=1)
Construct a floating-point type with fixed lanes.
Doc that represents assert statement.
Definition doc.h:1133
ffi::Optional< ExprDoc > msg
The optional error message when assertion failed.
Definition doc.h:1138
static void RegisterReflection()
Definition doc.h:1140
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.AssertDoc", AssertDocNode, StmtDocNode)
ExprDoc test
The expression to test.
Definition doc.h:1136
Reference type of AssertDocNode.
Definition doc.h:1154
TVM_TIRX_DLL AssertDoc(ExprDoc test, ffi::Optional< ExprDoc > msg=std::nullopt)
Constructor of AssertDoc.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(AssertDoc, StmtDoc, AssertDocNode)
Doc that represents assign statement.
Definition doc.h:814
ffi::Optional< ExprDoc > annotation
The type annotation of this assignment.
Definition doc.h:825
ffi::Optional< ExprDoc > rhs
The right hand side of the assignment.
Definition doc.h:823
ExprDoc lhs
The left hand side of the assignment.
Definition doc.h:817
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.AssignDoc", AssignDocNode, StmtDocNode)
static void RegisterReflection()
Definition doc.h:827
Reference type of AssignDocNode.
Definition doc.h:842
TVM_TIRX_DLL AssignDoc(ExprDoc lhs, ffi::Optional< ExprDoc > rhs, ffi::Optional< ExprDoc > annotation)
Constructor of AssignDoc.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(AssignDoc, StmtDoc, AssignDocNode)
Doc that represents attribute access on another expression.
Definition doc.h:402
ffi::String name
The attribute to be accessed.
Definition doc.h:407
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.AttrAccessDoc", AttrAccessDocNode, ExprDocNode)
ExprDoc value
The target expression to be accessed.
Definition doc.h:405
static void RegisterReflection()
Definition doc.h:409
Reference type of AttrAccessDocNode.
Definition doc.h:423
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(AttrAccessDoc, ExprDoc, AttrAccessDocNode)
TVM_TIRX_DLL AttrAccessDoc(ExprDoc value, ffi::String name)
Constructor of AttrAccessDoc.
Doc that represents break statement.
Definition doc.h:939
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.BreakDoc", BreakDocNode, StmtDocNode)
static void RegisterReflection()
Definition doc.h:941
Reference type of BreakDocNode.
Definition doc.h:954
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(BreakDoc, StmtDoc, BreakDocNode)
TVM_TIRX_DLL BreakDoc()
Constructor of BreakDoc.
Doc that represents function call.
Definition doc.h:482
ffi::Array< ffi::String > kwargs_keys
The keys of keyword arguments.
Definition doc.h:489
ffi::Array< ExprDoc > kwargs_values
The values of keyword arguments.
Definition doc.h:496
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.CallDoc", CallDocNode, ExprDocNode)
static void RegisterReflection()
Definition doc.h:498
ffi::Array< ExprDoc > args
The positional arguments.
Definition doc.h:487
ExprDoc callee
The callee of this function call.
Definition doc.h:485
Reference type of CallDocNode.
Definition doc.h:514
TVM_TIRX_DLL CallDoc(ExprDoc callee, ffi::Array< ExprDoc > args, ffi::Array< ffi::String > kwargs_keys, ffi::Array< ExprDoc > kwargs_values)
Constructor of CallDoc.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(CallDoc, ExprDoc, CallDocNode)
Doc that represents class definition.
Definition doc.h:1270
ffi::Array< ExprDoc > decorators
Decorators of class.
Definition doc.h:1275
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.ClassDoc", ClassDocNode, StmtDocNode)
static void RegisterReflection()
Definition doc.h:1279
IdDoc name
The name of class.
Definition doc.h:1273
ffi::Array< StmtDoc > body
The body of class.
Definition doc.h:1277
Reference type of ClassDocNode.
Definition doc.h:1294
TVM_TIRX_DLL ClassDoc(IdDoc name, ffi::Array< ExprDoc > decorators, ffi::Array< StmtDoc > body)
Constructor of ClassDoc.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ClassDoc, StmtDoc, ClassDocNode)
Doc that represents comment.
Definition doc.h:1312
static void RegisterReflection()
Definition doc.h:1314
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.CommentDoc", CommentDocNode, StmtDocNode)
Reference type of CommentDocNode.
Definition doc.h:1326
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(CommentDoc, StmtDoc, CommentDocNode)
TVM_TIRX_DLL CommentDoc(ffi::String comment)
Doc that represents continue statement.
Definition doc.h:968
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.ContinueDoc", ContinueDocNode, StmtDocNode)
static void RegisterReflection()
Definition doc.h:970
Reference type of ContinueDocNode.
Definition doc.h:983
TVM_TIRX_DLL ContinueDoc()
Constructor of ContinueDoc.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ContinueDoc, StmtDoc, ContinueDocNode)
Doc that represents dictionary literal.
Definition doc.h:724
ffi::Array< ExprDoc > keys
keys of dictionary
Definition doc.h:727
static void RegisterReflection()
Definition doc.h:736
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.DictDoc", DictDocNode, ExprDocNode)
ffi::Array< ExprDoc > values
Values of dictionary.
Definition doc.h:734
Reference type of DictDocNode.
Definition doc.h:750
TVM_TIRX_DLL DictDoc(ffi::Array< ExprDoc > keys, ffi::Array< ExprDoc > values)
Constructor of DictDoc.
DictDoc()
Create an empty dictionary.
Definition doc.h:755
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(DictDoc, ExprDoc, DictDocNode)
The base class of all Doc.
Definition doc.h:48
static constexpr bool _type_mutable
Definition doc.h:64
virtual ~DocNode()=default
TVM_FFI_DECLARE_OBJECT_INFO("script.printer.Doc", DocNode, ffi::Object)
static void RegisterReflection()
Definition doc.h:59
ffi::Array< AccessPath > source_paths
The list of object paths of the source IR node.
Definition doc.h:57
Doc that represents docstring.
Definition doc.h:1337
static void RegisterReflection()
Definition doc.h:1339
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.DocStringDoc", DocStringDocNode, StmtDocNode)
Reference type of DocStringDocNode.
Definition doc.h:1351
TVM_TIRX_DLL DocStringDoc(ffi::String docs)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(DocStringDoc, StmtDoc, DocStringDocNode)
Reference type of DocNode.
Definition doc.h:77
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Doc, ffi::ObjectRef, DocNode)
The base class of expression doc.
Definition doc.h:92
static void RegisterReflection()
Definition doc.h:122
TVM_FFI_DECLARE_OBJECT_INFO("script.printer.ExprDoc", ExprDocNode, DocNode)
TVM_TIRX_DLL ExprDoc Attr(ffi::String attr) const
Create a doc representing attribute access on the current ExprDoc.
TVM_TIRX_DLL ExprDoc Call(ffi::Array< ExprDoc, void > args) const
Create a doc representing calling the current ExprDoc.
TVM_TIRX_DLL ExprDoc operator[](ffi::Array< Doc > indices) const
Create a doc representing index access on the current ExprDoc.
TVM_TIRX_DLL ExprDoc Call(ffi::Array< ExprDoc, void > args, ffi::Array< ffi::String > kwargs_keys, ffi::Array< ExprDoc, void > kwargs_values) const
Create a doc representing attribute access on the current ExprDoc.
Reference type of ExprDocNode.
Definition doc.h:134
ExprDoc(ffi::ObjectPtr< ExprDocNode > data)
Definition doc.h:145
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ExprDoc, Doc, ExprDocNode)
TVM_TIRX_DLL ExprDoc operator[](ffi::Array< Doc > indices) const
Create a doc representing index access on the current ExprDoc.
Doc that represents an expression as statement.
Definition doc.h:1101
static void RegisterReflection()
Definition doc.h:1106
ExprDoc expr
The expression represented by this doc.
Definition doc.h:1104
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.ExprStmtDoc", ExprStmtDocNode, StmtDocNode)
Reference type of ExprStmtDocNode.
Definition doc.h:1118
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ExprStmtDoc, StmtDoc, ExprStmtDocNode)
TVM_TIRX_DLL ExprStmtDoc(ExprDoc expr)
Constructor of ExprStmtDoc.
Doc that renders an expression as a Python string literal.
Definition doc.h:335
static void RegisterReflection()
Definition doc.h:340
ExprDoc value
The expression to render as a string.
Definition doc.h:338
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.ExprStringDoc", ExprStringDocNode, ExprDocNode)
Reference type of ExprStringDocNode.
Definition doc.h:352
TVM_TIRX_DLL ExprStringDoc(ExprDoc value, const ffi::Optional< AccessPath > &object_path)
Constructor of ExprStringDoc.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ExprStringDoc, ExprDoc, ExprStringDocNode)
Doc that represents for statement.
Definition doc.h:1001
ffi::Array< StmtDoc > body
The body of the for statement.
Definition doc.h:1008
ExprDoc lhs
The left hand side of the assignment of iterating variable.
Definition doc.h:1004
static void RegisterReflection()
Definition doc.h:1010
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.ForDoc", ForDocNode, StmtDocNode)
ExprDoc rhs
The right hand side of the assignment of iterating variable.
Definition doc.h:1006
Reference type of ForDocNode.
Definition doc.h:1025
TVM_TIRX_DLL ForDoc(ExprDoc lhs, ExprDoc rhs, ffi::Array< StmtDoc > body)
Constructor of ForDoc.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ForDoc, StmtDoc, ForDocNode)
Doc that represents function definition.
Definition doc.h:1202
ffi::Array< AssignDoc > args
The arguments of function.
Definition doc.h:1213
ffi::Array< Doc > type_params
The PEP 695 type parameters of the function.
Definition doc.h:1227
ffi::Array< StmtDoc > body
The body of function.
Definition doc.h:1219
IdDoc name
The name of function.
Definition doc.h:1205
static void RegisterReflection()
Definition doc.h:1229
ffi::Array< ExprDoc > decorators
Decorators of function.
Definition doc.h:1215
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.FunctionDoc", FunctionDocNode, StmtDocNode)
ffi::Optional< ExprDoc > return_type
The return type of function.
Definition doc.h:1217
Reference type of FunctionDocNode.
Definition doc.h:1247
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(FunctionDoc, StmtDoc, FunctionDocNode)
TVM_TIRX_DLL FunctionDoc(IdDoc name, ffi::Array< AssignDoc > args, ffi::Array< ExprDoc > decorators, ffi::Optional< ExprDoc > return_type, ffi::Array< StmtDoc > body, ffi::Array< Doc > type_params={})
Constructor of FunctionDoc.
Doc that represents identifier.
Definition doc.h:369
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.IdDoc", IdDocNode, ExprDocNode)
ffi::String name
The name of the identifier.
Definition doc.h:372
static void RegisterReflection()
Definition doc.h:374
Reference type of IdDocNode.
Definition doc.h:386
IdDoc(std::nullptr_t)
Definition doc.h:393
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(IdDoc, ExprDoc, IdDocNode)
TVM_TIRX_DLL IdDoc(ffi::String name)
Constructor of IdDoc.
Doc that represent if-then-else statement.
Definition doc.h:860
static void RegisterReflection()
Definition doc.h:869
ffi::Optional< ffi::Array< StmtDoc > > else_branch
The optional else branch; an empty array represents a present empty branch.
Definition doc.h:867
ffi::Array< StmtDoc > then_branch
The then branch of the if-then-else statement.
Definition doc.h:865
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.IfDoc", IfDocNode, StmtDocNode)
ExprDoc predicate
The predicate of the if-then-else statement.
Definition doc.h:863
Reference type of IfDocNode.
Definition doc.h:884
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(IfDoc, StmtDoc, IfDocNode)
TVM_TIRX_DLL IfDoc(ExprDoc predicate, ffi::Array< StmtDoc > then_branch, ffi::Optional< ffi::Array< StmtDoc > > else_branch)
Constructor of IfDoc.
Doc that represents index access on another expression.
Definition doc.h:439
static void RegisterReflection()
Definition doc.h:452
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.IndexDoc", IndexDocNode, ExprDocNode)
ffi::Array< Doc > indices
The indices to access.
Definition doc.h:450
ExprDoc value
The container value to be accessed.
Definition doc.h:442
Reference type of IndexDocNode.
Definition doc.h:466
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(IndexDoc, ExprDoc, IndexDocNode)
TVM_TIRX_DLL IndexDoc(ExprDoc value, ffi::Array< Doc > indices)
Constructor of IndexDoc.
Doc that represents anonymous function.
Definition doc.h:615
static void RegisterReflection()
Definition doc.h:622
ExprDoc body
The body of this anonymous function.
Definition doc.h:620
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.LambdaDoc", LambdaDocNode, ExprDocNode)
ffi::Array< IdDoc > args
The arguments of this anonymous function.
Definition doc.h:618
Reference type of LambdaDocNode.
Definition doc.h:636
TVM_TIRX_DLL LambdaDoc(ffi::Array< IdDoc > args, ExprDoc body)
Constructor of LambdaDoc.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(LambdaDoc, ExprDoc, LambdaDocNode)
Doc that represents list literal.
Definition doc.h:688
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.ListDoc", ListDocNode, ExprDocNode)
ffi::Array< ExprDoc > elements
Elements of list.
Definition doc.h:691
static void RegisterReflection()
Definition doc.h:693
Reference type of ListDocNode.
Definition doc.h:705
TVM_TIRX_DLL ListDoc(ffi::Array< ExprDoc > elements)
Constructor of ListDoc.
ListDoc()
Create an empty ListDoc.
Definition doc.h:710
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ListDoc, ExprDoc, ListDocNode)
Doc that represents literal value.
Definition doc.h:227
ffi::Any value
the internal representation of the literal value.
Definition doc.h:238
static void RegisterReflection()
Definition doc.h:240
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.LiteralDoc", LiteralDocNode, ExprDocNode)
Reference type of LiteralDocNode.
Definition doc.h:252
static LiteralDoc DataType(DLDataType v, const ffi::Optional< AccessPath > &p)
Create a LiteralDoc to represent string.
Definition doc.h:311
static LiteralDoc Boolean(bool v, const ffi::Optional< AccessPath > &p)
Create a LiteralDoc to represent boolean.
Definition doc.h:287
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(LiteralDoc, ExprDoc, LiteralDocNode)
static LiteralDoc Device(const DLDevice &v, const ffi::Optional< AccessPath > &p)
Create a LiteralDoc to represent device.
Definition doc.h:321
TVM_TIRX_DLL LiteralDoc(ffi::Any value, const ffi::Optional< AccessPath > &object_path)
static LiteralDoc Int(IntImm v, const ffi::Optional< AccessPath > &p)
Create an integer literal preserving its typed payload.
Definition doc.h:279
static LiteralDoc Int(int64_t v, const ffi::Optional< AccessPath > &p)
Create a LiteralDoc to represent integer.
Definition doc.h:269
static LiteralDoc Float(double v, const ffi::Optional< AccessPath > &p)
Create a LiteralDoc to represent float.
Definition doc.h:295
static LiteralDoc None(const ffi::Optional< AccessPath > &p)
Create a LiteralDoc to represent None/null/empty value.
Definition doc.h:261
static LiteralDoc Str(const ffi::String &v, const ffi::Optional< AccessPath > &p)
Create a LiteralDoc to represent string.
Definition doc.h:303
A reference to a canonical script namespace.
Definition doc.h:1362
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.NamespaceDoc", NamespaceDocNode, ExprDocNode)
static void RegisterReflection()
Definition doc.h:1367
ffi::String canonical_name
The namespace name before alias resolution.
Definition doc.h:1365
An owning reference to a deferred script namespace.
Definition doc.h:1377
TVM_TIRX_DLL NamespaceDoc(ffi::String canonical_name)
Construct a deferred namespace reference.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(NamespaceDoc, ExprDoc, NamespaceDocNode)
Doc that represents operation.
Definition doc.h:536
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.OperationDoc", OperationDocNode, ExprDocNode)
ffi::Array< ExprDoc > operands
Operands of this expression.
Definition doc.h:580
Kind kind
The kind of operation (operator)
Definition doc.h:578
static void RegisterReflection()
Definition doc.h:582
Reference type of OperationDocNode.
Definition doc.h:596
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(OperationDoc, ExprDoc, OperationDocNode)
TVM_TIRX_DLL OperationDoc(OperationDocNode::Kind kind, ffi::Array< ExprDoc > operands)
Constructor of OperationDoc.
Doc that represents return statement.
Definition doc.h:1170
ExprDoc value
The value to return.
Definition doc.h:1173
static void RegisterReflection()
Definition doc.h:1175
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.ReturnDoc", ReturnDocNode, StmtDocNode)
Reference type of ReturnDocNode.
Definition doc.h:1187
TVM_TIRX_DLL ReturnDoc(ExprDoc value)
Constructor of ReturnDoc.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ReturnDoc, StmtDoc, ReturnDocNode)
Doc that represents special scopes.
Definition doc.h:1047
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.ScopeDoc", ScopeDocNode, StmtDocNode)
bool allow_concise_scoping
Whether a tail-position renderer may spell this scope concisely.
Definition doc.h:1056
ffi::Optional< ExprDoc > lhs
The name of the scoped variable.
Definition doc.h:1050
ExprDoc rhs
The value of the scoped variable.
Definition doc.h:1052
static void RegisterReflection()
Definition doc.h:1058
ffi::Array< StmtDoc > body
The body of the scope doc.
Definition doc.h:1054
Reference type of ScopeDocNode.
Definition doc.h:1074
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ScopeDoc, StmtDoc, ScopeDocNode)
TVM_TIRX_DLL ScopeDoc(ExprDoc rhs, ffi::Array< StmtDoc > body)
Constructor of ScopeDoc.
TVM_TIRX_DLL ScopeDoc(ffi::Optional< ExprDoc > lhs, ExprDoc rhs, ffi::Array< StmtDoc > body, bool allow_concise_scoping=false)
Constructor of ScopeDoc.
Doc that represents slice in Index expression.
Definition doc.h:772
ffi::Optional< ExprDoc > start
The start of slice.
Definition doc.h:775
ffi::Optional< ExprDoc > step
The step of slice.
Definition doc.h:779
ffi::Optional< ExprDoc > stop
The exclusive end of slice.
Definition doc.h:777
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.SliceDoc", SliceDocNode, DocNode)
static void RegisterReflection()
Definition doc.h:781
Reference type of SliceDocNode.
Definition doc.h:796
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(SliceDoc, Doc, SliceDocNode)
TVM_TIRX_DLL SliceDoc(ffi::Optional< ExprDoc > start, ffi::Optional< ExprDoc > stop, ffi::Optional< ExprDoc > step)
Constructor of SliceDoc.
The container doc that holds a list of StmtDoc.
Definition doc.h:196
static void RegisterReflection()
Definition doc.h:201
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.StmtBlockDoc", StmtBlockDocNode, DocNode)
ffi::Array< StmtDoc > stmts
The list of statements.
Definition doc.h:199
Reference type of StmtBlockDocNode.
Definition doc.h:212
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(StmtBlockDoc, Doc, StmtBlockDocNode)
TVM_TIRX_DLL StmtBlockDoc(ffi::Array< StmtDoc > stmts)
Constructor of StmtBlockDoc.
The base class of statement doc.
Definition doc.h:158
ffi::Optional< ffi::String > comment
The comment of this doc.
Definition doc.h:168
static void RegisterReflection()
Definition doc.h:170
TVM_FFI_DECLARE_OBJECT_INFO("script.printer.StmtDoc", StmtDocNode, DocNode)
Reference type of StmtDocNode.
Definition doc.h:182
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(StmtDoc, Doc, StmtDocNode)
Doc that represents tuple literal.
Definition doc.h:652
ffi::Array< ExprDoc > elements
Elements of tuple.
Definition doc.h:655
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.TupleDoc", TupleDocNode, ExprDocNode)
static void RegisterReflection()
Definition doc.h:657
Reference type of TupleDocNode.
Definition doc.h:669
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TupleDoc, ExprDoc, TupleDocNode)
TVM_TIRX_DLL TupleDoc(ffi::Array< ExprDoc > elements)
Constructor of TupleDoc.
TupleDoc()
Create an empty TupleDoc.
Definition doc.h:674
Doc that represents while statement.
Definition doc.h:902
static void RegisterReflection()
Definition doc.h:909
ffi::Array< StmtDoc > body
The body of the while statement.
Definition doc.h:907
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.printer.WhileDoc", WhileDocNode, StmtDocNode)
ExprDoc predicate
The predicate of the while statement.
Definition doc.h:905
Reference type of WhileDocNode.
Definition doc.h:923
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(WhileDoc, StmtDoc, WhileDocNode)
TVM_TIRX_DLL WhileDoc(ExprDoc predicate, ffi::Array< StmtDoc > body)
Constructor of WhileDoc.
Abstract device memory management API.
Base expr nodes in TVM.
IR/AST nodes for TVM types shared across IR variants.
std::ostream & operator<<(std::ostream &os, DLDevice dev)
Definition device_api.h:313
ffi::reflection::AccessPath AccessPath
Definition doc.h:35
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
#define TVM_TIRX_DLL
Definition base.h:83