Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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_DRIVER_H_ |
| 18 | #define ART_COMPILER_DEX_PASS_DRIVER_H_ |
| 19 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame^] | 20 | #include <vector> |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 21 | #include "pass.h" |
| 22 | #include "safe_map.h" |
| 23 | |
| 24 | // Forward Declarations. |
| 25 | class CompilationUnit; |
| 26 | class Pass; |
| 27 | |
| 28 | namespace art { |
| 29 | |
| 30 | /** |
| 31 | * @class PassDriver |
| 32 | * @brief PassDriver is the wrapper around all Pass instances in order to execute them from the Middle-End |
| 33 | */ |
| 34 | class PassDriver { |
| 35 | public: |
Jean Christophe Beyler | 775c472 | 2014-01-16 08:51:48 -0800 | [diff] [blame] | 36 | explicit PassDriver(CompilationUnit* cu, bool create_default_passes = true); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 37 | |
| 38 | ~PassDriver(); |
| 39 | |
| 40 | /** |
| 41 | * @brief Insert a Pass: can warn if multiple passes have the same name. |
| 42 | * @param new_pass the new Pass to insert in the map and list. |
| 43 | * @param warn_override warn if the name of the Pass is already used. |
| 44 | */ |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame^] | 45 | void InsertPass(const Pass* new_pass); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * @brief Run a pass using the name as key. |
| 49 | * @param c_unit the considered CompilationUnit. |
| 50 | * @param pass_name the Pass name. |
| 51 | * @return whether the pass was applied. |
| 52 | */ |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame^] | 53 | bool RunPass(CompilationUnit* c_unit, const char* pass_name); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * @brief Run a pass using the Pass itself. |
| 57 | * @param time_split do we want a time split request(default: false)? |
| 58 | * @return whether the pass was applied. |
| 59 | */ |
Jean Christophe Beyler | 775c472 | 2014-01-16 08:51:48 -0800 | [diff] [blame] | 60 | bool RunPass(CompilationUnit* c_unit, const Pass* pass, bool time_split = false); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 61 | |
| 62 | void Launch(); |
| 63 | |
Jean Christophe Beyler | 775c472 | 2014-01-16 08:51:48 -0800 | [diff] [blame] | 64 | void HandlePassFlag(CompilationUnit* c_unit, const Pass* pass); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * @brief Apply a patch: perform start/work/end functions. |
| 68 | */ |
Jean Christophe Beyler | 775c472 | 2014-01-16 08:51:48 -0800 | [diff] [blame] | 69 | void ApplyPass(CompilationUnit* c_unit, const Pass* pass); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * @brief Dispatch a patch: walk the BasicBlocks depending on the traversal mode |
| 73 | */ |
Jean Christophe Beyler | 775c472 | 2014-01-16 08:51:48 -0800 | [diff] [blame] | 74 | void DispatchPass(CompilationUnit* c_unit, const Pass* pass); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 75 | |
| 76 | void PrintPassNames() const; |
| 77 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame^] | 78 | const Pass* GetPass(const char* name) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 79 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame^] | 80 | const char* GetDumpCFGFolder() const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 81 | return dump_cfg_folder_; |
| 82 | } |
| 83 | |
| 84 | protected: |
| 85 | void CreatePasses(); |
| 86 | |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 87 | /** @brief List of passes: provides the order to execute the passes. */ |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame^] | 88 | std::vector<const Pass*> pass_list_; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 89 | |
| 90 | /** @brief The CompilationUnit on which to execute the passes on. */ |
| 91 | CompilationUnit* const cu_; |
| 92 | |
| 93 | /** @brief Dump CFG base folder: where is the base folder for dumping CFGs. */ |
| 94 | const char* dump_cfg_folder_; |
| 95 | }; |
| 96 | |
| 97 | } // namespace art |
| 98 | #endif // ART_COMPILER_DEX_PASS_DRIVER_H_ |