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 
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/source_map.h>
32 
33 #include <string>
34 
35 namespace tvm {
36 
47 class PointerTypeNode : public TypeNode {
48  public:
56  ffi::String storage_scope;
57 
58  static void RegisterReflection() {
59  namespace refl = tvm::ffi::reflection;
60  refl::ObjectDef<PointerTypeNode>()
61  .def_ro("element_type", &PointerTypeNode::element_type)
62  .def_ro("storage_scope", &PointerTypeNode::storage_scope);
63  }
65 };
66 
67 /*
68  * \brief Managed reference to PointerTypeNode.
69  * \sa PointerTypeNode
70  */
71 class PointerType : public Type {
72  public:
78  TVM_DLL explicit PointerType(Type element_type, ffi::String storage_scope = "");
79 
81  TVM_DLL static PointerType VoidPointerTy(ffi::String storage_scope = "");
82 
84 };
85 
90 class TupleTypeNode : public TypeNode {
91  public:
93  ffi::Array<Type> fields;
94 
96 
97  static void RegisterReflection() {
98  namespace refl = tvm::ffi::reflection;
99  refl::ObjectDef<TupleTypeNode>().def_ro("fields", &TupleTypeNode::fields);
100  }
102 };
103 
108 class TupleType : public Type {
109  public:
115  TVM_DLL explicit TupleType(ffi::Array<Type> fields, Span span = Span());
116 
121  TVM_DLL TupleType static Empty();
122 
124 };
125 
129 inline Type VoidType() { return TupleType::Empty(); }
130 
135 inline bool IsVoidType(const Type& type) {
136  auto* n = type.as<TupleTypeNode>();
137  return n && n->fields.size() == 0;
138 }
139 
148 class FuncTypeNode : public TypeNode {
149  public:
151  ffi::Array<Type> arg_types;
154 
155  static void RegisterReflection() {
156  namespace refl = tvm::ffi::reflection;
157  refl::ObjectDef<FuncTypeNode>()
158  .def_ro("arg_types", &FuncTypeNode::arg_types)
159  .def_ro("ret_type", &FuncTypeNode::ret_type);
160  }
162 };
163 
168 class FuncType : public Type {
169  public:
177  TVM_DLL FuncType(ffi::Array<Type> arg_types, Type ret_type, Span span = Span());
178 
180 };
181 
186 class TensorMapTypeNode : public TypeNode {
187  public:
188  static void RegisterReflection() {
189  namespace refl = tvm::ffi::reflection;
190  refl::ObjectDef<TensorMapTypeNode>();
191  }
193 };
194 
199 class TensorMapType : public Type {
200  public:
201  TVM_DLL TensorMapType(Span span = Span());
202 
204 };
205 
206 } // namespace tvm
207 #endif // TVM_IR_TYPE_H_
Base expression and primitive type nodes.
Function type.
Definition: type.h:148
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.FuncType", FuncTypeNode, TypeNode)
Type ret_type
The type of return value.
Definition: type.h:153
ffi::Array< Type > arg_types
type type of arguments
Definition: type.h:151
static void RegisterReflection()
Definition: type.h:155
Managed reference to FuncTypeNode.
Definition: type.h:168
FuncType(ffi::Array< Type > arg_types, Type ret_type, Span span=Span())
Constructor.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(FuncType, Type, FuncTypeNode)
Low-level raw pointer type.
Definition: type.h:47
Type element_type
The type of the element which the pointer points to.
Definition: type.h:52
ffi::String storage_scope
The storage scope of the pointer.
Definition: type.h:56
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.PointerType", PointerTypeNode, TypeNode)
static void RegisterReflection()
Definition: type.h:58
Definition: type.h:71
PointerType(Type element_type, ffi::String storage_scope="")
Constructor.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(PointerType, Type, PointerTypeNode)
static PointerType VoidPointerTy(ffi::String storage_scope="")
Construct an opaque pointer with void element type.
static PrimType Void()
Construct the void sentinel type, encoded as handle(0, 0).
Definition: source_map.h:111
The type of tensor map.
Definition: type.h:186
static void RegisterReflection()
Definition: type.h:188
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.TensorMapType", TensorMapTypeNode, TypeNode)
Managed reference to TensorMapTypeNode.
Definition: type.h:199
TensorMapType(Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TensorMapType, Type, TensorMapTypeNode)
The type of tuple values.
Definition: type.h:90
TupleTypeNode()
Definition: type.h:95
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.TupleType", TupleTypeNode, TypeNode)
static void RegisterReflection()
Definition: type.h:97
ffi::Array< Type > fields
The type of each field in the tuple.
Definition: type.h:93
Managed reference to TupleTypeNode.
Definition: type.h:108
TupleType(ffi::Array< Type > fields, Span span=Span())
Constructor.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TupleType, Type, TupleTypeNode)
static TupleType Empty()
Create an empty tuple type that constains nothing.
Type is the base type of all types.
Definition: base_expr.h:52
Managed reference to TypeNode.
Definition: base_expr.h:77
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:40
bool IsVoidType(const Type &type)
Check whether the tyep represents void.
Definition: type.h:135
Type VoidType()
Definition: type.h:129
A map from source names to source code.