tvm
expr.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 
24 // Acknowledgement: Many low-level IR nodes originate from Halide.
25 #ifndef TVM_TIR_EXPR_H_
26 #define TVM_TIR_EXPR_H_
27 
28 #include <tvm/ffi/container/array.h>
29 #include <tvm/ffi/container/map.h>
30 #include <tvm/ffi/dtype.h>
31 #include <tvm/ffi/string.h>
32 #include <tvm/ir/attrs.h>
33 #include <tvm/ir/cow.h>
34 #include <tvm/ir/expr.h>
35 #include <tvm/ir/node_functor.h>
36 #include <tvm/runtime/base.h>
37 #include <tvm/tirx/buffer.h>
38 #include <tvm/tirx/var.h>
39 
40 #include <algorithm>
41 #include <iostream>
42 #include <limits>
43 #include <string>
44 #include <unordered_map>
45 #include <utility>
46 
47 namespace tvm {
48 namespace tirx {
49 
52 
54 class StringImmNode : public ExprNode {
55  public:
57  ffi::String value;
58  static void RegisterReflection() {
59  namespace refl = tvm::ffi::reflection;
60  refl::ObjectDef<StringImmNode>().def_ro("value", &StringImmNode::value);
61  }
63 };
64 
69 class StringImm : public PrimExpr {
70  public:
71  TVM_DLL StringImm(ffi::String value, Span span = Span());
73  static constexpr bool _type_container_is_exact = true;
75 };
76 
81 class CastNode : public ExprNode {
82  public:
85  static void RegisterReflection() {
86  namespace refl = tvm::ffi::reflection;
87  refl::ObjectDef<CastNode>().def_ro("value", &CastNode::value);
88  }
90 };
91 
96 class Cast : public PrimExpr {
97  public:
98  TVM_DLL Cast(PrimType value_ty, PrimExpr value, Span span = Span());
100  static constexpr bool _type_container_is_exact = true;
102 };
103 
108 template <typename T>
109 class BinaryOpNode : public ExprNode {
110  public:
115  static void RegisterReflection() {
116  namespace refl = tvm::ffi::reflection;
117  refl::ObjectDef<T>().def_ro("a", &T::a).def_ro("b", &T::b);
118  }
119  static const constexpr int _type_child_slots [[maybe_unused]] = 0;
120  static const constexpr bool _type_final [[maybe_unused]] = true;
122 };
123 
125 class AddNode : public BinaryOpNode<AddNode> {
126  public:
127  static constexpr const char* _type_key = "tirx.Add";
128 };
129 
134 class Add : public PrimExpr {
135  public:
136  TVM_DLL Add(PrimExpr a, PrimExpr b, Span span = Span());
138  static constexpr bool _type_container_is_exact = true;
140 };
141 
143 class SubNode : public BinaryOpNode<SubNode> {
144  public:
145  static constexpr const char* _type_key = "tirx.Sub";
146 };
147 
152 class Sub : public PrimExpr {
153  public:
154  TVM_DLL Sub(PrimExpr a, PrimExpr b, Span span = Span());
155 
157  static constexpr bool _type_container_is_exact = true;
159 };
160 
162 class MulNode : public BinaryOpNode<MulNode> {
163  public:
164  static constexpr const char* _type_key = "tirx.Mul";
165 };
166 
171 class Mul : public PrimExpr {
172  public:
173  TVM_DLL Mul(PrimExpr a, PrimExpr b, Span span = Span());
175  static constexpr bool _type_container_is_exact = true;
177 };
178 
183 class DivNode : public BinaryOpNode<DivNode> {
184  public:
185  static constexpr const char* _type_key = "tirx.Div";
186 };
187 
192 class Div : public PrimExpr {
193  public:
194  TVM_DLL Div(PrimExpr a, PrimExpr b, Span span = Span());
196  static constexpr bool _type_container_is_exact = true;
198 };
199 
204 class ModNode : public BinaryOpNode<ModNode> {
205  public:
206  static constexpr const char* _type_key = "tirx.Mod";
207 };
208 
213 class Mod : public PrimExpr {
214  public:
215  TVM_DLL Mod(PrimExpr a, PrimExpr b, Span span = Span());
217  static constexpr bool _type_container_is_exact = true;
219 };
220 
222 class FloorDivNode : public BinaryOpNode<FloorDivNode> {
223  public:
224  static constexpr const char* _type_key = "tirx.FloorDiv";
225 };
226 
231 class FloorDiv : public PrimExpr {
232  public:
233  TVM_DLL FloorDiv(PrimExpr a, PrimExpr b, Span span = Span());
235  static constexpr bool _type_container_is_exact = true;
237 };
238 
240 class FloorModNode : public BinaryOpNode<FloorModNode> {
241  public:
242  static constexpr const char* _type_key = "tirx.FloorMod";
243 };
244 
249 class FloorMod : public PrimExpr {
250  public:
251  TVM_DLL FloorMod(PrimExpr a, PrimExpr b, Span span = Span());
253  static constexpr bool _type_container_is_exact = true;
255 };
256 
258 class MinNode : public BinaryOpNode<MinNode> {
259  public:
260  static constexpr const char* _type_key = "tirx.Min";
261 };
262 
267 class Min : public PrimExpr {
268  public:
269  TVM_DLL Min(PrimExpr a, PrimExpr b, Span span = Span());
271  static constexpr bool _type_container_is_exact = true;
273 };
274 
276 class MaxNode : public BinaryOpNode<MaxNode> {
277  public:
278  static constexpr const char* _type_key = "tirx.Max";
279 };
280 
285 class Max : public PrimExpr {
286  public:
287  TVM_DLL Max(PrimExpr a, PrimExpr b, Span span = Span());
289  static constexpr bool _type_container_is_exact = true;
291 };
292 
297 template <typename T>
298 class CmpOpNode : public ExprNode {
299  public:
304  static void RegisterReflection() {
305  namespace refl = tvm::ffi::reflection;
306  refl::ObjectDef<T>().def_ro("a", &T::a).def_ro("b", &T::b);
307  }
308  static const constexpr int _type_child_slots [[maybe_unused]] = 0;
309  static const constexpr bool _type_final [[maybe_unused]] = true;
311 };
312 
314 class EQNode : public CmpOpNode<EQNode> {
315  public:
316  static constexpr const char* _type_key = "tirx.EQ";
317 };
318 
323 class EQ : public PrimExpr {
324  public:
325  TVM_DLL EQ(PrimExpr a, PrimExpr b, Span span = Span());
327  static constexpr bool _type_container_is_exact = true;
329 };
330 
332 class NENode : public CmpOpNode<NENode> {
333  public:
334  static constexpr const char* _type_key = "tirx.NE";
335 };
336 
341 class NE : public PrimExpr {
342  public:
343  TVM_DLL NE(PrimExpr a, PrimExpr b, Span span = Span());
345  static constexpr bool _type_container_is_exact = true;
347 };
348 
350 class LTNode : public CmpOpNode<LTNode> {
351  public:
352  static constexpr const char* _type_key = "tirx.LT";
353 };
354 
359 class LT : public PrimExpr {
360  public:
361  TVM_DLL LT(PrimExpr a, PrimExpr b, Span span = Span());
363  static constexpr bool _type_container_is_exact = true;
365 };
366 
368 struct LENode : public CmpOpNode<LENode> {
369  public:
370  static constexpr const char* _type_key = "tirx.LE";
371 };
372 
377 class LE : public PrimExpr {
378  public:
379  TVM_DLL LE(PrimExpr a, PrimExpr b, Span span = Span());
381  static constexpr bool _type_container_is_exact = true;
383 };
384 
386 class GTNode : public CmpOpNode<GTNode> {
387  public:
388  static constexpr const char* _type_key = "tirx.GT";
389 };
390 
395 class GT : public PrimExpr {
396  public:
397  TVM_DLL GT(PrimExpr a, PrimExpr b, Span span = Span());
399  static constexpr bool _type_container_is_exact = true;
401 };
402 
404 class GENode : public CmpOpNode<GENode> {
405  public:
406  static constexpr const char* _type_key = "tirx.GE";
407 };
408 
413 class GE : public PrimExpr {
414  public:
415  TVM_DLL GE(PrimExpr a, PrimExpr b, Span span = Span());
417  static constexpr bool _type_container_is_exact = true;
419 };
420 
422 class AndNode : public ExprNode {
423  public:
428  static void RegisterReflection() {
429  namespace refl = tvm::ffi::reflection;
430  refl::ObjectDef<AndNode>().def_ro("a", &AndNode::a).def_ro("b", &AndNode::b);
431  }
433 };
434 
439 class And : public PrimExpr {
440  public:
441  TVM_DLL And(PrimExpr a, PrimExpr b, Span span = Span());
443  static constexpr bool _type_container_is_exact = true;
445 };
446 
448 class OrNode : public ExprNode {
449  public:
454  static void RegisterReflection() {
455  namespace refl = tvm::ffi::reflection;
456  refl::ObjectDef<OrNode>().def_ro("a", &OrNode::a).def_ro("b", &OrNode::b);
457  }
459 };
460 
465 class Or : public PrimExpr {
466  public:
467  TVM_DLL Or(PrimExpr a, PrimExpr b, Span span = Span());
469  static constexpr bool _type_container_is_exact = true;
471 };
472 
474 class NotNode : public ExprNode {
475  public:
478  static void RegisterReflection() {
479  namespace refl = tvm::ffi::reflection;
480  refl::ObjectDef<NotNode>().def_ro("a", &NotNode::a);
481  }
483 };
484 
489 class Not : public PrimExpr {
490  public:
491  TVM_DLL Not(PrimExpr a, Span span = Span());
493  static constexpr bool _type_container_is_exact = true;
495 };
496 
504 class SelectNode : public ExprNode {
505  public:
512  static void RegisterReflection() {
513  namespace refl = tvm::ffi::reflection;
514  refl::ObjectDef<SelectNode>()
515  .def_ro("condition", &SelectNode::condition)
516  .def_ro("true_value", &SelectNode::true_value)
517  .def_ro("false_value", &SelectNode::false_value);
518  }
520 };
521 
526 class Select : public PrimExpr {
527  public:
528  TVM_DLL Select(PrimExpr condition, PrimExpr true_value, PrimExpr false_value, Span span = Span());
529 
531  static constexpr bool _type_container_is_exact = true;
533 };
534 
545 class BufferLoadNode : public ExprNode {
546  public:
550  ffi::Array<PrimExpr> indices;
552  ffi::Optional<PrimExpr> predicate;
553  static void RegisterReflection() {
554  namespace refl = tvm::ffi::reflection;
555  refl::ObjectDef<BufferLoadNode>()
556  .def_ro("buffer", &BufferLoadNode::buffer)
557  .def_ro("indices", &BufferLoadNode::indices)
558  .def_ro("predicate", &BufferLoadNode::predicate);
559  }
561 
562  private:
572  void LegalizeDType();
573  friend class BufferLoad;
575  friend class VectorTypeRewriter;
576  friend class Vectorizer;
577 };
578 
583 class BufferLoad : public PrimExpr {
584  public:
585  TVM_DLL explicit BufferLoad(Buffer buffer, ffi::Array<PrimExpr> indices,
586  ffi::Optional<PrimExpr> predicate = std::nullopt, Span span = Span());
588  static constexpr bool _type_container_is_exact = true;
590 };
591 
601 class ProducerLoadNode : public ExprNode {
602  public:
606  ffi::Array<PrimExpr> indices;
607  static void RegisterReflection() {
608  namespace refl = tvm::ffi::reflection;
609  refl::ObjectDef<ProducerLoadNode>()
610  .def_ro("producer", &ProducerLoadNode::producer)
611  .def_ro("indices", &ProducerLoadNode::indices);
612  }
614 };
615 
620 class ProducerLoad : public PrimExpr {
621  public:
622  TVM_DLL explicit ProducerLoad(DataProducer producer, ffi::Array<PrimExpr> indices,
623  Span span = Span());
624 
626  static constexpr bool _type_container_is_exact = true;
628 };
629 
639 class RampNode : public ExprNode {
640  public:
647  static void RegisterReflection() {
648  namespace refl = tvm::ffi::reflection;
649  refl::ObjectDef<RampNode>()
650  .def_ro("base", &RampNode::base)
651  .def_ro("stride", &RampNode::stride)
652  .def_ro("lanes", &RampNode::lanes);
653  }
655 };
656 
661 class Ramp : public PrimExpr {
662  public:
663  TVM_DLL Ramp(PrimExpr base, PrimExpr stride, PrimExpr lanes, Span span = Span());
665  static constexpr bool _type_container_is_exact = true;
667 };
668 
670 class BroadcastNode : public ExprNode {
671  public:
676  static void RegisterReflection() {
677  namespace refl = tvm::ffi::reflection;
678  refl::ObjectDef<BroadcastNode>()
679  .def_ro("value", &BroadcastNode::value)
680  .def_ro("lanes", &BroadcastNode::lanes);
681  }
683 };
684 
689 class Broadcast : public PrimExpr {
690  public:
691  TVM_DLL Broadcast(PrimExpr value, PrimExpr lanes, Span span = Span());
693  static constexpr bool _type_container_is_exact = true;
695 };
696 
700 class LetNode : public ExprNode {
701  public:
708  static void RegisterReflection() {
709  namespace refl = tvm::ffi::reflection;
710  refl::ObjectDef<LetNode>()
711  // TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release
712  .def_ro("var", &LetNode::var, refl::AttachFieldFlag::SEqHashDefRecursive())
713  .def_ro("value", &LetNode::value)
714  .def_ro("body", &LetNode::body);
715  }
717 };
718 
723 class Let : public PrimExpr {
724  public:
725  TVM_DLL Let(Var var, PrimExpr value, PrimExpr body, Span span = Span());
727  static constexpr bool _type_container_is_exact = true;
729 };
730 
736 class ShuffleNode : public ExprNode {
737  public:
739  ffi::Array<PrimExpr> vectors;
741  ffi::Array<PrimExpr> indices;
742  static void RegisterReflection() {
743  namespace refl = tvm::ffi::reflection;
744  refl::ObjectDef<ShuffleNode>()
745  .def_ro("vectors", &ShuffleNode::vectors)
746  .def_ro("indices", &ShuffleNode::indices);
747  }
749 };
750 
755 class Shuffle : public PrimExpr {
756  public:
757  TVM_DLL Shuffle(ffi::Array<PrimExpr> vectors, ffi::Array<PrimExpr> indices, Span span = Span());
758  TVM_DLL static PrimExpr Concat(ffi::Array<PrimExpr> vectors, Span span = Span());
759  TVM_DLL static PrimExpr ExtractElement(PrimExpr vector, int index, Span span = Span());
760 
762  static constexpr bool _type_container_is_exact = true;
764 };
765 
766 // Reduce operator
771 class CommReducerNode : public ffi::Object {
772  public:
774  ffi::Array<PrimVar> lhs;
776  ffi::Array<PrimVar> rhs;
778  ffi::Array<PrimExpr> result;
784  ffi::Array<PrimExpr> identity_element;
786  ffi::Array<PrimExpr> operator()(ffi::Array<PrimExpr> a, ffi::Array<PrimExpr> b) const;
791  mutable Span span;
792 
793  static void RegisterReflection() {
794  namespace refl = tvm::ffi::reflection;
795  refl::ObjectDef<CommReducerNode>()
796  .def_ro("lhs", &CommReducerNode::lhs, refl::AttachFieldFlag::SEqHashDefRecursive())
797  .def_ro("rhs", &CommReducerNode::rhs, refl::AttachFieldFlag::SEqHashDefRecursive())
798  .def_ro("result", &CommReducerNode::result)
799  .def_ro("identity_element", &CommReducerNode::identity_element)
800  .def_ro("span", &CommReducerNode::span, refl::AttachFieldFlag::SEqHashIgnore());
801  }
802 
803  static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
804  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.CommReducer", CommReducerNode, ffi::Object);
805 };
806 
811 class CommReducer : public ffi::ObjectRef {
812  public:
813  TVM_DLL CommReducer(ffi::Array<PrimVar> lhs, ffi::Array<PrimVar> rhs, ffi::Array<PrimExpr> result,
814  ffi::Array<PrimExpr> identity_element, Span span = Span());
815 
817 };
818 
820 class ReduceNode : public ExprNode {
821  public:
825  ffi::Array<PrimExpr> source;
827  ffi::Array<PrimExpr> init;
829  ffi::Array<IterVar> axis;
837  static void RegisterReflection() {
838  namespace refl = tvm::ffi::reflection;
839  refl::ObjectDef<ReduceNode>()
840  .def_ro("combiner", &ReduceNode::combiner)
841  .def_ro("source", &ReduceNode::source)
842  .def_ro("init", &ReduceNode::init)
843  .def_ro("axis", &ReduceNode::axis)
844  .def_ro("condition", &ReduceNode::condition)
845  .def_ro("value_index", &ReduceNode::value_index);
846  }
848 };
849 
854 class Reduce : public PrimExpr {
855  public:
856  TVM_DLL Reduce(CommReducer combiner, ffi::Array<PrimExpr> src, ffi::Array<IterVar> rdom,
857  PrimExpr condition, int value_index, ffi::Array<PrimExpr> init,
858  Span span = Span());
859 
861  static constexpr bool _type_container_is_exact = true;
863 };
864 
865 /*
866  * \brief Template function to convert Map to unordered_map
867  * Sometimes useful for API gluing when internal uses unordered_map
868  * \param dmap The container map
869  * \return The corresponding unordered_map.
870  * \tparam K the key of the Map.
871  * \tparam V the value of the Map.
872  */
873 template <typename K, typename V>
874 inline std::unordered_map<K, V> as_unordered_map(const ffi::Map<K, V>& dmap) {
875  std::unordered_map<K, V> ret;
876  for (auto kv : dmap) {
877  ret[kv.first] = kv.second;
878  }
879  return ret;
880 }
881 } // namespace tirx
882 
883 namespace ffi {
884 
885 template <>
886 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::StringImmNode> = true;
887 template <>
888 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::CastNode> = true;
889 template <>
890 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::AddNode> = true;
891 template <>
892 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::SubNode> = true;
893 template <>
894 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::MulNode> = true;
895 template <>
896 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::DivNode> = true;
897 template <>
898 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::ModNode> = true;
899 template <>
900 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::FloorDivNode> = true;
901 template <>
902 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::FloorModNode> = true;
903 template <>
904 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::MinNode> = true;
905 template <>
906 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::MaxNode> = true;
907 template <>
908 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::EQNode> = true;
909 template <>
910 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::NENode> = true;
911 template <>
912 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::LTNode> = true;
913 template <>
914 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::LENode> = true;
915 template <>
916 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::GTNode> = true;
917 template <>
918 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::GENode> = true;
919 template <>
920 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::AndNode> = true;
921 template <>
922 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::OrNode> = true;
923 template <>
924 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::NotNode> = true;
925 template <>
926 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::SelectNode> = true;
927 template <>
928 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::BufferLoadNode> = true;
929 template <>
930 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::ProducerLoadNode> = true;
931 template <>
932 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::RampNode> = true;
933 template <>
934 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::BroadcastNode> = true;
935 template <>
936 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::LetNode> = true;
937 template <>
938 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::ShuffleNode> = true;
939 template <>
940 inline constexpr bool object_ref_contains_v<PrimExpr, tirx::ReduceNode> = true;
941 
942 template <>
943 inline constexpr bool use_default_type_traits_v<tvm::tirx::StringImm> = false;
944 
945 template <>
946 struct TypeTraits<tvm::tirx::StringImm>
947  : public ObjectRefWithFallbackTraitsBase<tvm::tirx::StringImm, ffi::String> {
948  TVM_FFI_INLINE static tvm::tirx::StringImm ConvertFallbackValue(ffi::String value) {
949  return tvm::tirx::StringImm(value);
950  }
951 };
952 } // namespace ffi
953 } // namespace tvm
954 
955 namespace std {
956 template <>
957 struct hash<::tvm::tirx::IterVar> : public ::tvm::ffi::ObjectPtrHash {};
958 } // namespace std
959 #endif // TVM_TIR_EXPR_H_
Helpers for attribute objects.
Symbolic n-dimensional array, to represent a memory buffer.
Base type of all the expressions.
Definition: base_expr.h:276
Constant floating point literals in the program.
Definition: expr.h:424
Constant integer literals in the program.
Definition: expr.h:361
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition: base_expr.h:354
Definition: base_expr.h:113
Definition: source_map.h:111
a + b
Definition: expr.h:125
static constexpr const char * _type_key
Definition: expr.h:127
Managed reference to AddNode.
Definition: expr.h:134
static constexpr bool _type_container_is_exact
Definition: expr.h:138
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Add, PrimExpr, AddNode)
Add(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(AddNode)
a && b
Definition: expr.h:422
PrimExpr a
The left operand.
Definition: expr.h:425
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.And", AndNode, ExprNode)
PrimExpr b
The right operand.
Definition: expr.h:427
static void RegisterReflection()
Definition: expr.h:428
Managed reference to AndNode.
Definition: expr.h:439
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(And, PrimExpr, AndNode)
static constexpr bool _type_container_is_exact
Definition: expr.h:443
And(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(AndNode)
Base template to implement binary ops.
Definition: expr.h:109
static constexpr const int _type_child_slots
Definition: expr.h:119
PrimExpr b
The right operand.
Definition: expr.h:114
static constexpr const bool _type_final
Definition: expr.h:120
TVM_FFI_DECLARE_OBJECT_INFO_PREDEFINED_TYPE_KEY(T, ExprNode)
static void RegisterReflection()
Definition: expr.h:115
PrimExpr a
The left operand.
Definition: expr.h:112
Create a vector where all the elements are value.
Definition: expr.h:670
PrimExpr value
The base value.
Definition: expr.h:673
static void RegisterReflection()
Definition: expr.h:676
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.Broadcast", BroadcastNode, ExprNode)
PrimExpr lanes
The number of lanes.
Definition: expr.h:675
Managed reference to BroadcastNode.
Definition: expr.h:689
TVM_DEFINE_OBJECT_REF_COW_METHOD(BroadcastNode)
Broadcast(PrimExpr value, PrimExpr lanes, Span span=Span())
static constexpr bool _type_container_is_exact
Definition: expr.h:693
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Broadcast, PrimExpr, BroadcastNode)
Load value from the high dimension buffer.
Definition: expr.h:545
Buffer buffer
The buffer variable.
Definition: expr.h:548
friend class VectorTypeRewriter
Definition: expr.h:575
ffi::Optional< PrimExpr > predicate
The predicate mask for loading values.
Definition: expr.h:552
friend class CustomDatatypesLowerer
Definition: expr.h:574
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.BufferLoad", BufferLoadNode, ExprNode)
friend class Vectorizer
Definition: expr.h:576
static void RegisterReflection()
Definition: expr.h:553
ffi::Array< PrimExpr > indices
The indices location to be loaded.
Definition: expr.h:550
Managed reference to BufferLoadNode.
Definition: expr.h:583
TVM_DEFINE_OBJECT_REF_COW_METHOD(BufferLoadNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(BufferLoad, PrimExpr, BufferLoadNode)
static constexpr bool _type_container_is_exact
Definition: expr.h:588
BufferLoad(Buffer buffer, ffi::Array< PrimExpr > indices, ffi::Optional< PrimExpr > predicate=std::nullopt, Span span=Span())
Buffer is a symbolic n-darray structure. It is a composition of primitive symbolic types,...
Definition: buffer.h:187
Cast value from one data type to another.
Definition: expr.h:81
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.Cast", CastNode, ExprNode)
PrimExpr value
Original data type.
Definition: expr.h:84
static void RegisterReflection()
Definition: expr.h:85
Managed reference to CastNode.
Definition: expr.h:96
Cast(PrimType value_ty, PrimExpr value, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(CastNode)
static constexpr bool _type_container_is_exact
Definition: expr.h:100
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Cast, PrimExpr, CastNode)
Base template to implement comparison ops.
Definition: expr.h:298
static constexpr const bool _type_final
Definition: expr.h:309
PrimExpr a
The left operand.
Definition: expr.h:301
static constexpr const int _type_child_slots
Definition: expr.h:308
static void RegisterReflection()
Definition: expr.h:304
PrimExpr b
The right operand.
Definition: expr.h:303
TVM_FFI_DECLARE_OBJECT_INFO_PREDEFINED_TYPE_KEY(T, ExprNode)
A commutative reducer node to represent a commutative binary operator with identity element.
Definition: expr.h:771
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: expr.h:803
ffi::Array< PrimVar > rhs
The right argument of reducer.
Definition: expr.h:776
Span span
Span that points to the original source code. Reserved debug information.
Definition: expr.h:791
ffi::Array< PrimExpr > identity_element
The identity element of reducer, which leaves other elements unchanged when combined with it,...
Definition: expr.h:784
static void RegisterReflection()
Definition: expr.h:793
ffi::Array< PrimExpr > operator()(ffi::Array< PrimExpr > a, ffi::Array< PrimExpr > b) const
Function call operator to combine a and b.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.CommReducer", CommReducerNode, ffi::Object)
ffi::Array< PrimVar > lhs
The left argument of reducer.
Definition: expr.h:774
ffi::Array< PrimExpr > result
The result of reducer.
Definition: expr.h:778
Managed reference to CommReducerNode.
Definition: expr.h:811
CommReducer(ffi::Array< PrimVar > lhs, ffi::Array< PrimVar > rhs, ffi::Array< PrimExpr > result, ffi::Array< PrimExpr > identity_element, Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(CommReducer, ffi::ObjectRef, CommReducerNode)
Managed reference to DataProducerNode.
Definition: buffer.h:350
a / b in the C semnatics.
Definition: expr.h:183
static constexpr const char * _type_key
Definition: expr.h:185
Managed reference to DivNode.
Definition: expr.h:192
TVM_DEFINE_OBJECT_REF_COW_METHOD(DivNode)
Div(PrimExpr a, PrimExpr b, Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Div, PrimExpr, DivNode)
static constexpr bool _type_container_is_exact
Definition: expr.h:196
a == b
Definition: expr.h:314
static constexpr const char * _type_key
Definition: expr.h:316
Managed reference to EQNode.
Definition: expr.h:323
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(EQ, PrimExpr, EQNode)
static constexpr bool _type_container_is_exact
Definition: expr.h:327
TVM_DEFINE_OBJECT_REF_COW_METHOD(EQNode)
EQ(PrimExpr a, PrimExpr b, Span span=Span())
Floor division, floor(a/b)
Definition: expr.h:222
static constexpr const char * _type_key
Definition: expr.h:224
Managed reference to FloorDivNode.
Definition: expr.h:231
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(FloorDiv, PrimExpr, FloorDivNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(FloorDivNode)
static constexpr bool _type_container_is_exact
Definition: expr.h:235
FloorDiv(PrimExpr a, PrimExpr b, Span span=Span())
The remainder of the floordiv.
Definition: expr.h:240
static constexpr const char * _type_key
Definition: expr.h:242
Managed reference to FloorModNode.
Definition: expr.h:249
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(FloorMod, PrimExpr, FloorModNode)
static constexpr bool _type_container_is_exact
Definition: expr.h:253
FloorMod(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(FloorModNode)
a >= b
Definition: expr.h:404
static constexpr const char * _type_key
Definition: expr.h:406
Managed reference to GENode.
Definition: expr.h:413
GE(PrimExpr a, PrimExpr b, Span span=Span())
static constexpr bool _type_container_is_exact
Definition: expr.h:417
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(GE, PrimExpr, GENode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(GENode)
a > b
Definition: expr.h:386
static constexpr const char * _type_key
Definition: expr.h:388
Managed reference to GTNode.
Definition: expr.h:395
TVM_DEFINE_OBJECT_REF_COW_METHOD(GTNode)
static constexpr bool _type_container_is_exact
Definition: expr.h:399
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(GT, PrimExpr, GTNode)
GT(PrimExpr a, PrimExpr b, Span span=Span())
Iteration Variable, represents an iteration over an integer interval.
Definition: var.h:274
Managed reference to LENode.
Definition: expr.h:377
TVM_DEFINE_OBJECT_REF_COW_METHOD(LENode)
static constexpr bool _type_container_is_exact
Definition: expr.h:381
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(LE, PrimExpr, LENode)
LE(PrimExpr a, PrimExpr b, Span span=Span())
a < b
Definition: expr.h:350
static constexpr const char * _type_key
Definition: expr.h:352
Managed reference to LTNode.
Definition: expr.h:359
TVM_DEFINE_OBJECT_REF_COW_METHOD(LTNode)
static constexpr bool _type_container_is_exact
Definition: expr.h:363
LT(PrimExpr a, PrimExpr b, Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(LT, PrimExpr, LTNode)
Let binding. Bind var to value then evaluate body.
Definition: expr.h:700
PrimExpr body
The result expression.
Definition: expr.h:707
PrimExpr value
The value to be binded.
Definition: expr.h:705
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.Let", LetNode, ExprNode)
static void RegisterReflection()
Definition: expr.h:708
Var var
The variable.
Definition: expr.h:703
Managed reference to LetNode.
Definition: expr.h:723
static constexpr bool _type_container_is_exact
Definition: expr.h:727
TVM_DEFINE_OBJECT_REF_COW_METHOD(LetNode)
Let(Var var, PrimExpr value, PrimExpr body, Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Let, PrimExpr, LetNode)
max(a, b)
Definition: expr.h:276
static constexpr const char * _type_key
Definition: expr.h:278
Managed reference to MaxNode.
Definition: expr.h:285
TVM_DEFINE_OBJECT_REF_COW_METHOD(MaxNode)
Max(PrimExpr a, PrimExpr b, Span span=Span())
static constexpr bool _type_container_is_exact
Definition: expr.h:289
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Max, PrimExpr, MaxNode)
min(a, b)
Definition: expr.h:258
static constexpr const char * _type_key
Definition: expr.h:260
Managed reference to MinNode.
Definition: expr.h:267
TVM_DEFINE_OBJECT_REF_COW_METHOD(MinNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Min, PrimExpr, MinNode)
Min(PrimExpr a, PrimExpr b, Span span=Span())
static constexpr bool _type_container_is_exact
Definition: expr.h:271
a % b in the C semnatics.
Definition: expr.h:204
static constexpr const char * _type_key
Definition: expr.h:206
Managed reference to ModNode.
Definition: expr.h:213
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Mod, PrimExpr, ModNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(ModNode)
Mod(PrimExpr a, PrimExpr b, Span span=Span())
static constexpr bool _type_container_is_exact
Definition: expr.h:217
a * b
Definition: expr.h:162
static constexpr const char * _type_key
Definition: expr.h:164
Managed reference to MulNode.
Definition: expr.h:171
Mul(PrimExpr a, PrimExpr b, Span span=Span())
static constexpr bool _type_container_is_exact
Definition: expr.h:175
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Mul, PrimExpr, MulNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(MulNode)
a != b
Definition: expr.h:332
static constexpr const char * _type_key
Definition: expr.h:334
Managed reference to NENode.
Definition: expr.h:341
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(NE, PrimExpr, NENode)
static constexpr bool _type_container_is_exact
Definition: expr.h:345
NE(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(NENode)
!a
Definition: expr.h:474
static void RegisterReflection()
Definition: expr.h:478
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.Not", NotNode, ExprNode)
PrimExpr a
The input operand.
Definition: expr.h:477
Managed reference to NotNode.
Definition: expr.h:489
static constexpr bool _type_container_is_exact
Definition: expr.h:493
Not(PrimExpr a, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(NotNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Not, PrimExpr, NotNode)
a || b
Definition: expr.h:448
PrimExpr b
The right operand.
Definition: expr.h:453
static void RegisterReflection()
Definition: expr.h:454
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.Or", OrNode, ExprNode)
PrimExpr a
The left operand.
Definition: expr.h:451
Managed reference to OrNode.
Definition: expr.h:465
Or(PrimExpr a, PrimExpr b, Span span=Span())
static constexpr bool _type_container_is_exact
Definition: expr.h:469
TVM_DEFINE_OBJECT_REF_COW_METHOD(OrNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Or, PrimExpr, OrNode)
Load value from the result produced by the producer.
Definition: expr.h:601
ffi::Array< PrimExpr > indices
The location arguments.
Definition: expr.h:606
DataProducer producer
The buffer producer.
Definition: expr.h:604
static void RegisterReflection()
Definition: expr.h:607
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.ProducerLoad", ProducerLoadNode, ExprNode)
Managed reference to ProducerLoadNode.
Definition: expr.h:620
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(ProducerLoad, PrimExpr, ProducerLoadNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(ProducerLoadNode)
ProducerLoad(DataProducer producer, ffi::Array< PrimExpr > indices, Span span=Span())
static constexpr bool _type_container_is_exact
Definition: expr.h:626
Construct a vector with lanes elements where its i-th element equals base + i * stride....
Definition: expr.h:639
PrimExpr lanes
Total number of lanes.
Definition: expr.h:646
PrimExpr base
The base value.
Definition: expr.h:642
static void RegisterReflection()
Definition: expr.h:647
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.Ramp", RampNode, ExprNode)
PrimExpr stride
The stride of each step.
Definition: expr.h:644
Managed reference to RampNode.
Definition: expr.h:661
TVM_DEFINE_OBJECT_REF_COW_METHOD(RampNode)
Ramp(PrimExpr base, PrimExpr stride, PrimExpr lanes, Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Ramp, PrimExpr, RampNode)
static constexpr bool _type_container_is_exact
Definition: expr.h:665
Reduction operator.
Definition: expr.h:820
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.Reduce", ReduceNode, ExprNode)
ffi::Array< PrimExpr > source
The source operand.
Definition: expr.h:825
ffi::Array< IterVar > axis
The reduction axis.
Definition: expr.h:829
CommReducer combiner
The commutative combiner.
Definition: expr.h:823
static void RegisterReflection()
Definition: expr.h:837
PrimExpr condition
Predicate on the reduction Only add the body to reduction if condition is true.
Definition: expr.h:834
int value_index
the index of this reduce node
Definition: expr.h:836
ffi::Array< PrimExpr > init
The init operand.
Definition: expr.h:827
Managed reference to ReduceNode.
Definition: expr.h:854
static constexpr bool _type_container_is_exact
Definition: expr.h:861
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Reduce, PrimExpr, ReduceNode)
Reduce(CommReducer combiner, ffi::Array< PrimExpr > src, ffi::Array< IterVar > rdom, PrimExpr condition, int value_index, ffi::Array< PrimExpr > init, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(ReduceNode)
return true_value if condition is true, otherwise return false_value.
Definition: expr.h:504
static void RegisterReflection()
Definition: expr.h:512
PrimExpr false_value
value to be returned when condition is false.
Definition: expr.h:511
PrimExpr true_value
value to be returned when condition is true.
Definition: expr.h:509
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.Select", SelectNode, ExprNode)
PrimExpr condition
The condition.
Definition: expr.h:507
Managed reference to SelectNode.
Definition: expr.h:526
static constexpr bool _type_container_is_exact
Definition: expr.h:531
Select(PrimExpr condition, PrimExpr true_value, PrimExpr false_value, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(SelectNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Select, PrimExpr, SelectNode)
Shuffle instruction. vec = concat(vectors) result = (vec[indices[0]], vec[indices[1]] ....
Definition: expr.h:736
ffi::Array< PrimExpr > indices
The indices of each element.
Definition: expr.h:741
ffi::Array< PrimExpr > vectors
the input vectors.
Definition: expr.h:739
static void RegisterReflection()
Definition: expr.h:742
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.Shuffle", ShuffleNode, ExprNode)
Managed reference to ShuffleNode.
Definition: expr.h:755
static PrimExpr ExtractElement(PrimExpr vector, int index, Span span=Span())
static constexpr bool _type_container_is_exact
Definition: expr.h:762
static PrimExpr Concat(ffi::Array< PrimExpr > vectors, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(ShuffleNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Shuffle, PrimExpr, ShuffleNode)
Shuffle(ffi::Array< PrimExpr > vectors, ffi::Array< PrimExpr > indices, Span span=Span())
ffi::String constants, only used in asserts.
Definition: expr.h:54
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.StringImm", StringImmNode, ExprNode)
ffi::String value
The constant value content.
Definition: expr.h:57
static void RegisterReflection()
Definition: expr.h:58
Managed reference to StringImmNode.
Definition: expr.h:69
static constexpr bool _type_container_is_exact
Definition: expr.h:73
TVM_DEFINE_OBJECT_REF_COW_METHOD(StringImmNode)
StringImm(ffi::String value, Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(StringImm, PrimExpr, StringImmNode)
a - b
Definition: expr.h:143
static constexpr const char * _type_key
Definition: expr.h:145
Managed reference to SubNode.
Definition: expr.h:152
static constexpr bool _type_container_is_exact
Definition: expr.h:157
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Sub, PrimExpr, SubNode)
Sub(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(SubNode)
a named variable in TIR
Definition: var.h:68
Copy-on-write helper macro for IR ffi::ObjectRef types.
Base expr nodes in TVM.
PrimVar var(std::string name_hint, PrimType t=PrimType::Int(32))
Construct a new Var expression.
tvm::FloatImmNode FloatImmNode
Definition: expr.h:51
tvm::IntImmNode IntImmNode
Definition: expr.h:50
std::unordered_map< K, V > as_unordered_map(const ffi::Map< K, V > &dmap)
Definition: expr.h:874
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:40
PrimExpr ret(PrimExpr value, Span span=Span())
Return the value.
Defines the Functor data structures.
static TVM_FFI_INLINE tvm::tirx::StringImm ConvertFallbackValue(ffi::String value)
Definition: expr.h:948
a <= b
Definition: expr.h:368
static constexpr const char * _type_key
Definition: expr.h:370
Variables in the TIR.