1 /* 2 * Copyright (C) 2015 The Android Open Source Project 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 ART_COMPILER_DEX_PASS_MANAGER_H_ 18 #define ART_COMPILER_DEX_PASS_MANAGER_H_ 19 20 #include <string> 21 #include <vector> 22 23 #include "base/logging.h" 24 25 namespace art { 26 27 class Pass; 28 29 class PassManagerOptions { 30 public: PassManagerOptions()31 PassManagerOptions() 32 : default_print_passes_(false), 33 print_pass_names_(false), 34 print_pass_options_(false) { 35 } 36 explicit PassManagerOptions(const PassManagerOptions&) = default; 37 SetPrintPassNames(bool b)38 void SetPrintPassNames(bool b) { 39 print_pass_names_ = b; 40 } 41 SetPrintAllPasses()42 void SetPrintAllPasses() { 43 default_print_passes_ = true; 44 } GetPrintAllPasses()45 bool GetPrintAllPasses() const { 46 return default_print_passes_; 47 } 48 SetDisablePassList(const std::string & list)49 void SetDisablePassList(const std::string& list) { 50 disable_pass_list_ = list; 51 } GetDisablePassList()52 const std::string& GetDisablePassList() const { 53 return disable_pass_list_; 54 } 55 SetPrintPassList(const std::string & list)56 void SetPrintPassList(const std::string& list) { 57 print_pass_list_ = list; 58 } GetPrintPassList()59 const std::string& GetPrintPassList() const { 60 return print_pass_list_; 61 } 62 SetDumpPassList(const std::string & list)63 void SetDumpPassList(const std::string& list) { 64 dump_pass_list_ = list; 65 } GetDumpPassList()66 const std::string& GetDumpPassList() const { 67 return dump_pass_list_; 68 } 69 70 /** 71 * @brief Used to set a string that contains the overridden pass options. 72 * @details An overridden pass option means that the pass uses this option 73 * instead of using its default option. 74 * @param s The string passed by user with overridden options. The string is in format 75 * Pass1Name:Pass1Option:Pass1Setting,Pass2Name:Pass2Option::Pass2Setting 76 */ SetOverriddenPassOptions(const std::string & list)77 void SetOverriddenPassOptions(const std::string& list) { 78 overridden_pass_options_list_ = list; 79 } GetOverriddenPassOptions()80 const std::string& GetOverriddenPassOptions() const { 81 return overridden_pass_options_list_; 82 } 83 SetPrintPassOptions(bool b)84 void SetPrintPassOptions(bool b) { 85 print_pass_options_ = b; 86 } GetPrintPassOptions()87 bool GetPrintPassOptions() const { 88 return print_pass_options_; 89 } 90 91 private: 92 /** @brief Do we, by default, want to be printing the log messages? */ 93 bool default_print_passes_; 94 95 /** @brief What are the passes we want to be printing the log messages? */ 96 std::string print_pass_list_; 97 98 /** @brief What are the passes we want to be dumping the CFG? */ 99 std::string dump_pass_list_; 100 101 /** @brief String of all options that should be overridden for selected passes */ 102 std::string overridden_pass_options_list_; 103 104 /** @brief String of all options that should be overridden for selected passes */ 105 std::string disable_pass_list_; 106 107 /** @brief Whether or not we print all the passes when we create the pass manager */ 108 bool print_pass_names_; 109 110 /** @brief Whether or not we print all the pass options when we create the pass manager */ 111 bool print_pass_options_; 112 }; 113 114 /** 115 * @class PassManager 116 * @brief Owns passes 117 */ 118 class PassManager { 119 public: 120 explicit PassManager(const PassManagerOptions& options); 121 virtual ~PassManager(); 122 void CreateDefaultPassList(); AddPass(const Pass * pass)123 void AddPass(const Pass* pass) { 124 passes_.push_back(pass); 125 } 126 /** 127 * @brief Print the pass names of all the passes available. 128 */ 129 void PrintPassNames() const; GetDefaultPassList()130 const std::vector<const Pass*>* GetDefaultPassList() const { 131 return &default_pass_list_; 132 } GetOptions()133 const PassManagerOptions& GetOptions() const { 134 return options_; 135 } 136 137 private: 138 /** @brief The set of possible passes. */ 139 std::vector<const Pass*> passes_; 140 141 /** @brief The default pass list is used to initialize pass_list_. */ 142 std::vector<const Pass*> default_pass_list_; 143 144 /** @brief Pass manager options. */ 145 PassManagerOptions options_; 146 147 DISALLOW_COPY_AND_ASSIGN(PassManager); 148 }; 149 } // namespace art 150 #endif // ART_COMPILER_DEX_PASS_MANAGER_H_ 151