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 tvm/arithmetic/ir_mutator_with_analyzer.h
22 * \brief IR mutator base-class with an analyzer context.
23 */
24#ifndef TVM_ARITH_IR_MUTATOR_WITH_ANALYZER_H_
25#define TVM_ARITH_IR_MUTATOR_WITH_ANALYZER_H_
26
27#include <tvm/arith/analyzer.h>
28#include <tvm/tir/stmt_functor.h>
29
30#include <utility>
31
32namespace tvm {
33namespace arith {
34
35/*!
36 * \brief IRMutator with an analyzer context.
37 *
38 * This class can sub-classed by ir mutators that need an analyzer.
39 * It will populates scope-related info such as bounds of loop-variables and constraints
40 * for the analyzer, so that the child class can do accurate context-dependent analysis.
41 *
42 * \sa src/arithmetic/ir_mutator_with_analyzer.cc
43 */
44class IRMutatorWithAnalyzer : public tir::StmtExprMutator {
45 public:
46 explicit IRMutatorWithAnalyzer(Analyzer* analyzer) : analyzer_(analyzer) {}
47
48 using StmtExprMutator::VisitExpr_;
49 using StmtExprMutator::VisitStmt_;
50
51 // override functions that need to populate the context information.
52 tir::Stmt VisitStmt_(const tir::ForNode* op) override;
53 tir::Stmt VisitStmt_(const tir::BlockNode* op) override;
54 tir::Stmt VisitStmt_(const tir::LetStmtNode* op) override;
55 tir::Stmt VisitStmt_(const tir::IfThenElseNode* op) override;
56 tir::Stmt VisitStmt_(const tir::AttrStmtNode* op) override;
57 tir::Stmt VisitStmt_(const tir::AssertStmtNode* op) override;
58 PrimExpr VisitExpr_(const tir::LetNode* op) override;
59 PrimExpr VisitExpr_(const tir::SelectNode* op) override;
60 PrimExpr VisitExpr_(const tir::CallNode* op) override;
61 PrimExpr VisitExpr_(const tir::ReduceNode* op) override;
62
63 protected:
64 /*! \brief internal analyzer field. */
65 Analyzer* analyzer_;
66};
67
68} // namespace arith
69} // namespace tvm
70#endif // TVM_ARITH_IR_MUTATOR_WITH_ANALYZER_H_
71