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_BB_OPTIMIZATIONS_H_ |
| 18 | #define ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_ |
| 19 | |
| 20 | #include "compiler_internals.h" |
| 21 | #include "pass.h" |
| 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | /** |
| 26 | * @class CodeLayout |
| 27 | * @brief Perform the code layout pass. |
| 28 | */ |
| 29 | class CodeLayout : public Pass { |
| 30 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 31 | CodeLayout() : Pass("CodeLayout", "2_post_layout_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 32 | } |
| 33 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 34 | void Start(CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 35 | cUnit->mir_graph->VerifyDataflow(); |
| 36 | } |
| 37 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 38 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | /** |
| 42 | * @class SSATransformation |
| 43 | * @brief Perform an SSA representation pass on the CompilationUnit. |
| 44 | */ |
| 45 | class SSATransformation : public Pass { |
| 46 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 47 | SSATransformation() : Pass("SSATransformation", kPreOrderDFSTraversal, "3_post_ssa_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 50 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 51 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 52 | void Start(CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 53 | cUnit->mir_graph->InitializeSSATransformation(); |
| 54 | } |
| 55 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 56 | void End(CompilationUnit* cUnit) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | /** |
| 60 | * @class ConstantPropagation |
| 61 | * @brief Perform a constant propagation pass. |
| 62 | */ |
| 63 | class ConstantPropagation : public Pass { |
| 64 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 65 | ConstantPropagation() : Pass("ConstantPropagation") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 68 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 69 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 70 | void Start(CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 71 | cUnit->mir_graph->InitializeConstantPropagation(); |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | /** |
| 76 | * @class InitRegLocations |
| 77 | * @brief Initialize Register Locations. |
| 78 | */ |
| 79 | class InitRegLocations : public Pass { |
| 80 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 81 | InitRegLocations() : Pass("InitRegLocation", kNoNodes) { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 82 | } |
| 83 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 84 | void Start(CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 85 | cUnit->mir_graph->InitRegLocations(); |
| 86 | } |
| 87 | }; |
| 88 | |
| 89 | /** |
| 90 | * @class MethodUseCount |
| 91 | * @brief Count the register uses of the method |
| 92 | */ |
| 93 | class MethodUseCount : public Pass { |
| 94 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 95 | MethodUseCount() : Pass("UseCount") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 98 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 99 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 100 | bool Gate(const CompilationUnit* cUnit) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | /** |
| 104 | * @class NullCheckEliminationAndTypeInferenceInit |
| 105 | * @brief Null check elimination and type inference initialization step. |
| 106 | */ |
| 107 | class NullCheckEliminationAndTypeInferenceInit : public Pass { |
| 108 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 109 | NullCheckEliminationAndTypeInferenceInit() : Pass("NCE_TypeInferenceInit") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 110 | } |
| 111 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 112 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 113 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 114 | bool Gate(const CompilationUnit* cUnit) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | /** |
| 118 | * @class NullCheckEliminationAndTypeInference |
| 119 | * @brief Null check elimination and type inference. |
| 120 | */ |
| 121 | class NullCheckEliminationAndTypeInference : public Pass { |
| 122 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 123 | NullCheckEliminationAndTypeInference() |
| 124 | : Pass("NCE_TypeInference", kRepeatingPreOrderDFSTraversal, "4_post_nce_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 125 | } |
| 126 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 127 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 128 | return cUnit->mir_graph->EliminateNullChecksAndInferTypes(bb); |
| 129 | } |
| 130 | }; |
| 131 | |
| 132 | /** |
| 133 | * @class NullCheckEliminationAndTypeInference |
| 134 | * @brief Null check elimination and type inference. |
| 135 | */ |
| 136 | class BBCombine : public Pass { |
| 137 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 138 | BBCombine() : Pass("BBCombine", kPreOrderDFSTraversal, "5_post_bbcombine_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 141 | bool Gate(const CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 142 | return ((cUnit->disable_opt & (1 << kSuppressExceptionEdges)) != 0); |
| 143 | } |
| 144 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 145 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | /** |
| 149 | * @class BasicBlock Optimizations |
| 150 | * @brief Any simple BasicBlock optimization can be put here. |
| 151 | */ |
| 152 | class BBOptimizations : public Pass { |
| 153 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 154 | BBOptimizations() : Pass("BBOptimizations", kNoNodes, "5_post_bbo_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 155 | } |
| 156 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 157 | bool Gate(const CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 158 | return ((cUnit->disable_opt & (1 << kBBOpt)) == 0); |
| 159 | } |
| 160 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 161 | void Start(CompilationUnit* cUnit) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | } // namespace art |
| 165 | |
| 166 | #endif // ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_ |