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 | |
27 | namespace tvm { |
28 | namespace relay { |
29 | |
30 | // DFPatternVisitor |
31 | |
32 | void 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 | |
39 | void DFPatternVisitor::VisitDFPattern_(const AltPatternNode* op) { |
40 | VisitDFPattern(op->left); |
41 | VisitDFPattern(op->right); |
42 | } |
43 | |
44 | void DFPatternVisitor::VisitDFPattern_(const AttrPatternNode* op) { VisitDFPattern(op->pattern); } |
45 | |
46 | void 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 | |
55 | void DFPatternVisitor::VisitDFPattern_(const DataTypePatternNode* op) { |
56 | VisitDFPattern(op->pattern); |
57 | } |
58 | |
59 | void DFPatternVisitor::VisitDFPattern_(const DominatorPatternNode* op) { |
60 | VisitDFPattern(op->parent); |
61 | VisitDFPattern(op->path); |
62 | VisitDFPattern(op->child); |
63 | } |
64 | |
65 | void DFPatternVisitor::VisitDFPattern_(const ExprPatternNode* op) {} |
66 | |
67 | void 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 | |
76 | void DFPatternVisitor::VisitDFPattern_(const ShapePatternNode* op) { VisitDFPattern(op->pattern); } |
77 | |
78 | void DFPatternVisitor::VisitDFPattern_(const TupleGetItemPatternNode* op) { |
79 | VisitDFPattern(op->tuple); |
80 | } |
81 | |
82 | void DFPatternVisitor::VisitDFPattern_(const TuplePatternNode* op) { |
83 | if (op->fields.defined()) { |
84 | for (auto field : op->fields) { |
85 | VisitDFPattern(field); |
86 | } |
87 | } |
88 | } |
89 | |
90 | void DFPatternVisitor::VisitDFPattern_(const IfPatternNode* op) { |
91 | VisitDFPattern(op->cond); |
92 | VisitDFPattern(op->true_branch); |
93 | VisitDFPattern(op->false_branch); |
94 | } |
95 | |
96 | void DFPatternVisitor::VisitDFPattern_(const LetPatternNode* op) { |
97 | VisitDFPattern(op->var); |
98 | VisitDFPattern(op->value); |
99 | VisitDFPattern(op->body); |
100 | } |
101 | |
102 | void DFPatternVisitor::VisitDFPattern_(const TypePatternNode* op) { VisitDFPattern(op->pattern); } |
103 | |
104 | void DFPatternVisitor::VisitDFPattern_(const VarPatternNode* op) {} |
105 | |
106 | void DFPatternVisitor::VisitDFPattern_(const ConstantPatternNode* op) {} |
107 | |
108 | void DFPatternVisitor::VisitDFPattern_(const WildcardPatternNode* op) {} |
109 | |
110 | } // namespace relay |
111 | } // namespace tvm |
112 |