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 | /** |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 26 | * @class CacheFieldLoweringInfo |
| 27 | * @brief Cache the lowering info for fields used by IGET/IPUT/SGET/SPUT insns. |
| 28 | */ |
| 29 | class CacheFieldLoweringInfo : public Pass { |
| 30 | public: |
| 31 | CacheFieldLoweringInfo() : Pass("CacheFieldLoweringInfo", kNoNodes) { |
| 32 | } |
| 33 | |
| 34 | void Start(CompilationUnit* cUnit) const { |
| 35 | cUnit->mir_graph->DoCacheFieldLoweringInfo(); |
| 36 | } |
Vladimir Marko | 3d73ba2 | 2014-03-06 15:18:04 +0000 | [diff] [blame] | 37 | |
| 38 | bool Gate(const CompilationUnit *cUnit) const { |
| 39 | return cUnit->mir_graph->HasFieldAccess(); |
| 40 | } |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | /** |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 44 | * @class CacheMethodLoweringInfo |
| 45 | * @brief Cache the lowering info for methods called by INVOKEs. |
| 46 | */ |
| 47 | class CacheMethodLoweringInfo : public Pass { |
| 48 | public: |
| 49 | CacheMethodLoweringInfo() : Pass("CacheMethodLoweringInfo", kNoNodes) { |
| 50 | } |
| 51 | |
| 52 | void Start(CompilationUnit* cUnit) const { |
| 53 | cUnit->mir_graph->DoCacheMethodLoweringInfo(); |
| 54 | } |
Vladimir Marko | 3d73ba2 | 2014-03-06 15:18:04 +0000 | [diff] [blame] | 55 | |
| 56 | bool Gate(const CompilationUnit *cUnit) const { |
| 57 | return cUnit->mir_graph->HasInvokes(); |
| 58 | } |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | /** |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 62 | * @class CallInlining |
| 63 | * @brief Perform method inlining pass. |
| 64 | */ |
| 65 | class CallInlining : public Pass { |
| 66 | public: |
| 67 | CallInlining() : Pass("CallInlining") { |
| 68 | } |
| 69 | |
| 70 | bool Gate(const CompilationUnit* cUnit) const { |
| 71 | return cUnit->mir_graph->InlineCallsGate(); |
| 72 | } |
| 73 | |
| 74 | void Start(CompilationUnit* cUnit) const { |
| 75 | cUnit->mir_graph->InlineCallsStart(); |
| 76 | } |
| 77 | |
| 78 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const { |
| 79 | cUnit->mir_graph->InlineCalls(bb); |
| 80 | // No need of repeating, so just return false. |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | void End(CompilationUnit* cUnit) const { |
| 85 | cUnit->mir_graph->InlineCallsEnd(); |
| 86 | } |
| 87 | }; |
| 88 | |
| 89 | /** |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 90 | * @class CodeLayout |
| 91 | * @brief Perform the code layout pass. |
| 92 | */ |
| 93 | class CodeLayout : public Pass { |
| 94 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 95 | CodeLayout() : Pass("CodeLayout", "2_post_layout_cfg") { |
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 | void Start(CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 99 | cUnit->mir_graph->VerifyDataflow(); |
| 100 | } |
| 101 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 102 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | /** |
| 106 | * @class SSATransformation |
| 107 | * @brief Perform an SSA representation pass on the CompilationUnit. |
| 108 | */ |
| 109 | class SSATransformation : public Pass { |
| 110 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 111 | SSATransformation() : Pass("SSATransformation", kPreOrderDFSTraversal, "3_post_ssa_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 112 | } |
| 113 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 114 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 115 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 116 | void Start(CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 117 | cUnit->mir_graph->InitializeSSATransformation(); |
| 118 | } |
| 119 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 120 | void End(CompilationUnit* cUnit) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | /** |
| 124 | * @class ConstantPropagation |
| 125 | * @brief Perform a constant propagation pass. |
| 126 | */ |
| 127 | class ConstantPropagation : public Pass { |
| 128 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 129 | ConstantPropagation() : Pass("ConstantPropagation") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 130 | } |
| 131 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 132 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 133 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 134 | void Start(CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 135 | cUnit->mir_graph->InitializeConstantPropagation(); |
| 136 | } |
| 137 | }; |
| 138 | |
| 139 | /** |
| 140 | * @class InitRegLocations |
| 141 | * @brief Initialize Register Locations. |
| 142 | */ |
| 143 | class InitRegLocations : public Pass { |
| 144 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 145 | InitRegLocations() : Pass("InitRegLocation", kNoNodes) { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 146 | } |
| 147 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 148 | void Start(CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 149 | cUnit->mir_graph->InitRegLocations(); |
| 150 | } |
| 151 | }; |
| 152 | |
| 153 | /** |
| 154 | * @class MethodUseCount |
| 155 | * @brief Count the register uses of the method |
| 156 | */ |
| 157 | class MethodUseCount : public Pass { |
| 158 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 159 | MethodUseCount() : Pass("UseCount") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 160 | } |
| 161 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 162 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 163 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 164 | bool Gate(const CompilationUnit* cUnit) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | /** |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 168 | * @class NullCheckEliminationAndTypeInference |
| 169 | * @brief Null check elimination and type inference. |
| 170 | */ |
| 171 | class NullCheckEliminationAndTypeInference : public Pass { |
| 172 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 173 | NullCheckEliminationAndTypeInference() |
| 174 | : Pass("NCE_TypeInference", kRepeatingPreOrderDFSTraversal, "4_post_nce_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 177 | void Start(CompilationUnit* cUnit) const { |
| 178 | cUnit->mir_graph->EliminateNullChecksAndInferTypesStart(); |
| 179 | } |
| 180 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 181 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 182 | return cUnit->mir_graph->EliminateNullChecksAndInferTypes(bb); |
| 183 | } |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 184 | |
| 185 | void End(CompilationUnit* cUnit) const { |
| 186 | cUnit->mir_graph->EliminateNullChecksAndInferTypesEnd(); |
| 187 | } |
| 188 | }; |
| 189 | |
| 190 | class ClassInitCheckElimination : public Pass { |
| 191 | public: |
| 192 | ClassInitCheckElimination() : Pass("ClInitCheckElimination", kRepeatingPreOrderDFSTraversal) { |
| 193 | } |
| 194 | |
| 195 | bool Gate(const CompilationUnit* cUnit) const { |
| 196 | return cUnit->mir_graph->EliminateClassInitChecksGate(); |
| 197 | } |
| 198 | |
| 199 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const { |
| 200 | return cUnit->mir_graph->EliminateClassInitChecks(bb); |
| 201 | } |
| 202 | |
| 203 | void End(CompilationUnit* cUnit) const { |
| 204 | cUnit->mir_graph->EliminateClassInitChecksEnd(); |
| 205 | } |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | /** |
| 209 | * @class NullCheckEliminationAndTypeInference |
| 210 | * @brief Null check elimination and type inference. |
| 211 | */ |
| 212 | class BBCombine : public Pass { |
| 213 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 214 | BBCombine() : Pass("BBCombine", kPreOrderDFSTraversal, "5_post_bbcombine_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 217 | bool Gate(const CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 218 | return ((cUnit->disable_opt & (1 << kSuppressExceptionEdges)) != 0); |
| 219 | } |
| 220 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 221 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | /** |
| 225 | * @class BasicBlock Optimizations |
| 226 | * @brief Any simple BasicBlock optimization can be put here. |
| 227 | */ |
| 228 | class BBOptimizations : public Pass { |
| 229 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 230 | BBOptimizations() : Pass("BBOptimizations", kNoNodes, "5_post_bbo_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 231 | } |
| 232 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 233 | bool Gate(const CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 234 | return ((cUnit->disable_opt & (1 << kBBOpt)) == 0); |
| 235 | } |
| 236 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 237 | void Start(CompilationUnit* cUnit) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 238 | }; |
| 239 | |
| 240 | } // namespace art |
| 241 | |
| 242 | #endif // ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_ |