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 attrs.cc
22 */
23#include <tvm/ir/attrs.h>
24#include <tvm/runtime/registry.h>
25
26#include "attr_functor.h"
27
28namespace tvm {
29
30void DictAttrsNode::VisitAttrs(AttrVisitor* v) { v->Visit("__dict__", &dict); }
31
32void DictAttrsNode::VisitNonDefaultAttrs(AttrVisitor* v) { v->Visit("__dict__", &dict); }
33
34void DictAttrsNode::InitByPackedArgs(const runtime::TVMArgs& args, bool allow_unknown) {
35 for (int i = 0; i < args.size(); i += 2) {
36 std::string key = args[i];
37 runtime::TVMArgValue val = args[i + 1];
38 if (val.IsObjectRef<ObjectRef>()) {
39 dict.Set(key, val.operator ObjectRef());
40 } else if (String::CanConvertFrom(val)) {
41 dict.Set(key, val.operator String());
42 } else {
43 dict.Set(key, val.operator PrimExpr());
44 }
45 }
46}
47
48Array<AttrFieldInfo> DictAttrsNode::ListFieldInfo() const { return {}; }
49
50DictAttrs::DictAttrs(Map<String, ObjectRef> dict) {
51 ObjectPtr<DictAttrsNode> n = make_object<DictAttrsNode>();
52 n->dict = std::move(dict);
53 data_ = std::move(n);
54}
55
56TVM_REGISTER_NODE_TYPE(DictAttrsNode);
57
58TVM_REGISTER_NODE_TYPE(AttrFieldInfoNode);
59
60TVM_REGISTER_GLOBAL("ir.DictAttrsGetDict").set_body_typed([](DictAttrs attrs) {
61 return attrs->dict;
62});
63
64TVM_REGISTER_GLOBAL("ir.AttrsListFieldInfo").set_body_typed([](Attrs attrs) {
65 return attrs->ListFieldInfo();
66});
67
68} // namespace tvm
69