1 /** 2 * Copyright 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 17 #ifndef MINDSPORE_LITE_TOOLS_CONVERTER_OPTIMIZER_MANAGER_H_ 18 #define MINDSPORE_LITE_TOOLS_CONVERTER_OPTIMIZER_MANAGER_H_ 19 20 #include <map> 21 #include <set> 22 #include <string> 23 #include <vector> 24 #include "include/backend/optimizer/pass.h" 25 #include "include/errorcode.h" 26 #include "include/registry/pass_registry.h" 27 #include "ir/func_graph.h" 28 29 namespace mindspore { 30 namespace lite { 31 class PassStorage { 32 public: StorePass(const std::string & pass_name,const opt::PassPtr & pass,bool access_for_outer)33 static void StorePass(const std::string &pass_name, const opt::PassPtr &pass, bool access_for_outer) { 34 pass_storage_[pass_name] = pass; 35 if (!access_for_outer) { 36 (void)inaccessible_for_outer_.insert(pass_name); 37 } 38 } ClearPass()39 static void ClearPass() { 40 pass_storage_.clear(); 41 inaccessible_for_outer_.clear(); 42 } GetPassFromStorage(const std::string & pass_name)43 static opt::PassPtr GetPassFromStorage(const std::string &pass_name) { return pass_storage_[pass_name]; } IsAccessibleForOuter(const std::string & pass_name)44 static bool IsAccessibleForOuter(const std::string &pass_name) { 45 return inaccessible_for_outer_.find(pass_name) == inaccessible_for_outer_.end(); 46 } 47 48 private: 49 static std::map<std::string, opt::PassPtr> pass_storage_; 50 static std::set<std::string> inaccessible_for_outer_; 51 }; 52 53 bool RunOptimizerPass(const FuncGraphPtr &func_graph, const std::vector<std::string> &pass_names); 54 bool RunExternalPass(const FuncGraphPtr &func_graph, registry::PassPosition position); 55 } // namespace lite 56 } // namespace mindspore 57 58 #endif // MINDSPORE_LITE_TOOLS_CONVERTER_OPTIMIZER_MANAGER_H_ 59