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 span_check.h |
22 | * \brief Check that the Relay IR has correctly attached span information. |
23 | */ |
24 | |
25 | #ifndef TVM_PARSER_SPAN_CHECK_H_ |
26 | #define TVM_PARSER_SPAN_CHECK_H_ |
27 | |
28 | #include <tvm/ir/transform.h> |
29 | #include <tvm/ir/type_functor.h> |
30 | #include <tvm/relay/expr.h> |
31 | #include <tvm/relay/expr_functor.h> |
32 | #include <tvm/runtime/logging.h> |
33 | #include <tvm/runtime/object.h> |
34 | |
35 | #include <fstream> |
36 | #include <string> |
37 | #include <unordered_map> |
38 | #include <vector> |
39 | |
40 | namespace tvm { |
41 | namespace parser { |
42 | |
43 | using namespace tvm::relay; |
44 | using tvm::transform::Pass; |
45 | |
46 | struct SpanChecker : ExprVisitor { |
47 | Expr expression; |
48 | DiagnosticContext diag_ctx; |
49 | std::vector<Span> span_stack; |
50 | |
51 | explicit SpanChecker(DiagnosticContext diag_ctx) : diag_ctx(diag_ctx) {} |
52 | |
53 | void VisitExpr(const Expr& expr) override; |
54 | void VisitExpr_(const VarNode* op) override; |
55 | void VisitExpr_(const GlobalVarNode* op) override; |
56 | void VisitExpr_(const ConstantNode* op) override; |
57 | void VisitExpr_(const TupleNode* op) override; |
58 | void VisitExpr_(const FunctionNode* op) override; |
59 | void VisitExpr_(const CallNode* op) override; |
60 | void VisitExpr_(const LetNode* op) override; |
61 | void VisitExpr_(const IfNode* op) override; |
62 | void VisitExpr_(const OpNode* op) override; |
63 | void VisitExpr_(const TupleGetItemNode* op) override; |
64 | void VisitExpr_(const RefCreateNode* op) override; |
65 | void VisitExpr_(const RefReadNode* op) override; |
66 | void VisitExpr_(const RefWriteNode* op) override; |
67 | void VisitExpr_(const ConstructorNode* op) override; |
68 | void VisitExpr_(const MatchNode* op) override; |
69 | void VisitType(const Type& t) override; |
70 | void VisitClause(const Clause& c) override; |
71 | void VisitPattern(const Pattern& c) override; |
72 | void VisitSpan(const Span& span) override; |
73 | }; |
74 | |
75 | Pass SpanCheck(); |
76 | |
77 | } // namespace parser |
78 | } // namespace tvm |
79 | #endif // TVM_PARSER_SPAN_CHECK_H_ |
80 | |