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 | |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 20 | #include "base/casts.h" |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 21 | #include "compiler_internals.h" |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 22 | #include "pass_me.h" |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 23 | |
| 24 | namespace art { |
| 25 | |
| 26 | /** |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 27 | * @class CacheFieldLoweringInfo |
| 28 | * @brief Cache the lowering info for fields used by IGET/IPUT/SGET/SPUT insns. |
| 29 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 30 | class CacheFieldLoweringInfo : public PassME { |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 31 | public: |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 32 | CacheFieldLoweringInfo() : PassME("CacheFieldLoweringInfo", kNoNodes) { |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Jean Christophe Beyler | e1f65bc | 2014-06-09 10:18:26 -0700 | [diff] [blame] | 35 | void Start(PassDataHolder* data) const { |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 36 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 37 | CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; |
| 38 | DCHECK(c_unit != nullptr); |
| 39 | c_unit->mir_graph->DoCacheFieldLoweringInfo(); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 40 | } |
Vladimir Marko | 3d73ba2 | 2014-03-06 15:18:04 +0000 | [diff] [blame] | 41 | |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 42 | bool Gate(const PassDataHolder* data) const { |
| 43 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 44 | CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 45 | DCHECK(c_unit != nullptr); |
| 46 | return c_unit->mir_graph->HasFieldAccess(); |
Vladimir Marko | 3d73ba2 | 2014-03-06 15:18:04 +0000 | [diff] [blame] | 47 | } |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | /** |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 51 | * @class CacheMethodLoweringInfo |
| 52 | * @brief Cache the lowering info for methods called by INVOKEs. |
| 53 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 54 | class CacheMethodLoweringInfo : public PassME { |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 55 | public: |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 56 | CacheMethodLoweringInfo() : PassME("CacheMethodLoweringInfo", kNoNodes) { |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Jean Christophe Beyler | e1f65bc | 2014-06-09 10:18:26 -0700 | [diff] [blame] | 59 | void Start(PassDataHolder* data) const { |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 60 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 61 | CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; |
| 62 | DCHECK(c_unit != nullptr); |
| 63 | c_unit->mir_graph->DoCacheMethodLoweringInfo(); |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 64 | } |
Vladimir Marko | 3d73ba2 | 2014-03-06 15:18:04 +0000 | [diff] [blame] | 65 | |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 66 | bool Gate(const PassDataHolder* data) const { |
| 67 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 68 | CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 69 | DCHECK(c_unit != nullptr); |
| 70 | return c_unit->mir_graph->HasInvokes(); |
Vladimir Marko | 3d73ba2 | 2014-03-06 15:18:04 +0000 | [diff] [blame] | 71 | } |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | /** |
Razvan A Lupusoru | cb80474 | 2014-07-09 16:42:19 -0700 | [diff] [blame] | 75 | * @class SpecialMethodInliner |
| 76 | * @brief Performs method inlining pass on special kinds of methods. |
| 77 | * @details Special methods are methods that fall in one of the following categories: |
| 78 | * empty, instance getter, instance setter, argument return, and constant return. |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 79 | */ |
Razvan A Lupusoru | cb80474 | 2014-07-09 16:42:19 -0700 | [diff] [blame] | 80 | class SpecialMethodInliner : public PassME { |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 81 | public: |
Razvan A Lupusoru | cb80474 | 2014-07-09 16:42:19 -0700 | [diff] [blame] | 82 | SpecialMethodInliner() : PassME("SpecialMethodInliner") { |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 83 | } |
| 84 | |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 85 | bool Gate(const PassDataHolder* data) const { |
| 86 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 87 | CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 88 | DCHECK(c_unit != nullptr); |
| 89 | return c_unit->mir_graph->InlineSpecialMethodsGate(); |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Jean Christophe Beyler | e1f65bc | 2014-06-09 10:18:26 -0700 | [diff] [blame] | 92 | void Start(PassDataHolder* data) const { |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 93 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 94 | CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; |
| 95 | DCHECK(c_unit != nullptr); |
| 96 | c_unit->mir_graph->InlineSpecialMethodsStart(); |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Jean Christophe Beyler | 09321df | 2014-07-18 15:33:57 -0700 | [diff] [blame] | 99 | bool Worker(PassDataHolder* data) const { |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 100 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 09321df | 2014-07-18 15:33:57 -0700 | [diff] [blame] | 101 | PassMEDataHolder* pass_me_data_holder = down_cast<PassMEDataHolder*>(data); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 102 | CompilationUnit* c_unit = pass_me_data_holder->c_unit; |
| 103 | DCHECK(c_unit != nullptr); |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 104 | BasicBlock* bb = pass_me_data_holder->bb; |
| 105 | DCHECK(bb != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 106 | c_unit->mir_graph->InlineSpecialMethods(bb); |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 107 | // No need of repeating, so just return false. |
| 108 | return false; |
| 109 | } |
| 110 | |
Jean Christophe Beyler | e1f65bc | 2014-06-09 10:18:26 -0700 | [diff] [blame] | 111 | void End(PassDataHolder* data) const { |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 112 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 113 | CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; |
| 114 | DCHECK(c_unit != nullptr); |
| 115 | c_unit->mir_graph->InlineSpecialMethodsEnd(); |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 116 | } |
| 117 | }; |
| 118 | |
| 119 | /** |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 120 | * @class CodeLayout |
| 121 | * @brief Perform the code layout pass. |
| 122 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 123 | class CodeLayout : public PassME { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 124 | public: |
Jean Christophe Beyler | 2469e60 | 2014-05-06 20:36:55 -0700 | [diff] [blame] | 125 | CodeLayout() : PassME("CodeLayout", kAllNodes, kOptimizationBasicBlockChange, "2_post_layout_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Jean Christophe Beyler | e1f65bc | 2014-06-09 10:18:26 -0700 | [diff] [blame] | 128 | void Start(PassDataHolder* data) const { |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 129 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 130 | CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; |
| 131 | DCHECK(c_unit != nullptr); |
| 132 | c_unit->mir_graph->VerifyDataflow(); |
| 133 | c_unit->mir_graph->ClearAllVisitedFlags(); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Jean Christophe Beyler | 09321df | 2014-07-18 15:33:57 -0700 | [diff] [blame] | 136 | bool Worker(PassDataHolder* data) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | /** |
Vladimir Marko | 67c72b8 | 2014-10-09 12:26:10 +0100 | [diff] [blame] | 140 | * @class NullCheckElimination |
| 141 | * @brief Null check elimination pass. |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 142 | */ |
Vladimir Marko | 67c72b8 | 2014-10-09 12:26:10 +0100 | [diff] [blame] | 143 | class NullCheckElimination : public PassME { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 144 | public: |
Vladimir Marko | 67c72b8 | 2014-10-09 12:26:10 +0100 | [diff] [blame] | 145 | NullCheckElimination() |
Vladimir Marko | 7baa6f8 | 2014-10-09 18:01:24 +0100 | [diff] [blame] | 146 | : PassME("NCE", kRepeatingPreOrderDFSTraversal, "3_post_nce_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Vladimir Marko | 67c72b8 | 2014-10-09 12:26:10 +0100 | [diff] [blame] | 149 | bool Gate(const PassDataHolder* data) const { |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 150 | DCHECK(data != nullptr); |
Vladimir Marko | 67c72b8 | 2014-10-09 12:26:10 +0100 | [diff] [blame] | 151 | CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 152 | DCHECK(c_unit != nullptr); |
Vladimir Marko | 67c72b8 | 2014-10-09 12:26:10 +0100 | [diff] [blame] | 153 | return c_unit->mir_graph->EliminateNullChecksGate(); |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Jean Christophe Beyler | 09321df | 2014-07-18 15:33:57 -0700 | [diff] [blame] | 156 | bool Worker(PassDataHolder* data) const { |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 157 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 09321df | 2014-07-18 15:33:57 -0700 | [diff] [blame] | 158 | PassMEDataHolder* pass_me_data_holder = down_cast<PassMEDataHolder*>(data); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 159 | CompilationUnit* c_unit = pass_me_data_holder->c_unit; |
| 160 | DCHECK(c_unit != nullptr); |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 161 | BasicBlock* bb = pass_me_data_holder->bb; |
| 162 | DCHECK(bb != nullptr); |
Vladimir Marko | 67c72b8 | 2014-10-09 12:26:10 +0100 | [diff] [blame] | 163 | return c_unit->mir_graph->EliminateNullChecks(bb); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 164 | } |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 165 | |
Jean Christophe Beyler | e1f65bc | 2014-06-09 10:18:26 -0700 | [diff] [blame] | 166 | void End(PassDataHolder* data) const { |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 167 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 168 | CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; |
| 169 | DCHECK(c_unit != nullptr); |
Vladimir Marko | 67c72b8 | 2014-10-09 12:26:10 +0100 | [diff] [blame] | 170 | c_unit->mir_graph->EliminateNullChecksEnd(); |
| 171 | } |
| 172 | }; |
| 173 | |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 174 | class ClassInitCheckElimination : public PassME { |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 175 | public: |
Vladimir Marko | 622bdbe | 2014-06-19 14:59:05 +0100 | [diff] [blame] | 176 | ClassInitCheckElimination() |
Vladimir Marko | 7baa6f8 | 2014-10-09 18:01:24 +0100 | [diff] [blame] | 177 | : PassME("ClInitCheckElimination", kRepeatingPreOrderDFSTraversal) { |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 178 | } |
| 179 | |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 180 | bool Gate(const PassDataHolder* data) const { |
| 181 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 182 | CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 183 | DCHECK(c_unit != nullptr); |
| 184 | return c_unit->mir_graph->EliminateClassInitChecksGate(); |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Jean Christophe Beyler | 09321df | 2014-07-18 15:33:57 -0700 | [diff] [blame] | 187 | bool Worker(PassDataHolder* data) const { |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 188 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 09321df | 2014-07-18 15:33:57 -0700 | [diff] [blame] | 189 | PassMEDataHolder* pass_me_data_holder = down_cast<PassMEDataHolder*>(data); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 190 | CompilationUnit* c_unit = pass_me_data_holder->c_unit; |
| 191 | DCHECK(c_unit != nullptr); |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 192 | BasicBlock* bb = pass_me_data_holder->bb; |
| 193 | DCHECK(bb != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 194 | return c_unit->mir_graph->EliminateClassInitChecks(bb); |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Jean Christophe Beyler | e1f65bc | 2014-06-09 10:18:26 -0700 | [diff] [blame] | 197 | void End(PassDataHolder* data) const { |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 198 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 199 | CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; |
| 200 | DCHECK(c_unit != nullptr); |
| 201 | c_unit->mir_graph->EliminateClassInitChecksEnd(); |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 202 | } |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | /** |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 206 | * @class GlobalValueNumberingPass |
| 207 | * @brief Performs the global value numbering pass. |
| 208 | */ |
| 209 | class GlobalValueNumberingPass : public PassME { |
| 210 | public: |
| 211 | GlobalValueNumberingPass() |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 212 | : PassME("GVN", kLoopRepeatingTopologicalSortTraversal, "4_post_gvn_cfg") { |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 213 | } |
| 214 | |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 215 | bool Gate(const PassDataHolder* data) const OVERRIDE { |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 216 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 217 | CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 218 | DCHECK(c_unit != nullptr); |
| 219 | return c_unit->mir_graph->ApplyGlobalValueNumberingGate(); |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 220 | } |
| 221 | |
Jean Christophe Beyler | 09321df | 2014-07-18 15:33:57 -0700 | [diff] [blame] | 222 | bool Worker(PassDataHolder* data) const { |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 223 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 09321df | 2014-07-18 15:33:57 -0700 | [diff] [blame] | 224 | PassMEDataHolder* pass_me_data_holder = down_cast<PassMEDataHolder*>(data); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 225 | CompilationUnit* c_unit = pass_me_data_holder->c_unit; |
| 226 | DCHECK(c_unit != nullptr); |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 227 | BasicBlock* bb = pass_me_data_holder->bb; |
| 228 | DCHECK(bb != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 229 | return c_unit->mir_graph->ApplyGlobalValueNumbering(bb); |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 230 | } |
| 231 | |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 232 | void End(PassDataHolder* data) const OVERRIDE { |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 233 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 234 | CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; |
| 235 | DCHECK(c_unit != nullptr); |
| 236 | c_unit->mir_graph->ApplyGlobalValueNumberingEnd(); |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 237 | } |
| 238 | }; |
| 239 | |
| 240 | /** |
| 241 | * @class BBCombine |
| 242 | * @brief Perform the basic block combination pass. |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 243 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 244 | class BBCombine : public PassME { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 245 | public: |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 246 | BBCombine() : PassME("BBCombine", kPreOrderDFSTraversal, "5_post_bbcombine_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 247 | } |
| 248 | |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 249 | bool Gate(const PassDataHolder* data) const { |
| 250 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 251 | CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 252 | DCHECK(c_unit != nullptr); |
Vladimir Marko | 312eb25 | 2014-10-07 15:01:57 +0100 | [diff] [blame] | 253 | return c_unit->mir_graph->HasTryCatchBlocks() || |
| 254 | ((c_unit->disable_opt & (1 << kSuppressExceptionEdges)) != 0); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Jean Christophe Beyler | 09321df | 2014-07-18 15:33:57 -0700 | [diff] [blame] | 257 | bool Worker(PassDataHolder* data) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 258 | }; |
| 259 | |
| 260 | /** |
Vladimir Marko | 066f9e4 | 2015-01-16 16:04:43 +0000 | [diff] [blame^] | 261 | * @class ConstantPropagation |
| 262 | * @brief Perform a constant propagation pass. |
| 263 | */ |
| 264 | class ConstantPropagation : public PassME { |
| 265 | public: |
| 266 | ConstantPropagation() : PassME("ConstantPropagation") { |
| 267 | } |
| 268 | |
| 269 | void Start(PassDataHolder* data) const { |
| 270 | DCHECK(data != nullptr); |
| 271 | CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; |
| 272 | DCHECK(c_unit != nullptr); |
| 273 | c_unit->mir_graph->InitializeConstantPropagation(); |
| 274 | } |
| 275 | |
| 276 | bool Worker(PassDataHolder* data) const { |
| 277 | DCHECK(data != nullptr); |
| 278 | CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; |
| 279 | DCHECK(c_unit != nullptr); |
| 280 | BasicBlock* bb = down_cast<PassMEDataHolder*>(data)->bb; |
| 281 | DCHECK(bb != nullptr); |
| 282 | c_unit->mir_graph->DoConstantPropagation(bb); |
| 283 | // No need of repeating, so just return false. |
| 284 | return false; |
| 285 | } |
| 286 | }; |
| 287 | |
| 288 | /** |
| 289 | * @class MethodUseCount |
| 290 | * @brief Count the register uses of the method |
| 291 | */ |
| 292 | class MethodUseCount : public PassME { |
| 293 | public: |
| 294 | MethodUseCount() : PassME("UseCount") { |
| 295 | } |
| 296 | |
| 297 | bool Worker(PassDataHolder* data) const; |
| 298 | |
| 299 | bool Gate(const PassDataHolder* data) const; |
| 300 | }; |
| 301 | |
| 302 | /** |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 303 | * @class BasicBlock Optimizations |
| 304 | * @brief Any simple BasicBlock optimization can be put here. |
| 305 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 306 | class BBOptimizations : public PassME { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 307 | public: |
Vladimir Marko | 341e425 | 2014-12-19 10:29:51 +0000 | [diff] [blame] | 308 | BBOptimizations() |
| 309 | : PassME("BBOptimizations", kNoNodes, kOptimizationBasicBlockChange, "5_post_bbo_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 310 | } |
| 311 | |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 312 | bool Gate(const PassDataHolder* data) const { |
| 313 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 314 | CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 315 | DCHECK(c_unit != nullptr); |
| 316 | return ((c_unit->disable_opt & (1 << kBBOpt)) == 0); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Vladimir Marko | ffda499 | 2014-12-18 17:05:58 +0000 | [diff] [blame] | 319 | void Start(PassDataHolder* data) const { |
| 320 | DCHECK(data != nullptr); |
| 321 | CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; |
| 322 | DCHECK(c_unit != nullptr); |
| 323 | c_unit->mir_graph->BasicBlockOptimizationStart(); |
| 324 | |
| 325 | /* |
| 326 | * This pass has a different ordering depending on the suppress exception, |
| 327 | * so do the pass here for now: |
| 328 | * - Later, the Start should just change the ordering and we can move the extended |
| 329 | * creation into the pass driver's main job with a new iterator |
| 330 | */ |
| 331 | c_unit->mir_graph->BasicBlockOptimization(); |
| 332 | } |
| 333 | |
| 334 | void End(PassDataHolder* data) const { |
| 335 | DCHECK(data != nullptr); |
| 336 | CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 337 | DCHECK(c_unit != nullptr); |
| 338 | c_unit->mir_graph->BasicBlockOptimizationEnd(); |
Vladimir Marko | 341e425 | 2014-12-19 10:29:51 +0000 | [diff] [blame] | 339 | down_cast<PassMEDataHolder*>(data)->dirty = !c_unit->mir_graph->DfsOrdersUpToDate(); |
Vladimir Marko | ffda499 | 2014-12-18 17:05:58 +0000 | [diff] [blame] | 340 | } |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 341 | }; |
| 342 | |
Vladimir Marko | 8b858e1 | 2014-11-27 14:52:37 +0000 | [diff] [blame] | 343 | /** |
| 344 | * @class SuspendCheckElimination |
| 345 | * @brief Any simple BasicBlock optimization can be put here. |
| 346 | */ |
| 347 | class SuspendCheckElimination : public PassME { |
| 348 | public: |
| 349 | SuspendCheckElimination() |
| 350 | : PassME("SuspendCheckElimination", kTopologicalSortTraversal, "6_post_sce_cfg") { |
| 351 | } |
| 352 | |
| 353 | bool Gate(const PassDataHolder* data) const { |
| 354 | DCHECK(data != nullptr); |
| 355 | CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 356 | DCHECK(c_unit != nullptr); |
| 357 | return c_unit->mir_graph->EliminateSuspendChecksGate(); |
| 358 | } |
| 359 | |
| 360 | bool Worker(PassDataHolder* data) const { |
| 361 | DCHECK(data != nullptr); |
| 362 | PassMEDataHolder* pass_me_data_holder = down_cast<PassMEDataHolder*>(data); |
| 363 | CompilationUnit* c_unit = pass_me_data_holder->c_unit; |
| 364 | DCHECK(c_unit != nullptr); |
| 365 | BasicBlock* bb = pass_me_data_holder->bb; |
| 366 | DCHECK(bb != nullptr); |
| 367 | return c_unit->mir_graph->EliminateSuspendChecks(bb); |
| 368 | } |
| 369 | |
| 370 | void End(PassDataHolder* data) const { |
| 371 | DCHECK(data != nullptr); |
| 372 | CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 373 | DCHECK(c_unit != nullptr); |
| 374 | c_unit->mir_graph->EliminateSuspendChecksEnd(); |
| 375 | } |
| 376 | }; |
| 377 | |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 378 | } // namespace art |
| 379 | |
| 380 | #endif // ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_ |