tvm
type.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 
49 #ifndef TVM_IR_TYPE_H_
50 #define TVM_IR_TYPE_H_
51 
52 #include <tvm/ffi/container/array.h>
53 #include <tvm/ffi/reflection/registry.h>
54 #include <tvm/ir/source_map.h>
55 #include <tvm/runtime/data_type.h>
56 #include <tvm/runtime/object.h>
57 
58 #include <string>
59 
60 namespace tvm {
61 
74 class TypeNode : public Object {
75  public:
80  mutable Span span;
81 
82  static void RegisterReflection() {
83  namespace refl = tvm::ffi::reflection;
84  // span do not participate in structural equal and hash.
85  refl::ObjectDef<TypeNode>().def_ro("span", &TypeNode::span, refl::DefaultValue(Span()),
86  refl::AttachFieldFlag::SEqHashIgnore());
87  }
88 
89  static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
90 
91  static constexpr const uint32_t _type_child_slots = 14;
93 };
94 
99 class Type : public ObjectRef {
100  public:
102 };
103 
112 class PrimTypeNode : public TypeNode {
113  public:
118 
119  static void RegisterReflection() {
120  namespace refl = tvm::ffi::reflection;
121  refl::ObjectDef<PrimTypeNode>().def_ro("dtype", &PrimTypeNode::dtype);
122  }
124 };
125 
126 /*
127  * \brief Managed reference to PrimTypeNode.
128  * \sa PrimTypeNode
129  */
130 class PrimType : public Type {
131  public:
137  TVM_DLL explicit PrimType(runtime::DataType dtype, Span span = Span());
138 
140 };
141 
152 class PointerTypeNode : public TypeNode {
153  public:
161  ffi::String storage_scope;
162 
163  static void RegisterReflection() {
164  namespace refl = tvm::ffi::reflection;
165  refl::ObjectDef<PointerTypeNode>()
166  .def_ro("element_type", &PointerTypeNode::element_type)
167  .def_ro("storage_scope", &PointerTypeNode::storage_scope);
168  }
170 };
171 
172 /*
173  * \brief Managed reference to PointerTypeNode.
174  * \sa PointerTypeNode
175  */
176 class PointerType : public Type {
177  public:
183  TVM_DLL explicit PointerType(Type element_type, ffi::String storage_scope = "");
184 
186 };
187 
192 class TupleTypeNode : public TypeNode {
193  public:
195  ffi::Array<Type> fields;
196 
198 
199  static void RegisterReflection() {
200  namespace refl = tvm::ffi::reflection;
201  refl::ObjectDef<TupleTypeNode>()
202  .def_ro("fields", &TupleTypeNode::fields)
203  .def_ro("span", &TupleTypeNode::span);
204  }
206 };
207 
212 class TupleType : public Type {
213  public:
219  TVM_DLL explicit TupleType(ffi::Array<Type> fields, Span span = Span());
220 
225  TVM_DLL TupleType static Empty();
226 
228 };
229 
233 inline Type VoidType() { return TupleType::Empty(); }
234 
239 inline bool IsVoidType(const Type& type) {
240  auto* n = type.as<TupleTypeNode>();
241  return n && n->fields.size() == 0;
242 }
243 
252 class FuncTypeNode : public TypeNode {
253  public:
255  ffi::Array<Type> arg_types;
258 
259  static void RegisterReflection() {
260  namespace refl = tvm::ffi::reflection;
261  refl::ObjectDef<FuncTypeNode>()
262  .def_ro("arg_types", &FuncTypeNode::arg_types)
263  .def_ro("ret_type", &FuncTypeNode::ret_type)
264  .def_ro("span", &FuncTypeNode::span);
265  }
267 };
268 
273 class FuncType : public Type {
274  public:
282  TVM_DLL FuncType(ffi::Array<Type> arg_types, Type ret_type, Span span = Span());
283 
285 };
286 
291 class TensorMapTypeNode : public TypeNode {
292  public:
293  static void RegisterReflection() {
294  namespace refl = tvm::ffi::reflection;
295  refl::ObjectDef<TensorMapTypeNode>().def_ro("span", &TensorMapTypeNode::span);
296  }
298 };
299 
304 class TensorMapType : public Type {
305  public:
306  TVM_DLL TensorMapType(Span span = Span());
307 
310 };
311 
312 } // namespace tvm
313 #endif // TVM_IR_TYPE_H_
Function type.
Definition: type.h:252
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.FuncType", FuncTypeNode, TypeNode)
Type ret_type
The type of return value.
Definition: type.h:257
ffi::Array< Type > arg_types
type type of arguments
Definition: type.h:255
static void RegisterReflection()
Definition: type.h:259
Managed reference to FuncTypeNode.
Definition: type.h:273
FuncType(ffi::Array< Type > arg_types, Type ret_type, Span span=Span())
Constructor.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(FuncType, Type, FuncTypeNode)
Low-level raw pointer type.
Definition: type.h:152
Type element_type
The type of the element which the pointer points to.
Definition: type.h:157
ffi::String storage_scope
The storage scope of the pointer.
Definition: type.h:161
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.PointerType", PointerTypeNode, TypeNode)
static void RegisterReflection()
Definition: type.h:163
Definition: type.h:176
PointerType(Type element_type, ffi::String storage_scope="")
Constructor.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(PointerType, Type, PointerTypeNode)
Primitive data types used in the low-level IR.
Definition: type.h:112
runtime::DataType dtype
The corresponding dtype field.
Definition: type.h:117
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.PrimType", PrimTypeNode, TypeNode)
static void RegisterReflection()
Definition: type.h:119
Definition: type.h:130
PrimType(runtime::DataType dtype, Span span=Span())
Constructor.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(PrimType, Type, PrimTypeNode)
Definition: source_map.h:111
The type of tensor map.
Definition: type.h:291
static void RegisterReflection()
Definition: type.h:293
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.TensorMapType", TensorMapTypeNode, TypeNode)
Managed reference to TensorMapTypeNode.
Definition: type.h:304
TensorMapType(Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE_WITHOUT_DEFAULT_CONSTRUCTOR(TensorMapType, Type, TensorMapTypeNode)
The type of tuple values.
Definition: type.h:192
TupleTypeNode()
Definition: type.h:197
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.TupleType", TupleTypeNode, TypeNode)
static void RegisterReflection()
Definition: type.h:199
ffi::Array< Type > fields
The type of each field in the tuple.
Definition: type.h:195
Managed reference to TupleTypeNode.
Definition: type.h:212
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(TupleType, Type, TupleTypeNode)
TupleType(ffi::Array< Type > fields, Span span=Span())
Constructor.
static TupleType Empty()
Create an empty tuple type that constains nothing.
Type is the base type of all types.
Definition: type.h:74
TVM_FFI_DECLARE_OBJECT_INFO("ir.Type", TypeNode, Object)
static constexpr const uint32_t _type_child_slots
Definition: type.h:91
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: type.h:89
static void RegisterReflection()
Definition: type.h:82
Span span
Span that points to the original source code. Reserved debug information.
Definition: type.h:80
Managed reference to TypeNode.
Definition: type.h:99
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Type, ObjectRef, TypeNode)
Runtime primitive data type.
Definition: data_type.h:47
Definition: repr_printer.h:91
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:37
bool IsVoidType(const Type &type)
Check whether the tyep represents void.
Definition: type.h:239
Type VoidType()
Definition: type.h:233
A managed object in the TVM runtime.
A map from source names to source code.