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 | } |
| 37 | }; |
| 38 | |
| 39 | /** |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame^] | 40 | * @class CacheMethodLoweringInfo |
| 41 | * @brief Cache the lowering info for methods called by INVOKEs. |
| 42 | */ |
| 43 | class CacheMethodLoweringInfo : public Pass { |
| 44 | public: |
| 45 | CacheMethodLoweringInfo() : Pass("CacheMethodLoweringInfo", kNoNodes) { |
| 46 | } |
| 47 | |
| 48 | void Start(CompilationUnit* cUnit) const { |
| 49 | cUnit->mir_graph->DoCacheMethodLoweringInfo(); |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | /** |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 54 | * @class CodeLayout |
| 55 | * @brief Perform the code layout pass. |
| 56 | */ |
| 57 | class CodeLayout : public Pass { |
| 58 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 59 | CodeLayout() : Pass("CodeLayout", "2_post_layout_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 62 | void Start(CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 63 | cUnit->mir_graph->VerifyDataflow(); |
| 64 | } |
| 65 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 66 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | /** |
| 70 | * @class SSATransformation |
| 71 | * @brief Perform an SSA representation pass on the CompilationUnit. |
| 72 | */ |
| 73 | class SSATransformation : public Pass { |
| 74 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 75 | SSATransformation() : Pass("SSATransformation", kPreOrderDFSTraversal, "3_post_ssa_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 78 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 79 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 80 | void Start(CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 81 | cUnit->mir_graph->InitializeSSATransformation(); |
| 82 | } |
| 83 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 84 | void End(CompilationUnit* cUnit) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | /** |
| 88 | * @class ConstantPropagation |
| 89 | * @brief Perform a constant propagation pass. |
| 90 | */ |
| 91 | class ConstantPropagation : public Pass { |
| 92 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 93 | ConstantPropagation() : Pass("ConstantPropagation") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 94 | } |
| 95 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 96 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 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->InitializeConstantPropagation(); |
| 100 | } |
| 101 | }; |
| 102 | |
| 103 | /** |
| 104 | * @class InitRegLocations |
| 105 | * @brief Initialize Register Locations. |
| 106 | */ |
| 107 | class InitRegLocations : public Pass { |
| 108 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 109 | InitRegLocations() : Pass("InitRegLocation", kNoNodes) { |
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 | void Start(CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 113 | cUnit->mir_graph->InitRegLocations(); |
| 114 | } |
| 115 | }; |
| 116 | |
| 117 | /** |
| 118 | * @class MethodUseCount |
| 119 | * @brief Count the register uses of the method |
| 120 | */ |
| 121 | class MethodUseCount : public Pass { |
| 122 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 123 | MethodUseCount() : Pass("UseCount") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 124 | } |
| 125 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 126 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 127 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 128 | bool Gate(const CompilationUnit* cUnit) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | /** |
| 132 | * @class NullCheckEliminationAndTypeInferenceInit |
| 133 | * @brief Null check elimination and type inference initialization step. |
| 134 | */ |
| 135 | class NullCheckEliminationAndTypeInferenceInit : public Pass { |
| 136 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 137 | NullCheckEliminationAndTypeInferenceInit() : Pass("NCE_TypeInferenceInit") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 138 | } |
| 139 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 140 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 141 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 142 | bool Gate(const CompilationUnit* cUnit) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | /** |
| 146 | * @class NullCheckEliminationAndTypeInference |
| 147 | * @brief Null check elimination and type inference. |
| 148 | */ |
| 149 | class NullCheckEliminationAndTypeInference : public Pass { |
| 150 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 151 | NullCheckEliminationAndTypeInference() |
| 152 | : Pass("NCE_TypeInference", kRepeatingPreOrderDFSTraversal, "4_post_nce_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 153 | } |
| 154 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 155 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 156 | return cUnit->mir_graph->EliminateNullChecksAndInferTypes(bb); |
| 157 | } |
| 158 | }; |
| 159 | |
| 160 | /** |
| 161 | * @class NullCheckEliminationAndTypeInference |
| 162 | * @brief Null check elimination and type inference. |
| 163 | */ |
| 164 | class BBCombine : public Pass { |
| 165 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 166 | BBCombine() : Pass("BBCombine", kPreOrderDFSTraversal, "5_post_bbcombine_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 169 | bool Gate(const CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 170 | return ((cUnit->disable_opt & (1 << kSuppressExceptionEdges)) != 0); |
| 171 | } |
| 172 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 173 | bool WalkBasicBlocks(CompilationUnit* cUnit, BasicBlock* bb) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | /** |
| 177 | * @class BasicBlock Optimizations |
| 178 | * @brief Any simple BasicBlock optimization can be put here. |
| 179 | */ |
| 180 | class BBOptimizations : public Pass { |
| 181 | public: |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 182 | BBOptimizations() : Pass("BBOptimizations", kNoNodes, "5_post_bbo_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 183 | } |
| 184 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 185 | bool Gate(const CompilationUnit* cUnit) const { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 186 | return ((cUnit->disable_opt & (1 << kBBOpt)) == 0); |
| 187 | } |
| 188 | |
Vladimir Marko | 75ba13f | 2014-01-28 12:15:24 +0000 | [diff] [blame] | 189 | void Start(CompilationUnit* cUnit) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 190 | }; |
| 191 | |
| 192 | } // namespace art |
| 193 | |
| 194 | #endif // ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_ |