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 | /** |
Vladimir Marko | 7a01dc2 | 2015-01-02 17:00:44 +0000 | [diff] [blame] | 243 | * @class DeadCodeEliminationPass |
| 244 | * @brief Performs the GVN-based dead code elimination pass. |
| 245 | */ |
| 246 | class DeadCodeEliminationPass : public PassME { |
| 247 | public: |
| 248 | DeadCodeEliminationPass() : PassME("DCE", kPreOrderDFSTraversal, "4_post_dce_cfg") { |
| 249 | } |
| 250 | |
| 251 | bool Gate(const PassDataHolder* data) const OVERRIDE { |
| 252 | DCHECK(data != nullptr); |
| 253 | CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 254 | DCHECK(c_unit != nullptr); |
| 255 | return c_unit->mir_graph->EliminateDeadCodeGate(); |
| 256 | } |
| 257 | |
| 258 | bool Worker(PassDataHolder* data) const { |
| 259 | DCHECK(data != nullptr); |
| 260 | PassMEDataHolder* pass_me_data_holder = down_cast<PassMEDataHolder*>(data); |
| 261 | CompilationUnit* c_unit = pass_me_data_holder->c_unit; |
| 262 | DCHECK(c_unit != nullptr); |
| 263 | BasicBlock* bb = pass_me_data_holder->bb; |
| 264 | DCHECK(bb != nullptr); |
| 265 | return c_unit->mir_graph->EliminateDeadCode(bb); |
| 266 | } |
| 267 | |
| 268 | void End(PassDataHolder* data) const OVERRIDE { |
| 269 | DCHECK(data != nullptr); |
| 270 | CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; |
| 271 | DCHECK(c_unit != nullptr); |
| 272 | c_unit->mir_graph->EliminateDeadCodeEnd(); |
| 273 | down_cast<PassMEDataHolder*>(data)->dirty = !c_unit->mir_graph->MirSsaRepUpToDate(); |
| 274 | } |
| 275 | }; |
| 276 | |
| 277 | /** |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 278 | * @class BBCombine |
| 279 | * @brief Perform the basic block combination pass. |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 280 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 281 | class BBCombine : public PassME { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 282 | public: |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 283 | BBCombine() : PassME("BBCombine", kPreOrderDFSTraversal, "5_post_bbcombine_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 284 | } |
| 285 | |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 286 | bool Gate(const PassDataHolder* data) const { |
| 287 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 288 | CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 289 | DCHECK(c_unit != nullptr); |
Vladimir Marko | 312eb25 | 2014-10-07 15:01:57 +0100 | [diff] [blame] | 290 | return c_unit->mir_graph->HasTryCatchBlocks() || |
| 291 | ((c_unit->disable_opt & (1 << kSuppressExceptionEdges)) != 0); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 292 | } |
| 293 | |
Jean Christophe Beyler | 09321df | 2014-07-18 15:33:57 -0700 | [diff] [blame] | 294 | bool Worker(PassDataHolder* data) const; |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 295 | }; |
| 296 | |
| 297 | /** |
Vladimir Marko | 066f9e4 | 2015-01-16 16:04:43 +0000 | [diff] [blame] | 298 | * @class ConstantPropagation |
| 299 | * @brief Perform a constant propagation pass. |
| 300 | */ |
| 301 | class ConstantPropagation : public PassME { |
| 302 | public: |
| 303 | ConstantPropagation() : PassME("ConstantPropagation") { |
| 304 | } |
| 305 | |
| 306 | void Start(PassDataHolder* data) const { |
| 307 | DCHECK(data != nullptr); |
| 308 | CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; |
| 309 | DCHECK(c_unit != nullptr); |
| 310 | c_unit->mir_graph->InitializeConstantPropagation(); |
| 311 | } |
| 312 | |
| 313 | bool Worker(PassDataHolder* data) const { |
| 314 | DCHECK(data != nullptr); |
| 315 | CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; |
| 316 | DCHECK(c_unit != nullptr); |
| 317 | BasicBlock* bb = down_cast<PassMEDataHolder*>(data)->bb; |
| 318 | DCHECK(bb != nullptr); |
| 319 | c_unit->mir_graph->DoConstantPropagation(bb); |
| 320 | // No need of repeating, so just return false. |
| 321 | return false; |
| 322 | } |
| 323 | }; |
| 324 | |
| 325 | /** |
| 326 | * @class MethodUseCount |
| 327 | * @brief Count the register uses of the method |
| 328 | */ |
| 329 | class MethodUseCount : public PassME { |
| 330 | public: |
| 331 | MethodUseCount() : PassME("UseCount") { |
| 332 | } |
| 333 | |
| 334 | bool Worker(PassDataHolder* data) const; |
| 335 | |
| 336 | bool Gate(const PassDataHolder* data) const; |
| 337 | }; |
| 338 | |
| 339 | /** |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 340 | * @class BasicBlock Optimizations |
| 341 | * @brief Any simple BasicBlock optimization can be put here. |
| 342 | */ |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 343 | class BBOptimizations : public PassME { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 344 | public: |
Vladimir Marko | 341e425 | 2014-12-19 10:29:51 +0000 | [diff] [blame] | 345 | BBOptimizations() |
| 346 | : PassME("BBOptimizations", kNoNodes, kOptimizationBasicBlockChange, "5_post_bbo_cfg") { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 347 | } |
| 348 | |
James C Scott | 4f59668 | 2014-05-01 05:52:04 -0700 | [diff] [blame] | 349 | bool Gate(const PassDataHolder* data) const { |
| 350 | DCHECK(data != nullptr); |
Jean Christophe Beyler | 75bcc37 | 2014-09-04 08:15:11 -0700 | [diff] [blame] | 351 | CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 352 | DCHECK(c_unit != nullptr); |
| 353 | return ((c_unit->disable_opt & (1 << kBBOpt)) == 0); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 354 | } |
| 355 | |
Vladimir Marko | ffda499 | 2014-12-18 17:05:58 +0000 | [diff] [blame] | 356 | void Start(PassDataHolder* data) const { |
| 357 | DCHECK(data != nullptr); |
| 358 | CompilationUnit* c_unit = down_cast<PassMEDataHolder*>(data)->c_unit; |
| 359 | DCHECK(c_unit != nullptr); |
| 360 | c_unit->mir_graph->BasicBlockOptimizationStart(); |
| 361 | |
| 362 | /* |
| 363 | * This pass has a different ordering depending on the suppress exception, |
| 364 | * so do the pass here for now: |
| 365 | * - Later, the Start should just change the ordering and we can move the extended |
| 366 | * creation into the pass driver's main job with a new iterator |
| 367 | */ |
| 368 | c_unit->mir_graph->BasicBlockOptimization(); |
| 369 | } |
| 370 | |
| 371 | void End(PassDataHolder* data) const { |
| 372 | DCHECK(data != nullptr); |
| 373 | CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 374 | DCHECK(c_unit != nullptr); |
| 375 | c_unit->mir_graph->BasicBlockOptimizationEnd(); |
Vladimir Marko | 341e425 | 2014-12-19 10:29:51 +0000 | [diff] [blame] | 376 | down_cast<PassMEDataHolder*>(data)->dirty = !c_unit->mir_graph->DfsOrdersUpToDate(); |
Vladimir Marko | ffda499 | 2014-12-18 17:05:58 +0000 | [diff] [blame] | 377 | } |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 378 | }; |
| 379 | |
Vladimir Marko | 8b858e1 | 2014-11-27 14:52:37 +0000 | [diff] [blame] | 380 | /** |
| 381 | * @class SuspendCheckElimination |
| 382 | * @brief Any simple BasicBlock optimization can be put here. |
| 383 | */ |
| 384 | class SuspendCheckElimination : public PassME { |
| 385 | public: |
| 386 | SuspendCheckElimination() |
| 387 | : PassME("SuspendCheckElimination", kTopologicalSortTraversal, "6_post_sce_cfg") { |
| 388 | } |
| 389 | |
| 390 | bool Gate(const PassDataHolder* data) const { |
| 391 | DCHECK(data != nullptr); |
| 392 | CompilationUnit* c_unit = down_cast<const PassMEDataHolder*>(data)->c_unit; |
| 393 | DCHECK(c_unit != nullptr); |
| 394 | return c_unit->mir_graph->EliminateSuspendChecksGate(); |
| 395 | } |
| 396 | |
| 397 | bool Worker(PassDataHolder* data) const { |
| 398 | DCHECK(data != nullptr); |
| 399 | PassMEDataHolder* pass_me_data_holder = down_cast<PassMEDataHolder*>(data); |
| 400 | CompilationUnit* c_unit = pass_me_data_holder->c_unit; |
| 401 | DCHECK(c_unit != nullptr); |
| 402 | BasicBlock* bb = pass_me_data_holder->bb; |
| 403 | DCHECK(bb != nullptr); |
| 404 | return c_unit->mir_graph->EliminateSuspendChecks(bb); |
| 405 | } |
Vladimir Marko | 8b858e1 | 2014-11-27 14:52:37 +0000 | [diff] [blame] | 406 | }; |
| 407 | |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 408 | } // namespace art |
| 409 | |
| 410 | #endif // ART_COMPILER_DEX_BB_OPTIMIZATIONS_H_ |