tvm
Loading...
Searching...
No Matches
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
24#ifndef TVM_IR_TYPE_H_
25#define TVM_IR_TYPE_H_
26
27#include <tvm/ffi/container/array.h>
28#include <tvm/ffi/dtype.h>
29#include <tvm/ffi/reflection/registry.h>
30#include <tvm/ir/base_expr.h>
31#include <tvm/ir/location.h>
32
33#include <string>
34
35namespace tvm {
36
43class AnyTypeNode : public TypeNode {
44 public:
45 static void RegisterReflection() { ffi::reflection::ObjectDef<AnyTypeNode>(); }
47};
48
59
62 public:
63 static void RegisterReflection() {
64 namespace refl = tvm::ffi::reflection;
65 refl::ObjectDef<TensorRegionTypeNode>();
66 }
67
69};
70
78
80class StringTypeNode : public TypeNode {
81 public:
82 static void RegisterReflection() { ffi::reflection::ObjectDef<StringTypeNode>(); }
84};
85
92
103class PtrTypeNode : public TypeNode {
104 public:
112 ffi::String storage_scope;
113
114 static void RegisterReflection() {
115 namespace refl = tvm::ffi::reflection;
116 refl::ObjectDef<PtrTypeNode>()
117 .def_ro("element_type", &PtrTypeNode::element_type)
118 .def_ro("storage_scope", &PtrTypeNode::storage_scope);
119 }
121};
122
123/*
124 * \brief Managed reference to PtrTypeNode.
125 * \sa PtrTypeNode
126 */
127class PtrType : public Type {
128 public:
134 TVM_TIRX_DLL explicit PtrType(Type element_type, ffi::String storage_scope = "");
135
137 TVM_TIRX_DLL static PtrType VoidPtrType(ffi::String storage_scope = "");
138
140};
141
146class TupleTypeNode : public TypeNode {
147 public:
149 ffi::Array<Type> fields;
150
152
153 static void RegisterReflection() {
154 namespace refl = tvm::ffi::reflection;
155 refl::ObjectDef<TupleTypeNode>().def_ro("fields", &TupleTypeNode::fields);
156 }
158};
159
164class TupleType : public Type {
165 public:
171 TVM_TIRX_DLL explicit TupleType(ffi::Array<Type> fields, Location loc = UnknownLoc());
172
178
180};
181
185inline Type VoidType() { return TupleType::Empty(); }
186
191inline bool IsVoidType(const Type& type) {
192 auto* n = type.as<TupleTypeNode>();
193 return n && n->fields.size() == 0;
194}
195
204class FuncTypeNode : public TypeNode {
205 public:
207 ffi::Array<Type> arg_types;
210
211 static void RegisterReflection() {
212 namespace refl = tvm::ffi::reflection;
213 refl::ObjectDef<FuncTypeNode>()
214 .def_ro("arg_types", &FuncTypeNode::arg_types)
215 .def_ro("ret_type", &FuncTypeNode::ret_type);
216 }
218};
219
224class FuncType : public Type {
225 public:
233 TVM_TIRX_DLL FuncType(ffi::Array<Type> arg_types, Type ret_type, Location loc = UnknownLoc());
234
236};
237
238} // namespace tvm
239#endif // TVM_IR_TYPE_H_
Base expression and primitive type nodes.
The top type, which admits any value.
Definition type.h:43
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.AnyType", AnyTypeNode, TypeNode)
static void RegisterReflection()
Definition type.h:45
Managed reference to AnyTypeNode.
Definition type.h:53
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(AnyType, Type, AnyTypeNode)
TVM_TIRX_DLL AnyType(Location loc=UnknownLoc())
Function type.
Definition type.h:204
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.FuncType", FuncTypeNode, TypeNode)
Type ret_type
The type of return value.
Definition type.h:209
ffi::Array< Type > arg_types
type type of arguments
Definition type.h:207
static void RegisterReflection()
Definition type.h:211
Managed reference to FuncTypeNode.
Definition type.h:224
TVM_TIRX_DLL FuncType(ffi::Array< Type > arg_types, Type ret_type, Location loc=UnknownLoc())
Constructor.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(FuncType, Type, FuncTypeNode)
Non-nullable source-location metadata.
Definition location.h:91
static TVM_TIRX_DLL PrimType Void()
Construct the void sentinel type, encoded as handle(0, 0).
Low-level raw pointer type.
Definition type.h:103
ffi::String storage_scope
The storage scope of the pointer.
Definition type.h:112
static void RegisterReflection()
Definition type.h:114
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.PtrType", PtrTypeNode, TypeNode)
Type element_type
The type of the element which the pointer points to.
Definition type.h:108
Definition type.h:127
TVM_TIRX_DLL PtrType(Type element_type, ffi::String storage_scope="")
Constructor.
static TVM_TIRX_DLL PtrType VoidPtrType(ffi::String storage_scope="")
Construct an opaque pointer with void element type.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(PtrType, Type, PtrTypeNode)
Semantic string type; its physical representation is context dependent.
Definition type.h:80
static void RegisterReflection()
Definition type.h:82
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.StringType", StringTypeNode, TypeNode)
Managed reference to StringTypeNode.
Definition type.h:87
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(StringType, Type, StringTypeNode)
TVM_TIRX_DLL StringType()
The type of a multi-dimensional tensor region expression.
Definition type.h:61
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.TensorRegionType", TensorRegionTypeNode, TypeNode)
static void RegisterReflection()
Definition type.h:63
Managed reference to TensorRegionTypeNode.
Definition type.h:72
TVM_TIRX_DLL TensorRegionType()
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TensorRegionType, Type, TensorRegionTypeNode)
The type of tuple values.
Definition type.h:146
TupleTypeNode()
Definition type.h:151
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.TupleType", TupleTypeNode, TypeNode)
static void RegisterReflection()
Definition type.h:153
ffi::Array< Type > fields
The type of each field in the tuple.
Definition type.h:149
Managed reference to TupleTypeNode.
Definition type.h:164
TVM_TIRX_DLL static TupleType Empty()
Create an empty tuple type that constains nothing.
TVM_TIRX_DLL TupleType(ffi::Array< Type > fields, Location loc=UnknownLoc())
Constructor.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TupleType, Type, TupleTypeNode)
Type is the base type of all types.
Definition base_expr.h:54
Managed reference to TypeNode.
Definition base_expr.h:80
Reference to the shared immutable unknown location.
Definition location.h:105
Source locations and source-text lookup.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
bool IsVoidType(const Type &type)
Check whether the tyep represents void.
Definition type.h:191
Type VoidType()
Definition type.h:185
#define TVM_TIRX_DLL
Definition base.h:83