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/type_relation.cc
22 * \brief Type relation
23 */
24#include <tvm/ir/type.h>
25#include <tvm/ir/type_relation.h>
26#include <tvm/runtime/registry.h>
27namespace tvm {
28
29TypeCall::TypeCall(Type func, tvm::Array<Type> args) {
30 ObjectPtr<TypeCallNode> n = make_object<TypeCallNode>();
31 n->func = std::move(func);
32 n->args = std::move(args);
33 data_ = std::move(n);
34}
35
36TVM_REGISTER_NODE_TYPE(TypeCallNode);
37
38TVM_REGISTER_GLOBAL("ir.TypeCall").set_body_typed([](Type func, Array<Type> type) {
39 return TypeCall(func, type);
40});
41
42TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable)
43 .set_dispatch<TypeCallNode>([](const ObjectRef& ref, ReprPrinter* p) {
44 auto* node = static_cast<const TypeCallNode*>(ref.get());
45 p->stream << "TypeCallNode(" << node->func << ", " << node->args << ")";
46 });
47
48TypeRelation::TypeRelation(TypeRelationFn func, Array<Type> args, int num_inputs, Attrs attrs) {
49 ObjectPtr<TypeRelationNode> n = make_object<TypeRelationNode>();
50 n->func = std::move(func);
51 n->args = std::move(args);
52 n->num_inputs = num_inputs;
53 n->attrs = std::move(attrs);
54 data_ = std::move(n);
55}
56
57TVM_REGISTER_NODE_TYPE(TypeRelationNode);
58
59TVM_REGISTER_GLOBAL("ir.TypeRelation")
60 .set_body_typed([](TypeRelationFn func, Array<Type> args, int num_inputs, Attrs attrs) {
61 return TypeRelation(func, args, num_inputs, attrs);
62 });
63
64TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable)
65 .set_dispatch<TypeRelationNode>([](const ObjectRef& ref, ReprPrinter* p) {
66 auto* node = static_cast<const TypeRelationNode*>(ref.get());
67 p->stream << "TypeRelationNode(" << node->func->name << ", " << node->args << ")";
68 });
69} // namespace tvm
70