1 /** 2 * Copyright 2020-2022 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 <string> 22 23 #include "utils/hash_map.h" 24 #include "include/backend/optimizer/pass.h" 25 #include "ir/func_graph.h" 26 #include "backend/common/graph_kernel/model/lite_graph.h" 27 28 namespace mindspore::graphkernel { 29 class PatternTree; 30 using PatternTreePtr = std::shared_ptr<PatternTree>; 31 class ArithmeticSimplify : public opt::Pass { 32 public: ArithmeticSimplify()33 ArithmeticSimplify() : Pass("arithmetic_simplify") {} 34 ~ArithmeticSimplify() override = default; 35 bool Run(const FuncGraphPtr &func_graph) override; 36 37 private: 38 bool DoArithmeticTrans(const inner::LiteGraphPtr &litegraph); 39 bool DoConstantFold(const inner::LiteGraphPtr &litegraph); 40 mindspore::HashMap<std::string, std::vector<PatternTreePtr>> expressions_map_; 41 }; 42 using ArithmeticSimplifyPtr = std::shared_ptr<ArithmeticSimplify>; 43 } // namespace mindspore::graphkernel 44 #endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_ARITHMETIC_SIMPLIFY_H_ 45