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 check_contains.h |
22 | * \brief Interface of the analysis that tells if an expression contains |
23 | a node that satisfies a given predicate. |
24 | */ |
25 | |
26 | #ifndef TVM_TIR_ANALYSIS_CHECK_CONTAINS_H_ |
27 | #define TVM_TIR_ANALYSIS_CHECK_CONTAINS_H_ |
28 | |
29 | #include <tvm/tir/expr.h> |
30 | #include <tvm/tir/stmt_functor.h> // For the class StmtExprVisitor |
31 | |
32 | namespace tvm { |
33 | namespace tir { |
34 | |
35 | /*! |
36 | * \brief Visitor which tells if a given expression or statement contains a subexpression |
37 | that satisfies a given predicate |
38 | */ |
39 | class CheckContains : public StmtExprVisitor { |
40 | public: |
41 | // Toplevel (static) functions |
42 | static bool ExprContains(const PrimExpr& expr, std::function<bool(const PrimExpr&)> predicate); |
43 | static bool StmtContains(const Stmt& stmt, std::function<bool(const PrimExpr&)> predicate); |
44 | |
45 | protected: |
46 | // Constructor |
47 | explicit CheckContains(std::function<bool(const PrimExpr&)> predicate); |
48 | |
49 | void VisitExpr(const PrimExpr& expr) override; |
50 | void VisitStmt(const Stmt& stmt) override; |
51 | |
52 | private: |
53 | std::function<bool(const PrimExpr&)> predicate_; |
54 | bool contains_it_ = false; |
55 | }; |
56 | |
57 | } // namespace tir |
58 | } // namespace tvm |
59 | |
60 | #endif // TVM_TIR_ANALYSIS_CHECK_CONTAINS_H_ |
61 | |