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 | |
| 20 | #include <list> |
| 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: |
| 36 | explicit PassDriver(CompilationUnit* const cu, bool create_default_passes = true); |
| 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 | */ |
| 45 | void InsertPass(Pass *new_pass, bool warn_override = true); |
| 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 | */ |
| 53 | bool RunPass(CompilationUnit* c_unit, const std::string& pass_name); |
| 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 | */ |
| 60 | bool RunPass(CompilationUnit* c_unit, Pass* pass, bool time_split = false); |
| 61 | |
| 62 | void Launch(); |
| 63 | |
| 64 | void HandlePassFlag(CompilationUnit* c_unit, Pass* pass); |
| 65 | |
| 66 | /** |
| 67 | * @brief Apply a patch: perform start/work/end functions. |
| 68 | */ |
| 69 | void ApplyPass(CompilationUnit* c_unit, Pass* pass); |
| 70 | |
| 71 | /** |
| 72 | * @brief Dispatch a patch: walk the BasicBlocks depending on the traversal mode |
| 73 | */ |
| 74 | void DispatchPass(CompilationUnit* c_unit, Pass* pass); |
| 75 | |
| 76 | void PrintPassNames() const; |
| 77 | |
| 78 | Pass* GetPass(const std::string& name) const; |
| 79 | |
| 80 | const char *GetDumpCFGFolder() const { |
| 81 | return dump_cfg_folder_; |
| 82 | } |
| 83 | |
| 84 | protected: |
| 85 | void CreatePasses(); |
| 86 | |
| 87 | /** @brief The Pass Map: contains name -> pass for quick lookup. */ |
| 88 | SafeMap<std::string, Pass*> pass_map_; |
| 89 | |
| 90 | /** @brief List of passes: provides the order to execute the passes. */ |
| 91 | std::list<Pass*> pass_list_; |
| 92 | |
| 93 | /** @brief The CompilationUnit on which to execute the passes on. */ |
| 94 | CompilationUnit* const cu_; |
| 95 | |
| 96 | /** @brief Dump CFG base folder: where is the base folder for dumping CFGs. */ |
| 97 | const char* dump_cfg_folder_; |
| 98 | }; |
| 99 | |
| 100 | } // namespace art |
| 101 | #endif // ART_COMPILER_DEX_PASS_DRIVER_H_ |