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