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_H_ |
| 18 | #define ART_COMPILER_DEX_PASS_H_ |
| 19 | |
| 20 | #include <string> |
| 21 | |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 22 | #include "base/macros.h" |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 23 | namespace art { |
| 24 | |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 25 | // Empty Pass Data Class, can be extended by any pass extending the base Pass class. |
| 26 | class PassDataHolder { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | /** |
| 30 | * @class Pass |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 31 | * @brief Base Pass class, can be extended to perform a more defined way of doing the work call. |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 32 | */ |
| 33 | class Pass { |
| 34 | public: |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 35 | explicit Pass(const char* name) |
| 36 | : pass_name_(name) { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 37 | } |
| 38 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 39 | virtual ~Pass() { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 40 | } |
| 41 | |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 42 | virtual const char* GetName() const { |
| 43 | return pass_name_; |
| 44 | } |
| 45 | |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 46 | /** |
| 47 | * @brief Gate for the pass: determines whether to execute the pass or not considering a CompilationUnit |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 48 | * @param data the PassDataHolder. |
| 49 | * @return whether or not to execute the pass. |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 50 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 51 | virtual bool Gate(const PassDataHolder* data) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 52 | // Unused parameter. |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 53 | UNUSED(data); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 54 | |
| 55 | // Base class says yes. |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | /** |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 60 | * @brief Start of the pass: called before the Worker function. |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 61 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 62 | virtual void Start(const PassDataHolder* data) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 63 | // Unused parameter. |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 64 | UNUSED(data); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /** |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 68 | * @brief End of the pass: called after the WalkBasicBlocks function. |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 69 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 70 | virtual void End(const PassDataHolder* data) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 71 | // Unused parameter. |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 72 | UNUSED(data); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /** |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 76 | * @param data the object containing data necessary for the pass. |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 77 | * @return whether or not there is a change when walking the BasicBlock |
| 78 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 79 | virtual bool Worker(const PassDataHolder* data) const { |
| 80 | // Unused parameter. |
| 81 | UNUSED(data); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 82 | |
| 83 | // BasicBlock did not change. |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | protected: |
| 88 | /** @brief The pass name: used for searching for a pass when running a particular pass or debugging. */ |
| 89 | const char* const pass_name_; |
| 90 | |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 91 | private: |
| 92 | // In order to make the all passes not copy-friendly. |
| 93 | DISALLOW_COPY_AND_ASSIGN(Pass); |
| 94 | }; |
| 95 | } // namespace art |
| 96 | #endif // ART_COMPILER_DEX_PASS_H_ |