Roland Levillain | 75be283 | 2014-10-17 17:02:00 +0100 | [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_OPTIMIZING_OPTIMIZATION_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_OPTIMIZATION_H_ |
| 19 | |
Roland Levillain | 75be283 | 2014-10-17 17:02:00 +0100 | [diff] [blame] | 20 | #include "nodes.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 21 | #include "optimizing_compiler_stats.h" |
Roland Levillain | 75be283 | 2014-10-17 17:02:00 +0100 | [diff] [blame] | 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | /** |
| 26 | * Abstraction to implement an optimization pass. |
| 27 | */ |
| 28 | class HOptimization : public ValueObject { |
| 29 | public: |
| 30 | HOptimization(HGraph* graph, |
| 31 | bool is_in_ssa_form, |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 32 | const char* pass_name, |
| 33 | OptimizingCompilerStats* stats = nullptr) |
Roland Levillain | 75be283 | 2014-10-17 17:02:00 +0100 | [diff] [blame] | 34 | : graph_(graph), |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 35 | stats_(stats), |
Roland Levillain | 75be283 | 2014-10-17 17:02:00 +0100 | [diff] [blame] | 36 | is_in_ssa_form_(is_in_ssa_form), |
Nicolas Geoffray | 5e6916c | 2014-11-18 16:53:35 +0000 | [diff] [blame] | 37 | pass_name_(pass_name) {} |
Roland Levillain | 75be283 | 2014-10-17 17:02:00 +0100 | [diff] [blame] | 38 | |
| 39 | virtual ~HOptimization() {} |
| 40 | |
Roland Levillain | 75be283 | 2014-10-17 17:02:00 +0100 | [diff] [blame] | 41 | // Return the name of the pass. |
| 42 | const char* GetPassName() const { return pass_name_; } |
| 43 | |
| 44 | // Peform the analysis itself. |
| 45 | virtual void Run() = 0; |
| 46 | |
Roland Levillain | 75be283 | 2014-10-17 17:02:00 +0100 | [diff] [blame] | 47 | // Verify the graph; abort if it is not valid. |
| 48 | void Check(); |
| 49 | |
| 50 | protected: |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 51 | void MaybeRecordStat(MethodCompilationStat compilation_stat, size_t count = 1) const; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 52 | |
Roland Levillain | 75be283 | 2014-10-17 17:02:00 +0100 | [diff] [blame] | 53 | HGraph* const graph_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 54 | // Used to record stats about the optimization. |
| 55 | OptimizingCompilerStats* const stats_; |
Roland Levillain | 75be283 | 2014-10-17 17:02:00 +0100 | [diff] [blame] | 56 | |
| 57 | private: |
| 58 | // Does the analyzed graph use the SSA form? |
| 59 | const bool is_in_ssa_form_; |
| 60 | // Optimization pass name. |
| 61 | const char* pass_name_; |
Roland Levillain | 75be283 | 2014-10-17 17:02:00 +0100 | [diff] [blame] | 62 | |
| 63 | DISALLOW_COPY_AND_ASSIGN(HOptimization); |
| 64 | }; |
| 65 | |
| 66 | } // namespace art |
| 67 | |
| 68 | #endif // ART_COMPILER_OPTIMIZING_OPTIMIZATION_H_ |