1 /** 2 * Copyright 2020-2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_ARITHMETIC_SIMPLIFY_H_ 17 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_ARITHMETIC_SIMPLIFY_H_ 18 19 #include <memory> 20 #include <vector> 21 #include <unordered_map> 22 #include <string> 23 24 #include "backend/optimizer/common/optimizer.h" 25 #include "ir/func_graph.h" 26 #include "backend/optimizer/graph_kernel/model/lite_graph.h" 27 28 namespace mindspore { 29 namespace opt { 30 class PatternTree; 31 using PatternTreePtr = std::shared_ptr<PatternTree>; 32 class ArithmeticSimplify : public Pass { 33 public: ArithmeticSimplify()34 ArithmeticSimplify() : Pass("arithmetic_simplify") {} 35 ~ArithmeticSimplify() override = default; 36 bool Run(const FuncGraphPtr &func_graph) override; 37 38 private: 39 bool DoArithmeticTrans(const graphkernel::LiteGraphPtr &litegraph); 40 bool DoConstantFold(const graphkernel::LiteGraphPtr &litegraph); 41 std::unordered_map<std::string, std::vector<PatternTreePtr>> expressions_map_; 42 }; 43 using ArithmeticSimplifyPtr = std::shared_ptr<ArithmeticSimplify>; 44 } // namespace opt 45 } // namespace mindspore 46 #endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_ARITHMETIC_SIMPLIFY_H_ 47