tvm
Loading...
Searching...
No Matches
stmt.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 */
22#ifndef TVM_IR_STMT_H_
23#define TVM_IR_STMT_H_
24
25#include <tvm/ffi/reflection/registry.h>
26#include <tvm/ir/op.h>
27#include <tvm/ir/prim/expr.h>
28
29#include <initializer_list>
30#include <optional>
31#include <string>
32#include <utility>
33
34namespace tvm {
35
37class StmtNode : public ffi::Object {
38 public:
43 mutable Location loc = UnknownLoc();
44
45 StmtNode() = default;
46 explicit StmtNode(Location loc) : loc(loc) {}
47
48 static void RegisterReflection() {
49 namespace refl = tvm::ffi::reflection;
50 refl::ObjectDef<StmtNode>().def_ro("loc", &StmtNode::loc,
51 refl::AttachFieldFlag::SEqHashIgnore());
52 }
53
54 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
55 static constexpr bool _type_s_eq_hash_subclass_kind_fixed = true;
56
57 static constexpr const uint32_t _type_child_slots = 15;
58 TVM_FFI_DECLARE_OBJECT_INFO("ir.Stmt", StmtNode, ffi::Object);
59};
60
62class Stmt : public ffi::ObjectRef {
63 public:
64 explicit Stmt(ffi::ObjectPtr<StmtNode> node) : ffi::ObjectRef(std::move(node)) {
65 TVM_FFI_CHECK(defined(), ValueError) << "Stmt expects a defined node";
66 }
67
69};
70
75class SeqStmtNode : public StmtNode {
76 public:
78 ffi::Array<Stmt> seq;
79
81 size_t size() const { return seq.size(); }
85 Stmt operator[](size_t index) const { return seq[index]; }
86
89};
90
92class SeqStmt : public Stmt {
93 public:
99 TVM_TIRX_DLL explicit SeqStmt(ffi::Array<Stmt> seq, Location loc = UnknownLoc());
101 TVM_TIRX_DLL SeqStmt(Stmt stmt, ffi::Optional<Location> loc = std::nullopt);
102 SeqStmt(std::initializer_list<Stmt> seq, Location loc = UnknownLoc())
103 : SeqStmt(ffi::Array<Stmt>(seq), std::move(loc)) {}
104
106 size_t size() const { return operator->()->size(); }
110 Stmt operator[](size_t index) const { return (*(operator->()))[index]; }
111 explicit SeqStmt(ffi::ObjectPtr<SeqStmtNode> node) : Stmt(std::move(node)) {}
112
115};
116
117namespace ffi {
118template <>
119inline constexpr bool use_default_type_traits_v<SeqStmt> = false;
120
121template <>
122struct TypeTraits<SeqStmt> : public ObjectRefWithFallbackTraitsBase<SeqStmt, Stmt, Array<Stmt>> {
123 static SeqStmt ConvertFallbackValue(Stmt stmt) { return SeqStmt(std::move(stmt)); }
124 static SeqStmt ConvertFallbackValue(Array<Stmt> seq) { return SeqStmt(std::move(seq)); }
125};
126} // namespace ffi
127
135class BindNode : public StmtNode {
136 public:
137 explicit BindNode(ffi::UnsafeInit tag) : var(tag), value(tag) {}
138
139 BindNode(Var var, Expr value) : var(std::move(var)), value(std::move(value)) {}
140
145
146 static void RegisterReflection() {
147 namespace refl = tvm::ffi::reflection;
148 refl::ObjectDef<BindNode>()
149 .def_ro("var", &BindNode::var, refl::AttachFieldFlag::SEqHashDefSimple())
150 .def_ro("value", &BindNode::value);
151 }
153};
154
159class Bind : public Stmt {
160 public:
162
163 explicit Bind(ffi::ObjectPtr<BindNode> node) : Stmt(std::move(node)) {}
164
167};
168
172TVM_TIRX_DLL bool IsRegionOp(const Op& op);
173
182TVM_TIRX_DLL ffi::Array<Var> GetRegionBodyParams(Op op, ffi::Array<Expr> args, DictAttrs attrs);
183
189class RegionStmtNode : public StmtNode {
190 public:
194 ffi::Array<Expr> args;
196 ffi::Array<Var> body_params;
202 ffi::Array<Var> result_vars;
203
204 explicit RegionStmtNode(ffi::UnsafeInit tag) : op(tag), body(tag) {}
205
206 RegionStmtNode(Op op, SeqStmt body) : op(std::move(op)), body(std::move(body)) {}
207
208 static void RegisterReflection() {
209 namespace refl = tvm::ffi::reflection;
210 refl::ObjectDef<RegionStmtNode>()
211 .def_ro("op", &RegionStmtNode::op)
212 .def_ro("attrs", &RegionStmtNode::attrs)
213 .def_ro("args", &RegionStmtNode::args)
214 .def_ro("body_params", &RegionStmtNode::body_params,
215 refl::AttachFieldFlag::SEqHashDefSimple())
216 .def_ro("body", &RegionStmtNode::body)
217 .def_ro("result_vars", &RegionStmtNode::result_vars,
218 refl::AttachFieldFlag::SEqHashDefSimple());
219 }
221};
222
224class RegionStmt : public Stmt {
225 public:
226 TVM_TIRX_DLL RegionStmt(Op op, ffi::Array<Expr> args, ffi::Array<Var> body_params,
227 DictAttrs attrs, SeqStmt body, ffi::Array<Var> result_vars = {},
228 Location loc = UnknownLoc());
229
230 explicit RegionStmt(ffi::ObjectPtr<RegionStmtNode> node) : Stmt(std::move(node)) {}
231
234};
235
246 ffi::reflection::NativeFunctionView<ffi::Array<Var>(const CallNode* call)>;
247
249using FRegionValidate = ffi::reflection::NativeFunctionView<void(const RegionStmtNode*)>;
250
260class AssertStmtNode : public StmtNode {
261 public:
262 explicit AssertStmtNode(ffi::UnsafeInit tag) : condition(tag), error_kind(tag) {}
263
266
272 ffi::Array<StringImm> message_parts;
273
274 static void RegisterReflection() {
275 namespace refl = tvm::ffi::reflection;
276 refl::ObjectDef<AssertStmtNode>()
277 .def_ro("condition", &AssertStmtNode::condition)
278 .def_ro("error_kind", &AssertStmtNode::error_kind)
279 .def_ro("message_parts", &AssertStmtNode::message_parts);
280 }
282};
283
288class AssertStmt : public Stmt {
289 public:
291 ffi::Array<StringImm> message_parts, Location loc = UnknownLoc());
292
293 explicit AssertStmt(ffi::ObjectPtr<AssertStmtNode> node) : Stmt(std::move(node)) {}
294
297};
298
308class TensorStoreNode : public StmtNode {
309 public:
310 explicit TensorStoreNode(ffi::UnsafeInit tag) : dest(tag), value(tag) {}
311
312 TensorStoreNode(Expr dest, PrimExpr value) : dest(std::move(dest)), value(std::move(value)) {}
313
317 ffi::Array<PrimExpr> indices;
320
321 static void RegisterReflection() {
322 namespace refl = tvm::ffi::reflection;
323 refl::ObjectDef<TensorStoreNode>()
324 .def_ro("dest", &TensorStoreNode::dest)
325 .def_ro("indices", &TensorStoreNode::indices)
326 .def_ro("value", &TensorStoreNode::value);
327 }
329};
330
335class TensorStore : public Stmt {
336 public:
337 TVM_TIRX_DLL explicit TensorStore(Expr dest, ffi::Array<PrimExpr> indices, PrimExpr value,
338 Location loc = UnknownLoc());
339
340 explicit TensorStore(ffi::ObjectPtr<TensorStoreNode> node) : Stmt(std::move(node)) {}
341
344};
345
352class EvaluateNode : public StmtNode {
353 public:
354 explicit EvaluateNode(ffi::UnsafeInit tag) : value(tag) {}
355
356 explicit EvaluateNode(Expr value) : value(std::move(value)) {}
357
360
361 static void RegisterReflection() {
362 namespace refl = tvm::ffi::reflection;
363 refl::ObjectDef<EvaluateNode>().def_ro("value", &EvaluateNode::value);
364 }
366};
367
372class Evaluate : public Stmt {
373 public:
374 TVM_TIRX_DLL explicit Evaluate(Expr value, Location loc = UnknownLoc());
375
376 explicit Evaluate(int value, Location loc = UnknownLoc()) : Evaluate(PrimExpr(value), loc) {}
377
378 explicit Evaluate(ffi::ObjectPtr<EvaluateNode> node) : Stmt(std::move(node)) {}
379
382};
383
387class IfNode : public StmtNode {
388 public:
389 explicit IfNode(ffi::UnsafeInit tag) : condition(tag), then_case(tag) {}
390
393
399 ffi::Optional<SeqStmt> else_case;
400
401 static void RegisterReflection() {
402 namespace refl = tvm::ffi::reflection;
403 refl::ObjectDef<IfNode>()
404 .def_ro("condition", &IfNode::condition)
405 .def_ro("then_case", &IfNode::then_case)
406 .def_ro("else_case", &IfNode::else_case);
407 }
409};
410
415class If : public Stmt {
416 public:
417 TVM_TIRX_DLL If(PrimExpr condition, SeqStmt then_case,
418 ffi::Optional<SeqStmt> else_case = std::nullopt, Location loc = UnknownLoc());
419
420 explicit If(ffi::ObjectPtr<IfNode> node) : Stmt(std::move(node)) {}
421
424};
425
433enum class ForKind : int {
435 kDefault = 0,
437 kParallel = 1,
442 kVectorized = 2,
444 kUnrolled = 3,
445};
446
457class ForNode : public StmtNode {
458 public:
459 explicit ForNode(ffi::UnsafeInit tag) : loop_var(tag), min(tag), extent(tag), body(tag) {}
460
462 : loop_var(std::move(loop_var)),
463 min(std::move(min)),
464 extent(std::move(extent)),
465 body(std::move(body)) {}
466
483 ffi::Map<ffi::String, ffi::Any> annotations;
487 ffi::Optional<PrimExpr> step;
488
489 static void RegisterReflection() {
490 namespace refl = tvm::ffi::reflection;
491 refl::ObjectDef<ForNode>()
492 .def_ro("loop_var", &ForNode::loop_var, refl::AttachFieldFlag::SEqHashDefSimple())
493 .def_ro("min", &ForNode::min)
494 .def_ro("extent", &ForNode::extent)
495 .def_ro("kind", &ForNode::kind)
496 .def_ro("body", &ForNode::body)
497 .def_ro("annotations", &ForNode::annotations)
498 .def_ro("step", &ForNode::step);
499 }
500
502 bool HasTrivialStep() const;
503
505};
506
511class For : public Stmt {
512 public:
514 ffi::Map<ffi::String, ffi::Any> annotations = {},
515 ffi::Optional<PrimExpr> step = std::nullopt, Location loc = UnknownLoc());
516
517 explicit For(ffi::ObjectPtr<ForNode> node) : Stmt(std::move(node)) {}
518
521};
522
533class WhileNode : public StmtNode {
534 public:
535 explicit WhileNode(ffi::UnsafeInit tag) : condition(tag), body(tag) {}
536
538 : condition(std::move(condition)), body(std::move(body)) {}
539
544
545 static void RegisterReflection() {
546 namespace refl = tvm::ffi::reflection;
547 refl::ObjectDef<WhileNode>()
548 .def_ro("condition", &WhileNode::condition)
549 .def_ro("body", &WhileNode::body);
550 }
552};
553
558class While : public Stmt {
559 public:
561
562 explicit While(ffi::ObjectPtr<WhileNode> node) : Stmt(std::move(node)) {}
563
566};
567
571class ReturnNode : public StmtNode {
572 public:
573 explicit ReturnNode(ffi::UnsafeInit tag) : value(tag) {}
574
575 explicit ReturnNode(Expr value) : value(std::move(value)) {}
576
579
580 static void RegisterReflection() {
581 namespace refl = tvm::ffi::reflection;
582 refl::ObjectDef<ReturnNode>().def_ro("value", &ReturnNode::value);
583 }
584
586};
587
592class Return : public Stmt {
593 public:
594 TVM_TIRX_DLL explicit Return(Expr value, Location loc = UnknownLoc());
595
596 explicit Return(ffi::ObjectPtr<ReturnNode> node) : Stmt(std::move(node)) {}
597
600};
601
605class BreakNode : public StmtNode {
606 public:
607 static void RegisterReflection() {
608 namespace refl = tvm::ffi::reflection;
609 refl::ObjectDef<BreakNode>();
610 }
611
613};
614
619class Break : public Stmt {
620 public:
622
623 explicit Break(ffi::ObjectPtr<BreakNode> node) : Stmt(std::move(node)) {}
624
627};
628
632class ContinueNode : public StmtNode {
633 public:
634 static void RegisterReflection() {
635 namespace refl = tvm::ffi::reflection;
636 refl::ObjectDef<ContinueNode>();
637 }
638
640};
641
646class Continue : public Stmt {
647 public:
649
650 explicit Continue(ffi::ObjectPtr<ContinueNode> node) : Stmt(std::move(node)) {}
651
654};
655
656// overload printing of for type.
657TVM_TIRX_DLL std::ostream& operator<<(std::ostream& os, ForKind kind);
658
659// inline implementations
660inline const char* ForKind2String(ForKind t) {
661 switch (t) {
663 return "serial";
665 return "parallel";
667 return "vectorized";
669 return "unroll";
670 }
671 TVM_FFI_THROW(InternalError) << "Unknown ForKind" << t;
672 TVM_FFI_UNREACHABLE();
673}
674
675namespace op_attr {
676inline constexpr const char* kRegionGetBodyParams = "FRegionGetBodyParams";
677inline constexpr const char* kRegionValidate = "FRegionValidate";
678} // namespace op_attr
679
680namespace type_attr {
681inline constexpr const char* kEvaluateValidate = "__evaluate_validate__";
682inline constexpr const char* kTensorStoreValidate = "__tensor_store_validate__";
683} // namespace type_attr
684
685} // namespace tvm
686#endif // TVM_IR_STMT_H_
Assert condition, if an error occurs, return the error message.
Definition stmt.h:260
static void RegisterReflection()
Definition stmt.h:274
ffi::Array< StringImm > message_parts
Error message fragments, concatenated at runtime when assertion fails.
Definition stmt.h:272
PrimExpr condition
Condition to be checked.
Definition stmt.h:268
AssertStmtNode(PrimExpr condition, StringImm error_kind)
Definition stmt.h:264
StringImm error_kind
The error kind, e.g. "RuntimeError", "TypeError", "ValueError".
Definition stmt.h:270
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.AssertStmt", AssertStmtNode, StmtNode)
AssertStmtNode(ffi::UnsafeInit tag)
Definition stmt.h:262
Managed reference to AssertStmtNode.
Definition stmt.h:288
TVM_DEFINE_OBJECT_REF_COW_METHOD(AssertStmtNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(AssertStmt, Stmt, AssertStmtNode)
AssertStmt(ffi::ObjectPtr< AssertStmtNode > node)
Definition stmt.h:293
TVM_TIRX_DLL AssertStmt(PrimExpr condition, StringImm error_kind, ffi::Array< StringImm > message_parts, Location loc=UnknownLoc())
Bind a variable to a value in the enclosing scope.
Definition stmt.h:135
Var var
The variable being bound.
Definition stmt.h:142
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Bind", BindNode, StmtNode)
BindNode(Var var, Expr value)
Definition stmt.h:139
Expr value
The value to bind to the variable.
Definition stmt.h:144
static void RegisterReflection()
Definition stmt.h:146
BindNode(ffi::UnsafeInit tag)
Definition stmt.h:137
Managed reference to BindNode.
Definition stmt.h:159
Bind(ffi::ObjectPtr< BindNode > node)
Definition stmt.h:163
TVM_DEFINE_OBJECT_REF_COW_METHOD(BindNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Bind, Stmt, BindNode)
TVM_TIRX_DLL Bind(Var var, Expr value, Location loc=UnknownLoc())
A Break in control flow.
Definition stmt.h:605
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Break", BreakNode, StmtNode)
static void RegisterReflection()
Definition stmt.h:607
Managed reference to BreakNode.
Definition stmt.h:619
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Break, Stmt, BreakNode)
Break(ffi::ObjectPtr< BreakNode > node)
Definition stmt.h:623
TVM_TIRX_DLL Break(Location loc)
TVM_DEFINE_OBJECT_REF_COW_METHOD(BreakNode)
Call corresponds to callable invocation.
Definition expr.h:935
A Continue in control flow.
Definition stmt.h:632
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Continue", ContinueNode, StmtNode)
static void RegisterReflection()
Definition stmt.h:634
Managed reference to ContinueNode.
Definition stmt.h:646
TVM_DEFINE_OBJECT_REF_COW_METHOD(ContinueNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Continue, Stmt, ContinueNode)
Continue(ffi::ObjectPtr< ContinueNode > node)
Definition stmt.h:650
TVM_TIRX_DLL Continue(Location loc)
Managed reference to DictAttrsNode.
Definition attrs.h:108
Evaluates an expression. This is mostly used for putting a Call node into Stmt.
Definition stmt.h:352
EvaluateNode(ffi::UnsafeInit tag)
Definition stmt.h:354
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Evaluate", EvaluateNode, StmtNode)
static void RegisterReflection()
Definition stmt.h:361
Expr value
The expression to be evaluated.
Definition stmt.h:359
EvaluateNode(Expr value)
Definition stmt.h:356
Managed reference to EvaluateNode.
Definition stmt.h:372
Evaluate(int value, Location loc=UnknownLoc())
Definition stmt.h:376
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Evaluate, Stmt, EvaluateNode)
TVM_TIRX_DLL Evaluate(Expr value, Location loc=UnknownLoc())
TVM_DEFINE_OBJECT_REF_COW_METHOD(EvaluateNode)
Evaluate(ffi::ObjectPtr< EvaluateNode > node)
Definition stmt.h:378
Managed reference to ExprNode.
Definition base_expr.h:359
A for loop, with possible type annotations.
Definition stmt.h:457
ForNode(PrimVar loop_var, PrimExpr min, PrimExpr extent, SeqStmt body)
Definition stmt.h:461
SeqStmt body
The body of the for loop.
Definition stmt.h:476
ForNode(ffi::UnsafeInit tag)
Definition stmt.h:459
PrimExpr min
The minimum value of iteration.
Definition stmt.h:470
ForKind kind
The kind of the for loop.
Definition stmt.h:474
static void RegisterReflection()
Definition stmt.h:489
PrimExpr extent
The extent of the iteration.
Definition stmt.h:472
ffi::Optional< PrimExpr > step
The loop step. It is one if not specified.
Definition stmt.h:487
ffi::Map< ffi::String, ffi::Any > annotations
Additional annotations about the loop.
Definition stmt.h:483
bool HasTrivialStep() const
Check it is a loop without nontrivial loop step.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.For", ForNode, StmtNode)
PrimVar loop_var
The loop variable.
Definition stmt.h:468
Managed reference to ForNode.
Definition stmt.h:511
TVM_DEFINE_OBJECT_REF_COW_METHOD(ForNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(For, Stmt, ForNode)
For(ffi::ObjectPtr< ForNode > node)
Definition stmt.h:517
TVM_TIRX_DLL For(PrimVar loop_var, PrimExpr min, PrimExpr extent, ForKind kind, SeqStmt body, ffi::Map< ffi::String, ffi::Any > annotations={}, ffi::Optional< PrimExpr > step=std::nullopt, Location loc=UnknownLoc())
If statement.
Definition stmt.h:387
IfNode(PrimExpr condition, SeqStmt then_case)
Definition stmt.h:391
ffi::Optional< SeqStmt > else_case
The branch to be executed when condition is false, can be null.
Definition stmt.h:399
PrimExpr condition
The condition.
Definition stmt.h:395
IfNode(ffi::UnsafeInit tag)
Definition stmt.h:389
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.If", IfNode, StmtNode)
static void RegisterReflection()
Definition stmt.h:401
SeqStmt then_case
The branch to be executed when condition is true.
Definition stmt.h:397
Managed reference to IfNode.
Definition stmt.h:415
If(ffi::ObjectPtr< IfNode > node)
Definition stmt.h:420
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(If, Stmt, IfNode)
TVM_TIRX_DLL If(PrimExpr condition, SeqStmt then_case, ffi::Optional< SeqStmt > else_case=std::nullopt, Location loc=UnknownLoc())
TVM_DEFINE_OBJECT_REF_COW_METHOD(IfNode)
Non-nullable source-location metadata.
Definition location.h:91
Reference-counted handle to a canonical named operator.
Definition op.h:147
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:447
Checked scalar view over a VarNode.
Definition expr.h:742
A single-body statement whose semantics are defined by an operator. Operands are evaluated in the enc...
Definition stmt.h:189
static void RegisterReflection()
Definition stmt.h:208
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.RegionStmt", RegionStmtNode, StmtNode)
DictAttrs attrs
Attributes evaluated in the enclosing scope.
Definition stmt.h:198
RegionStmtNode(ffi::UnsafeInit tag)
Definition stmt.h:204
Op op
Operator defining the region's semantics.
Definition stmt.h:192
ffi::Array< Expr > args
Operands evaluated in the enclosing scope.
Definition stmt.h:194
RegionStmtNode(Op op, SeqStmt body)
Definition stmt.h:206
ffi::Array< Var > result_vars
Variables defined after the region in the enclosing sequence.
Definition stmt.h:202
SeqStmt body
Body evaluated with the body parameters in scope.
Definition stmt.h:200
ffi::Array< Var > body_params
Variables defined at body entry, visible only within the body.
Definition stmt.h:196
Managed reference to RegionStmtNode.
Definition stmt.h:224
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(RegionStmt, Stmt, RegionStmtNode)
RegionStmt(ffi::ObjectPtr< RegionStmtNode > node)
Definition stmt.h:230
TVM_DEFINE_OBJECT_REF_COW_METHOD(RegionStmtNode)
TVM_TIRX_DLL RegionStmt(Op op, ffi::Array< Expr > args, ffi::Array< Var > body_params, DictAttrs attrs, SeqStmt body, ffi::Array< Var > result_vars={}, Location loc=UnknownLoc())
A return from the current function.
Definition stmt.h:571
Expr value
The value to return.
Definition stmt.h:578
ReturnNode(Expr value)
Definition stmt.h:575
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Return", ReturnNode, StmtNode)
ReturnNode(ffi::UnsafeInit tag)
Definition stmt.h:573
static void RegisterReflection()
Definition stmt.h:580
Managed reference to ReturnNode.
Definition stmt.h:592
Return(ffi::ObjectPtr< ReturnNode > node)
Definition stmt.h:596
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Return, Stmt, ReturnNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(ReturnNode)
TVM_TIRX_DLL Return(Expr value, Location loc=UnknownLoc())
The container of seq statement. Represent a sequence of statements.
Definition stmt.h:75
static TVM_TIRX_DLL void RegisterReflection()
ffi::Array< Stmt > seq
internal sequence content.
Definition stmt.h:78
Stmt operator[](size_t index) const
Get the index-th element in the sequence.
Definition stmt.h:85
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.SeqStmt", SeqStmtNode, StmtNode)
size_t size() const
Definition stmt.h:81
Sequence statement.
Definition stmt.h:92
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(SeqStmt, Stmt, SeqStmtNode)
SeqStmt(std::initializer_list< Stmt > seq, Location loc=UnknownLoc())
Definition stmt.h:102
TVM_DEFINE_OBJECT_REF_COW_METHOD(SeqStmtNode)
SeqStmt(ffi::ObjectPtr< SeqStmtNode > node)
Definition stmt.h:111
size_t size() const
Definition stmt.h:106
TVM_TIRX_DLL SeqStmt(Stmt stmt, ffi::Optional< Location > loc=std::nullopt)
Wrap a statement, reusing an existing sequence when possible.
Stmt operator[](size_t index) const
Get the index-th element in the sequence.
Definition stmt.h:110
TVM_TIRX_DLL SeqStmt(ffi::Array< Stmt > seq, Location loc=UnknownLoc())
Construct SeqStmt.
Base node of all statements.
Definition stmt.h:37
static constexpr const uint32_t _type_child_slots
Definition stmt.h:57
Location loc
Location that points to the original source code. Reserved debug information.
Definition stmt.h:43
static void RegisterReflection()
Definition stmt.h:48
static constexpr bool _type_s_eq_hash_subclass_kind_fixed
Definition stmt.h:55
StmtNode(Location loc)
Definition stmt.h:46
TVM_FFI_DECLARE_OBJECT_INFO("ir.Stmt", StmtNode, ffi::Object)
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition stmt.h:54
StmtNode()=default
Container of all statements.
Definition stmt.h:62
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Stmt, ffi::ObjectRef, StmtNode)
Stmt(ffi::ObjectPtr< StmtNode > node)
Definition stmt.h:64
Managed reference to a string literal.
Definition expr.h:99
Store a primitive value to an indexed destination expression.
Definition stmt.h:308
Expr dest
The indexed destination expression.
Definition stmt.h:315
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.TensorStore", TensorStoreNode, StmtNode)
TensorStoreNode(ffi::UnsafeInit tag)
Definition stmt.h:310
static void RegisterReflection()
Definition stmt.h:321
TensorStoreNode(Expr dest, PrimExpr value)
Definition stmt.h:312
PrimExpr value
The value to be stored.
Definition stmt.h:319
ffi::Array< PrimExpr > indices
The indices location to be stored.
Definition stmt.h:317
Managed reference to TensorStoreNode.
Definition stmt.h:335
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TensorStore, Stmt, TensorStoreNode)
TVM_TIRX_DLL TensorStore(Expr dest, ffi::Array< PrimExpr > indices, PrimExpr value, Location loc=UnknownLoc())
TensorStore(ffi::ObjectPtr< TensorStoreNode > node)
Definition stmt.h:340
TVM_DEFINE_OBJECT_REF_COW_METHOD(TensorStoreNode)
Reference to the shared immutable unknown location.
Definition location.h:105
Managed reference to VarNode.
Definition expr.h:714
A While loop.
Definition stmt.h:533
SeqStmt body
The body of the while loop.
Definition stmt.h:543
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.While", WhileNode, StmtNode)
static void RegisterReflection()
Definition stmt.h:545
WhileNode(ffi::UnsafeInit tag)
Definition stmt.h:535
WhileNode(PrimExpr condition, SeqStmt body)
Definition stmt.h:537
PrimExpr condition
The termination condition.
Definition stmt.h:541
Managed reference to WhileNode.
Definition stmt.h:558
While(ffi::ObjectPtr< WhileNode > node)
Definition stmt.h:562
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(While, Stmt, WhileNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(WhileNode)
TVM_TIRX_DLL While(PrimExpr condition, SeqStmt body, Location loc=UnknownLoc())
Canonical primitive operators and their registration.
TIR expressions.
constexpr bool use_default_type_traits_v< SeqStmt >
Definition stmt.h:119
constexpr const char * kRegionGetBodyParams
Definition stmt.h:676
constexpr const char * kRegionValidate
Definition stmt.h:677
constexpr const char * kEvaluateValidate
Definition stmt.h:681
constexpr const char * kTensorStoreValidate
Definition stmt.h:682
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
TVM_TIRX_DLL bool IsRegionOp(const Op &op)
Check FRegionGetBodyParams registration without invoking it or creating variables.
TVM_TIRX_DLL PrimExpr min(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
take minimum of two values
TVM_TIRX_DLL ffi::Array< Var > GetRegionBodyParams(Op op, ffi::Array< Expr > args, DictAttrs attrs)
Validate region operands and construct fresh typed body parameters.
@ kDefault
Default calling convention.
const char * ForKind2String(ForKind t)
Definition stmt.h:660
ForKind
The kind of the loop.
Definition stmt.h:433
@ kUnrolled
The loop body must be unrolled.
@ kDefault
Ordinary loop with sequential iteration semantics.
@ kParallel
Parallel execution.
@ kVectorized
Vector SIMD loop. The loop body will be vectorized.
ffi::reflection::NativeFunctionView< void(const RegionStmtNode *)> FRegionValidate
Optional dialect validation of a complete region statement.
Definition stmt.h:249
ffi::reflection::NativeFunctionView< ffi::Array< Var >(const CallNode *call)> FRegionGetBodyParams
Construct fresh typed variables for a region's lexical body parameters.
Definition stmt.h:246
TVM_TIRX_DLL PrimExpr operator<<(PrimExpr a, PrimExpr b)
left shift operator
#define TVM_TIRX_DLL
Definition base.h:83
static SeqStmt ConvertFallbackValue(Stmt stmt)
Definition stmt.h:123
static SeqStmt ConvertFallbackValue(Array< Stmt > seq)
Definition stmt.h:124