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_visitor_with_analyzer.h
22 * \brief IR visitor class with an analyzer context.
23 */
24
25#ifndef TVM_ARITH_IR_VISITOR_WITH_ANALYZER_H_
26#define TVM_ARITH_IR_VISITOR_WITH_ANALYZER_H_
27
28#include <tvm/arith/analyzer.h>
29#include <tvm/tir/expr.h>
30#include <tvm/tir/stmt_functor.h>
31
32namespace tvm {
33namespace arith {
34
35class IRVisitorWithAnalyzer : public tir::StmtExprVisitor {
36 public:
37 PrimExpr Simplify(const PrimExpr& expr) { return analyzer_.Simplify(expr); }
38
39 using StmtExprVisitor::VisitExpr_;
40 using StmtExprVisitor::VisitStmt_;
41
42 void VisitStmt_(const tir::ForNode* op);
43 void VisitStmt_(const tir::BlockNode* op);
44 void VisitStmt_(const tir::LetStmtNode* op);
45 void VisitStmt_(const tir::IfThenElseNode* op);
46 void VisitStmt_(const tir::AttrStmtNode* op);
47 void VisitStmt_(const tir::AssertStmtNode* op);
48 void VisitExpr_(const tir::CallNode* op);
49 void VisitExpr_(const tir::LetNode* op);
50 void VisitExpr_(const tir::ReduceNode* op);
51
52 // IRVisitorWithAnalyzer deliberately does not handle Select nodes,
53 // because both sides of a Select node are visited regardless of the
54 // condition.
55
56 protected:
57 /*! \brief internal analyzer field. */
58 arith::Analyzer analyzer_;
59
60 /*! \brief Extract a constraint from a conditional statement
61 *
62 * Intended for preparing argument for use in
63 * `With<ConstraintContext>`.
64 */
65 PrimExpr ExtractRealCondition(PrimExpr condition) const;
66};
67
68} // namespace arith
69} // namespace tvm
70#endif // TVM_ARITH_IR_VISITOR_WITH_ANALYZER_H_
71