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 | /** |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 62 | * @class CodeLayout |
| 63 | * @brief Perform the code layout pass. |
| 64 | */ |
| 65 | class CodeLayout : public Pass { |
| 66 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 67 | CodeLayout() : Pass("CodeLayout", "2_post_layout_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 68 | } |
| 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->VerifyDataflow(); |
| 72 | } |
| 73 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 74 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | /** |
| 78 | * @class SSATransformation |
| 79 | * @brief Perform an SSA representation pass on the CompilationUnit. |
| 80 | */ |
| 81 | class SSATransformation : public Pass { |
| 82 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 83 | SSATransformation() : Pass("SSATransformation", kPreOrderDFSTraversal, "3_post_ssa_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 84 | } |
| 85 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 86 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 87 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 88 | void Start(CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 89 | cUnit->mir_graph->InitializeSSATransformation(); |
| 90 | } |
| 91 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 92 | void End(CompilationUnit* cUnit) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | /** |
| 96 | * @class ConstantPropagation |
| 97 | * @brief Perform a constant propagation pass. |
| 98 | */ |
| 99 | class ConstantPropagation : public Pass { |
| 100 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 101 | ConstantPropagation() : Pass("ConstantPropagation") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 104 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 105 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 106 | void Start(CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 107 | cUnit->mir_graph->InitializeConstantPropagation(); |
| 108 | } |
| 109 | }; |
| 110 | |
| 111 | /** |
| 112 | * @class InitRegLocations |
| 113 | * @brief Initialize Register Locations. |
| 114 | */ |
| 115 | class InitRegLocations : public Pass { |
| 116 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 117 | InitRegLocations() : Pass("InitRegLocation", kNoNodes) { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 120 | void Start(CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 121 | cUnit->mir_graph->InitRegLocations(); |
| 122 | } |
| 123 | }; |
| 124 | |
| 125 | /** |
| 126 | * @class MethodUseCount |
| 127 | * @brief Count the register uses of the method |
| 128 | */ |
| 129 | class MethodUseCount : public Pass { |
| 130 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 131 | MethodUseCount() : Pass("UseCount") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 134 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 135 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 136 | bool Gate(const CompilationUnit* cUnit) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | /** |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 140 | * @class NullCheckEliminationAndTypeInference |
| 141 | * @brief Null check elimination and type inference. |
| 142 | */ |
| 143 | class NullCheckEliminationAndTypeInference : public Pass { |
| 144 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 145 | NullCheckEliminationAndTypeInference() |
| 146 | : Pass("NCE_TypeInference", kRepeatingPreOrderDFSTraversal, "4_post_nce_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame^] | 149 | void Start(CompilationUnit* cUnit) const { |
| 150 | cUnit->mir_graph->EliminateNullChecksAndInferTypesStart(); |
| 151 | } |
| 152 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 153 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 154 | return cUnit->mir_graph->EliminateNullChecksAndInferTypes(bb); |
| 155 | } |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame^] | 156 | |
| 157 | void End(CompilationUnit* cUnit) const { |
| 158 | cUnit->mir_graph->EliminateNullChecksAndInferTypesEnd(); |
| 159 | } |
| 160 | }; |
| 161 | |
| 162 | class ClassInitCheckElimination : public Pass { |
| 163 | public: |
| 164 | ClassInitCheckElimination() : Pass("ClInitCheckElimination", kRepeatingPreOrderDFSTraversal) { |
| 165 | } |
| 166 | |
| 167 | bool Gate(const CompilationUnit* cUnit) const { |
| 168 | return cUnit->mir_graph->EliminateClassInitChecksGate(); |
| 169 | } |
| 170 | |
| 171 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const { |
| 172 | return cUnit->mir_graph->EliminateClassInitChecks(bb); |
| 173 | } |
| 174 | |
| 175 | void End(CompilationUnit* cUnit) const { |
| 176 | cUnit->mir_graph->EliminateClassInitChecksEnd(); |
| 177 | } |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | /** |
| 181 | * @class NullCheckEliminationAndTypeInference |
| 182 | * @brief Null check elimination and type inference. |
| 183 | */ |
| 184 | class BBCombine : public Pass { |
| 185 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 186 | BBCombine() : Pass("BBCombine", kPreOrderDFSTraversal, "5_post_bbcombine_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 187 | } |
| 188 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 189 | bool Gate(const CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 190 | return ((cUnit->disable_opt & (1 << kSuppressExceptionEdges)) != 0); |
| 191 | } |
| 192 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 193 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | /** |
| 197 | * @class BasicBlock Optimizations |
| 198 | * @brief Any simple BasicBlock optimization can be put here. |
| 199 | */ |
| 200 | class BBOptimizations : public Pass { |
| 201 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 202 | BBOptimizations() : Pass("BBOptimizations", kNoNodes, "5_post_bbo_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 205 | bool Gate(const CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 206 | return ((cUnit->disable_opt & (1 << kBBOpt)) == 0); |
| 207 | } |
| 208 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 209 | void Start(CompilationUnit* cUnit) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | } // namespace art |
| 213 | |
| 214 | #endif // ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_ |