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