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/tvm/relay/dataflow_matcher.cc
22 * \brief The dataflow pattern matcher for Relay.
23 */
24
25#include <tvm/relay/dataflow_pattern_functor.h>
26
27namespace tvm {
28namespace relay {
29
30// DFPatternVisitor
31
32void DFPatternVisitor::VisitDFPattern(const DFPattern& pattern) {
33 if (this->visited_.count(pattern.get()) == 0) {
34 visited_.insert(pattern.get());
35 DFPatternFunctor::VisitDFPattern(pattern);
36 }
37}
38
39void DFPatternVisitor::VisitDFPattern_(const AltPatternNode* op) {
40 VisitDFPattern(op->left);
41 VisitDFPattern(op->right);
42}
43
44void DFPatternVisitor::VisitDFPattern_(const AttrPatternNode* op) { VisitDFPattern(op->pattern); }
45
46void DFPatternVisitor::VisitDFPattern_(const CallPatternNode* op) {
47 VisitDFPattern(op->op);
48 if (op->args.defined()) {
49 for (auto arg : op->args) {
50 VisitDFPattern(arg);
51 }
52 }
53}
54
55void DFPatternVisitor::VisitDFPattern_(const DataTypePatternNode* op) {
56 VisitDFPattern(op->pattern);
57}
58
59void DFPatternVisitor::VisitDFPattern_(const DominatorPatternNode* op) {
60 VisitDFPattern(op->parent);
61 VisitDFPattern(op->path);
62 VisitDFPattern(op->child);
63}
64
65void DFPatternVisitor::VisitDFPattern_(const ExprPatternNode* op) {}
66
67void DFPatternVisitor::VisitDFPattern_(const FunctionPatternNode* op) {
68 if (op->params.defined()) {
69 for (auto param : op->params) {
70 VisitDFPattern(param);
71 }
72 }
73 VisitDFPattern(op->body);
74}
75
76void DFPatternVisitor::VisitDFPattern_(const ShapePatternNode* op) { VisitDFPattern(op->pattern); }
77
78void DFPatternVisitor::VisitDFPattern_(const TupleGetItemPatternNode* op) {
79 VisitDFPattern(op->tuple);
80}
81
82void DFPatternVisitor::VisitDFPattern_(const TuplePatternNode* op) {
83 if (op->fields.defined()) {
84 for (auto field : op->fields) {
85 VisitDFPattern(field);
86 }
87 }
88}
89
90void DFPatternVisitor::VisitDFPattern_(const IfPatternNode* op) {
91 VisitDFPattern(op->cond);
92 VisitDFPattern(op->true_branch);
93 VisitDFPattern(op->false_branch);
94}
95
96void DFPatternVisitor::VisitDFPattern_(const LetPatternNode* op) {
97 VisitDFPattern(op->var);
98 VisitDFPattern(op->value);
99 VisitDFPattern(op->body);
100}
101
102void DFPatternVisitor::VisitDFPattern_(const TypePatternNode* op) { VisitDFPattern(op->pattern); }
103
104void DFPatternVisitor::VisitDFPattern_(const VarPatternNode* op) {}
105
106void DFPatternVisitor::VisitDFPattern_(const ConstantPatternNode* op) {}
107
108void DFPatternVisitor::VisitDFPattern_(const WildcardPatternNode* op) {}
109
110} // namespace relay
111} // namespace tvm
112