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