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 | |
20 | /*! |
21 | * \file src/ir/adt.cc |
22 | * \brief ADT type definitions. |
23 | */ |
24 | #include <tvm/ir/adt.h> |
25 | #include <tvm/ir/type.h> |
26 | #include <tvm/runtime/registry.h> |
27 | |
28 | namespace tvm { |
29 | |
30 | Constructor::Constructor(String name_hint, tvm::Array<Type> inputs, GlobalTypeVar belong_to) { |
31 | ObjectPtr<ConstructorNode> n = make_object<ConstructorNode>(); |
32 | n->name_hint = std::move(name_hint); |
33 | n->inputs = std::move(inputs); |
34 | n->belong_to = std::move(belong_to); |
35 | data_ = std::move(n); |
36 | } |
37 | |
38 | TVM_REGISTER_NODE_TYPE(ConstructorNode); |
39 | |
40 | TVM_REGISTER_GLOBAL("ir.Constructor" ) |
41 | .set_body_typed([](String name_hint, tvm::Array<Type> inputs, GlobalTypeVar belong_to) { |
42 | return Constructor(name_hint, inputs, belong_to); |
43 | }); |
44 | |
45 | TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable) |
46 | .set_dispatch<ConstructorNode>([](const ObjectRef& ref, ReprPrinter* p) { |
47 | auto* node = static_cast<const ConstructorNode*>(ref.get()); |
48 | p->stream << "ConstructorNode(" << node->name_hint << ", " << node->inputs << ", " |
49 | << node->belong_to << ")" ; |
50 | }); |
51 | |
52 | TypeData::TypeData(GlobalTypeVar , tvm::Array<TypeVar> type_vars, |
53 | tvm::Array<Constructor> constructors) { |
54 | ObjectPtr<TypeDataNode> n = make_object<TypeDataNode>(); |
55 | n->header = std::move(header); |
56 | n->type_vars = std::move(type_vars); |
57 | n->constructors = std::move(constructors); |
58 | data_ = std::move(n); |
59 | } |
60 | |
61 | TVM_REGISTER_NODE_TYPE(TypeDataNode); |
62 | |
63 | TVM_REGISTER_GLOBAL("ir.TypeData" ) |
64 | .set_body_typed([](GlobalTypeVar , tvm::Array<TypeVar> type_vars, |
65 | tvm::Array<Constructor> constructors) { |
66 | return TypeData(header, type_vars, constructors); |
67 | }); |
68 | |
69 | TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable) |
70 | .set_dispatch<TypeDataNode>([](const ObjectRef& ref, ReprPrinter* p) { |
71 | auto* node = static_cast<const TypeDataNode*>(ref.get()); |
72 | p->stream << "TypeDataNode(" << node->header << ", " << node->type_vars << ", " |
73 | << node->constructors << ")" ; |
74 | }); |
75 | |
76 | } // namespace tvm |
77 | |