Roland Levillain | bf9cd7b | 2014-09-30 16:15:14 +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 | |
| 20 | #include "graph_visualizer.h" |
| 21 | #include "nodes.h" |
| 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, |
| 32 | const char* pass_name, |
| 33 | const HGraphVisualizer& visualizer) |
| 34 | : graph_(graph), |
| 35 | is_in_ssa_form_(is_in_ssa_form), |
| 36 | pass_name_(pass_name), |
| 37 | visualizer_(visualizer) {} |
| 38 | |
| 39 | virtual ~HOptimization() {} |
| 40 | |
| 41 | // Execute the optimization pass. |
| 42 | void Execute(); |
| 43 | |
| 44 | // Return the name of the pass. |
| 45 | const char* GetPassName() const { return pass_name_; } |
| 46 | |
| 47 | // Peform the analysis itself. |
| 48 | virtual void Run() = 0; |
| 49 | |
| 50 | private: |
| 51 | // Verify the graph; abort if it is not valid. |
| 52 | void Check(); |
| 53 | |
| 54 | template <typename T> |
| 55 | void CheckInternal(T* checker) { |
| 56 | checker->VisitInsertionOrder(); |
| 57 | if (!checker->IsValid()) { |
| 58 | LOG(FATAL) << Dumpable<T>(*checker); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | protected: |
| 63 | HGraph* const graph_; |
| 64 | |
| 65 | private: |
| 66 | // Does the analyzed graph use SSA form? |
| 67 | bool is_in_ssa_form_; |
| 68 | // Optimization pass name. |
| 69 | const char* pass_name_; |
| 70 | // A graph visualiser invoked during the execution of the |
| 71 | // optimization pass if non null. |
| 72 | const HGraphVisualizer& visualizer_; |
| 73 | |
| 74 | DISALLOW_COPY_AND_ASSIGN(HOptimization); |
| 75 | }; |
| 76 | |
| 77 | } // namespace art |
| 78 | |
| 79 | #endif // ART_COMPILER_OPTIMIZING_OPTIMIZATION_H_ |