buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | #include "compiler_internals.h" |
| 18 | #include "local_value_numbering.h" |
Ian Rogers | 8d3a117 | 2013-06-04 01:13:28 -0700 | [diff] [blame] | 19 | #include "dataflow_iterator-inl.h" |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 20 | |
| 21 | namespace art { |
| 22 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 23 | static unsigned int Predecessors(BasicBlock* bb) { |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 24 | return bb->predecessors->Size(); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | /* Setup a constant value for opcodes thare have the DF_SETS_CONST attribute */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 28 | void MIRGraph::SetConstant(int32_t ssa_reg, int value) { |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 29 | is_constant_v_->SetBit(ssa_reg); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 30 | constant_values_[ssa_reg] = value; |
| 31 | } |
| 32 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 33 | void MIRGraph::SetConstantWide(int ssa_reg, int64_t value) { |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 34 | is_constant_v_->SetBit(ssa_reg); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 35 | constant_values_[ssa_reg] = Low32Bits(value); |
| 36 | constant_values_[ssa_reg + 1] = High32Bits(value); |
| 37 | } |
| 38 | |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 39 | void MIRGraph::DoConstantPropagation(BasicBlock* bb) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 40 | MIR* mir; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 41 | |
| 42 | for (mir = bb->first_mir_insn; mir != NULL; mir = mir->next) { |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 43 | uint64_t df_attributes = oat_data_flow_attributes_[mir->dalvikInsn.opcode]; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 44 | |
| 45 | DecodedInstruction *d_insn = &mir->dalvikInsn; |
| 46 | |
| 47 | if (!(df_attributes & DF_HAS_DEFS)) continue; |
| 48 | |
| 49 | /* Handle instructions that set up constants directly */ |
| 50 | if (df_attributes & DF_SETS_CONST) { |
| 51 | if (df_attributes & DF_DA) { |
| 52 | int32_t vB = static_cast<int32_t>(d_insn->vB); |
| 53 | switch (d_insn->opcode) { |
| 54 | case Instruction::CONST_4: |
| 55 | case Instruction::CONST_16: |
| 56 | case Instruction::CONST: |
| 57 | SetConstant(mir->ssa_rep->defs[0], vB); |
| 58 | break; |
| 59 | case Instruction::CONST_HIGH16: |
| 60 | SetConstant(mir->ssa_rep->defs[0], vB << 16); |
| 61 | break; |
| 62 | case Instruction::CONST_WIDE_16: |
| 63 | case Instruction::CONST_WIDE_32: |
| 64 | SetConstantWide(mir->ssa_rep->defs[0], static_cast<int64_t>(vB)); |
| 65 | break; |
| 66 | case Instruction::CONST_WIDE: |
Brian Carlstrom | b1eba21 | 2013-07-17 18:07:19 -0700 | [diff] [blame] | 67 | SetConstantWide(mir->ssa_rep->defs[0], d_insn->vB_wide); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 68 | break; |
| 69 | case Instruction::CONST_WIDE_HIGH16: |
| 70 | SetConstantWide(mir->ssa_rep->defs[0], static_cast<int64_t>(vB) << 48); |
| 71 | break; |
| 72 | default: |
| 73 | break; |
| 74 | } |
| 75 | } |
| 76 | /* Handle instructions that set up constants directly */ |
| 77 | } else if (df_attributes & DF_IS_MOVE) { |
| 78 | int i; |
| 79 | |
| 80 | for (i = 0; i < mir->ssa_rep->num_uses; i++) { |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 81 | if (!is_constant_v_->IsBitSet(mir->ssa_rep->uses[i])) break; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 82 | } |
| 83 | /* Move a register holding a constant to another register */ |
| 84 | if (i == mir->ssa_rep->num_uses) { |
| 85 | SetConstant(mir->ssa_rep->defs[0], constant_values_[mir->ssa_rep->uses[0]]); |
| 86 | if (df_attributes & DF_A_WIDE) { |
| 87 | SetConstant(mir->ssa_rep->defs[1], constant_values_[mir->ssa_rep->uses[1]]); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | /* TODO: implement code to handle arithmetic operations */ |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 93 | } |
| 94 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 95 | /* Advance to next strictly dominated MIR node in an extended basic block */ |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 96 | MIR* MIRGraph::AdvanceMIR(BasicBlock** p_bb, MIR* mir) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 97 | BasicBlock* bb = *p_bb; |
| 98 | if (mir != NULL) { |
| 99 | mir = mir->next; |
| 100 | if (mir == NULL) { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 101 | bb = GetBasicBlock(bb->fall_through); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 102 | if ((bb == NULL) || Predecessors(bb) != 1) { |
| 103 | mir = NULL; |
| 104 | } else { |
| 105 | *p_bb = bb; |
| 106 | mir = bb->first_mir_insn; |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | return mir; |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | * To be used at an invoke mir. If the logically next mir node represents |
| 115 | * a move-result, return it. Else, return NULL. If a move-result exists, |
| 116 | * it is required to immediately follow the invoke with no intervening |
| 117 | * opcodes or incoming arcs. However, if the result of the invoke is not |
| 118 | * used, a move-result may not be present. |
| 119 | */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 120 | MIR* MIRGraph::FindMoveResult(BasicBlock* bb, MIR* mir) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 121 | BasicBlock* tbb = bb; |
| 122 | mir = AdvanceMIR(&tbb, mir); |
| 123 | while (mir != NULL) { |
| 124 | int opcode = mir->dalvikInsn.opcode; |
| 125 | if ((mir->dalvikInsn.opcode == Instruction::MOVE_RESULT) || |
| 126 | (mir->dalvikInsn.opcode == Instruction::MOVE_RESULT_OBJECT) || |
| 127 | (mir->dalvikInsn.opcode == Instruction::MOVE_RESULT_WIDE)) { |
| 128 | break; |
| 129 | } |
| 130 | // Keep going if pseudo op, otherwise terminate |
| 131 | if (opcode < kNumPackedOpcodes) { |
| 132 | mir = NULL; |
| 133 | } else { |
| 134 | mir = AdvanceMIR(&tbb, mir); |
| 135 | } |
| 136 | } |
| 137 | return mir; |
| 138 | } |
| 139 | |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 140 | BasicBlock* MIRGraph::NextDominatedBlock(BasicBlock* bb) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 141 | if (bb->block_type == kDead) { |
| 142 | return NULL; |
| 143 | } |
| 144 | DCHECK((bb->block_type == kEntryBlock) || (bb->block_type == kDalvikByteCode) |
| 145 | || (bb->block_type == kExitBlock)); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 146 | BasicBlock* bb_taken = GetBasicBlock(bb->taken); |
| 147 | BasicBlock* bb_fall_through = GetBasicBlock(bb->fall_through); |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 148 | if (((bb_fall_through == NULL) && (bb_taken != NULL)) && |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 149 | ((bb_taken->block_type == kDalvikByteCode) || (bb_taken->block_type == kExitBlock))) { |
buzbee | cbcfaf3 | 2013-08-19 07:37:40 -0700 | [diff] [blame] | 150 | // Follow simple unconditional branches. |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 151 | bb = bb_taken; |
buzbee | cbcfaf3 | 2013-08-19 07:37:40 -0700 | [diff] [blame] | 152 | } else { |
| 153 | // Follow simple fallthrough |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 154 | bb = (bb_taken != NULL) ? NULL : bb_fall_through; |
buzbee | cbcfaf3 | 2013-08-19 07:37:40 -0700 | [diff] [blame] | 155 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 156 | if (bb == NULL || (Predecessors(bb) != 1)) { |
| 157 | return NULL; |
| 158 | } |
| 159 | DCHECK((bb->block_type == kDalvikByteCode) || (bb->block_type == kExitBlock)); |
| 160 | return bb; |
| 161 | } |
| 162 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 163 | static MIR* FindPhi(BasicBlock* bb, int ssa_name) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 164 | for (MIR* mir = bb->first_mir_insn; mir != NULL; mir = mir->next) { |
| 165 | if (static_cast<int>(mir->dalvikInsn.opcode) == kMirOpPhi) { |
| 166 | for (int i = 0; i < mir->ssa_rep->num_uses; i++) { |
| 167 | if (mir->ssa_rep->uses[i] == ssa_name) { |
| 168 | return mir; |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | return NULL; |
| 174 | } |
| 175 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 176 | static SelectInstructionKind SelectKind(MIR* mir) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 177 | switch (mir->dalvikInsn.opcode) { |
| 178 | case Instruction::MOVE: |
| 179 | case Instruction::MOVE_OBJECT: |
| 180 | case Instruction::MOVE_16: |
| 181 | case Instruction::MOVE_OBJECT_16: |
| 182 | case Instruction::MOVE_FROM16: |
| 183 | case Instruction::MOVE_OBJECT_FROM16: |
| 184 | return kSelectMove; |
Brian Carlstrom | 6f485c6 | 2013-07-18 15:35:35 -0700 | [diff] [blame] | 185 | case Instruction::CONST: |
| 186 | case Instruction::CONST_4: |
| 187 | case Instruction::CONST_16: |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 188 | return kSelectConst; |
Brian Carlstrom | 6f485c6 | 2013-07-18 15:35:35 -0700 | [diff] [blame] | 189 | case Instruction::GOTO: |
| 190 | case Instruction::GOTO_16: |
| 191 | case Instruction::GOTO_32: |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 192 | return kSelectGoto; |
Brian Carlstrom | 02c8cc6 | 2013-07-18 15:54:44 -0700 | [diff] [blame] | 193 | default: |
| 194 | return kSelectNone; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 195 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Vladimir Marko | a1a7074 | 2014-03-03 10:28:05 +0000 | [diff] [blame] | 198 | static constexpr ConditionCode kIfCcZConditionCodes[] = { |
| 199 | kCondEq, kCondNe, kCondLt, kCondGe, kCondGt, kCondLe |
| 200 | }; |
| 201 | |
| 202 | COMPILE_ASSERT(arraysize(kIfCcZConditionCodes) == Instruction::IF_LEZ - Instruction::IF_EQZ + 1, |
| 203 | if_ccz_ccodes_size1); |
| 204 | |
| 205 | static constexpr bool IsInstructionIfCcZ(Instruction::Code opcode) { |
| 206 | return Instruction::IF_EQZ <= opcode && opcode <= Instruction::IF_LEZ; |
| 207 | } |
| 208 | |
| 209 | static constexpr ConditionCode ConditionCodeForIfCcZ(Instruction::Code opcode) { |
| 210 | return kIfCcZConditionCodes[opcode - Instruction::IF_EQZ]; |
| 211 | } |
| 212 | |
| 213 | COMPILE_ASSERT(ConditionCodeForIfCcZ(Instruction::IF_EQZ) == kCondEq, check_if_eqz_ccode); |
| 214 | COMPILE_ASSERT(ConditionCodeForIfCcZ(Instruction::IF_NEZ) == kCondNe, check_if_nez_ccode); |
| 215 | COMPILE_ASSERT(ConditionCodeForIfCcZ(Instruction::IF_LTZ) == kCondLt, check_if_ltz_ccode); |
| 216 | COMPILE_ASSERT(ConditionCodeForIfCcZ(Instruction::IF_GEZ) == kCondGe, check_if_gez_ccode); |
| 217 | COMPILE_ASSERT(ConditionCodeForIfCcZ(Instruction::IF_GTZ) == kCondGt, check_if_gtz_ccode); |
| 218 | COMPILE_ASSERT(ConditionCodeForIfCcZ(Instruction::IF_LEZ) == kCondLe, check_if_lez_ccode); |
| 219 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 220 | int MIRGraph::GetSSAUseCount(int s_reg) { |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 221 | return raw_use_counts_.Get(s_reg); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 222 | } |
| 223 | |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 224 | size_t MIRGraph::GetNumAvailableNonSpecialCompilerTemps() { |
| 225 | if (num_non_special_compiler_temps_ >= max_available_non_special_compiler_temps_) { |
| 226 | return 0; |
| 227 | } else { |
| 228 | return max_available_non_special_compiler_temps_ - num_non_special_compiler_temps_; |
| 229 | } |
| 230 | } |
| 231 | |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 232 | |
| 233 | // FIXME - will probably need to revisit all uses of this, as type not defined. |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 234 | static const RegLocation temp_loc = {kLocCompilerTemp, |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 235 | 0, 1 /*defined*/, 0, 0, 0, 0, 0, 1 /*home*/, kVectorNotUsed, |
| 236 | RegStorage(), INVALID_SREG, INVALID_SREG}; |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 237 | |
| 238 | CompilerTemp* MIRGraph::GetNewCompilerTemp(CompilerTempType ct_type, bool wide) { |
| 239 | // There is a limit to the number of non-special temps so check to make sure it wasn't exceeded. |
| 240 | if (ct_type == kCompilerTempVR) { |
| 241 | size_t available_temps = GetNumAvailableNonSpecialCompilerTemps(); |
| 242 | if (available_temps <= 0 || (available_temps <= 1 && wide)) { |
| 243 | return 0; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | CompilerTemp *compiler_temp = static_cast<CompilerTemp *>(arena_->Alloc(sizeof(CompilerTemp), |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 248 | kArenaAllocRegAlloc)); |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 249 | |
| 250 | // Create the type of temp requested. Special temps need special handling because |
| 251 | // they have a specific virtual register assignment. |
| 252 | if (ct_type == kCompilerTempSpecialMethodPtr) { |
| 253 | DCHECK_EQ(wide, false); |
| 254 | compiler_temp->v_reg = static_cast<int>(kVRegMethodPtrBaseReg); |
| 255 | compiler_temp->s_reg_low = AddNewSReg(compiler_temp->v_reg); |
| 256 | |
| 257 | // The MIR graph keeps track of the sreg for method pointer specially, so record that now. |
| 258 | method_sreg_ = compiler_temp->s_reg_low; |
| 259 | } else { |
| 260 | DCHECK_EQ(ct_type, kCompilerTempVR); |
| 261 | |
| 262 | // The new non-special compiler temp must receive a unique v_reg with a negative value. |
| 263 | compiler_temp->v_reg = static_cast<int>(kVRegNonSpecialTempBaseReg) - num_non_special_compiler_temps_; |
| 264 | compiler_temp->s_reg_low = AddNewSReg(compiler_temp->v_reg); |
| 265 | num_non_special_compiler_temps_++; |
| 266 | |
| 267 | if (wide) { |
| 268 | // Ensure that the two registers are consecutive. Since the virtual registers used for temps grow in a |
| 269 | // negative fashion, we need the smaller to refer to the low part. Thus, we redefine the v_reg and s_reg_low. |
| 270 | compiler_temp->v_reg--; |
| 271 | int ssa_reg_high = compiler_temp->s_reg_low; |
| 272 | compiler_temp->s_reg_low = AddNewSReg(compiler_temp->v_reg); |
| 273 | int ssa_reg_low = compiler_temp->s_reg_low; |
| 274 | |
| 275 | // If needed initialize the register location for the high part. |
| 276 | // The low part is handled later in this method on a common path. |
| 277 | if (reg_location_ != nullptr) { |
| 278 | reg_location_[ssa_reg_high] = temp_loc; |
| 279 | reg_location_[ssa_reg_high].high_word = 1; |
| 280 | reg_location_[ssa_reg_high].s_reg_low = ssa_reg_low; |
| 281 | reg_location_[ssa_reg_high].wide = true; |
| 282 | |
| 283 | // A new SSA needs new use counts. |
| 284 | use_counts_.Insert(0); |
| 285 | raw_use_counts_.Insert(0); |
| 286 | } |
| 287 | |
| 288 | num_non_special_compiler_temps_++; |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | // Have we already allocated the register locations? |
| 293 | if (reg_location_ != nullptr) { |
| 294 | int ssa_reg_low = compiler_temp->s_reg_low; |
| 295 | reg_location_[ssa_reg_low] = temp_loc; |
| 296 | reg_location_[ssa_reg_low].s_reg_low = ssa_reg_low; |
| 297 | reg_location_[ssa_reg_low].wide = wide; |
| 298 | |
| 299 | // A new SSA needs new use counts. |
| 300 | use_counts_.Insert(0); |
| 301 | raw_use_counts_.Insert(0); |
| 302 | } |
| 303 | |
| 304 | compiler_temps_.Insert(compiler_temp); |
| 305 | return compiler_temp; |
| 306 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 307 | |
| 308 | /* Do some MIR-level extended basic block optimizations */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 309 | bool MIRGraph::BasicBlockOpt(BasicBlock* bb) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 310 | if (bb->block_type == kDead) { |
| 311 | return true; |
| 312 | } |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 313 | bool use_lvn = bb->use_lvn; |
| 314 | UniquePtr<LocalValueNumbering> local_valnum; |
| 315 | if (use_lvn) { |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 316 | local_valnum.reset(LocalValueNumbering::Create(cu_)); |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 317 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 318 | while (bb != NULL) { |
| 319 | for (MIR* mir = bb->first_mir_insn; mir != NULL; mir = mir->next) { |
| 320 | // TUNING: use the returned value number for CSE. |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 321 | if (use_lvn) { |
| 322 | local_valnum->GetValueNumber(mir); |
| 323 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 324 | // Look for interesting opcodes, skip otherwise |
| 325 | Instruction::Code opcode = mir->dalvikInsn.opcode; |
| 326 | switch (opcode) { |
| 327 | case Instruction::CMPL_FLOAT: |
| 328 | case Instruction::CMPL_DOUBLE: |
| 329 | case Instruction::CMPG_FLOAT: |
| 330 | case Instruction::CMPG_DOUBLE: |
| 331 | case Instruction::CMP_LONG: |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 332 | if ((cu_->disable_opt & (1 << kBranchFusing)) != 0) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 333 | // Bitcode doesn't allow this optimization. |
| 334 | break; |
| 335 | } |
| 336 | if (mir->next != NULL) { |
| 337 | MIR* mir_next = mir->next; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 338 | // Make sure result of cmp is used by next insn and nowhere else |
Vladimir Marko | a1a7074 | 2014-03-03 10:28:05 +0000 | [diff] [blame] | 339 | if (IsInstructionIfCcZ(mir->next->dalvikInsn.opcode) && |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 340 | (mir->ssa_rep->defs[0] == mir_next->ssa_rep->uses[0]) && |
| 341 | (GetSSAUseCount(mir->ssa_rep->defs[0]) == 1)) { |
Vladimir Marko | a1a7074 | 2014-03-03 10:28:05 +0000 | [diff] [blame] | 342 | mir_next->meta.ccode = ConditionCodeForIfCcZ(mir_next->dalvikInsn.opcode); |
Brian Carlstrom | df62950 | 2013-07-17 22:39:56 -0700 | [diff] [blame] | 343 | switch (opcode) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 344 | case Instruction::CMPL_FLOAT: |
| 345 | mir_next->dalvikInsn.opcode = |
| 346 | static_cast<Instruction::Code>(kMirOpFusedCmplFloat); |
| 347 | break; |
| 348 | case Instruction::CMPL_DOUBLE: |
| 349 | mir_next->dalvikInsn.opcode = |
| 350 | static_cast<Instruction::Code>(kMirOpFusedCmplDouble); |
| 351 | break; |
| 352 | case Instruction::CMPG_FLOAT: |
| 353 | mir_next->dalvikInsn.opcode = |
| 354 | static_cast<Instruction::Code>(kMirOpFusedCmpgFloat); |
| 355 | break; |
| 356 | case Instruction::CMPG_DOUBLE: |
| 357 | mir_next->dalvikInsn.opcode = |
| 358 | static_cast<Instruction::Code>(kMirOpFusedCmpgDouble); |
| 359 | break; |
| 360 | case Instruction::CMP_LONG: |
| 361 | mir_next->dalvikInsn.opcode = |
| 362 | static_cast<Instruction::Code>(kMirOpFusedCmpLong); |
| 363 | break; |
| 364 | default: LOG(ERROR) << "Unexpected opcode: " << opcode; |
| 365 | } |
| 366 | mir->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpNop); |
| 367 | mir_next->ssa_rep->num_uses = mir->ssa_rep->num_uses; |
| 368 | mir_next->ssa_rep->uses = mir->ssa_rep->uses; |
| 369 | mir_next->ssa_rep->fp_use = mir->ssa_rep->fp_use; |
| 370 | mir_next->ssa_rep->num_defs = 0; |
| 371 | mir->ssa_rep->num_uses = 0; |
| 372 | mir->ssa_rep->num_defs = 0; |
| 373 | } |
| 374 | } |
| 375 | break; |
| 376 | case Instruction::GOTO: |
| 377 | case Instruction::GOTO_16: |
| 378 | case Instruction::GOTO_32: |
| 379 | case Instruction::IF_EQ: |
| 380 | case Instruction::IF_NE: |
| 381 | case Instruction::IF_LT: |
| 382 | case Instruction::IF_GE: |
| 383 | case Instruction::IF_GT: |
| 384 | case Instruction::IF_LE: |
| 385 | case Instruction::IF_EQZ: |
| 386 | case Instruction::IF_NEZ: |
| 387 | case Instruction::IF_LTZ: |
| 388 | case Instruction::IF_GEZ: |
| 389 | case Instruction::IF_GTZ: |
| 390 | case Instruction::IF_LEZ: |
buzbee | cbcfaf3 | 2013-08-19 07:37:40 -0700 | [diff] [blame] | 391 | // If we've got a backwards branch to return, no need to suspend check. |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 392 | if ((IsBackedge(bb, bb->taken) && GetBasicBlock(bb->taken)->dominates_return) || |
| 393 | (IsBackedge(bb, bb->fall_through) && |
| 394 | GetBasicBlock(bb->fall_through)->dominates_return)) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 395 | mir->optimization_flags |= MIR_IGNORE_SUSPEND_CHECK; |
| 396 | if (cu_->verbose) { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 397 | LOG(INFO) << "Suppressed suspend check on branch to return at 0x" << std::hex |
| 398 | << mir->offset; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | break; |
| 402 | default: |
| 403 | break; |
| 404 | } |
| 405 | // Is this the select pattern? |
Razvan A Lupusoru | e27b3bf | 2014-01-23 09:41:45 -0800 | [diff] [blame] | 406 | // TODO: flesh out support for Mips. NOTE: llvm's select op doesn't quite work here. |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 407 | // TUNING: expand to support IF_xx compare & branches |
Nicolas Geoffray | a36aeb3 | 2014-02-25 11:04:13 +0000 | [diff] [blame] | 408 | if (!cu_->compiler_backend->IsPortable() && |
Razvan A Lupusoru | e27b3bf | 2014-01-23 09:41:45 -0800 | [diff] [blame] | 409 | (cu_->instruction_set == kThumb2 || cu_->instruction_set == kX86) && |
Vladimir Marko | a1a7074 | 2014-03-03 10:28:05 +0000 | [diff] [blame] | 410 | IsInstructionIfCcZ(mir->dalvikInsn.opcode)) { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 411 | BasicBlock* ft = GetBasicBlock(bb->fall_through); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 412 | DCHECK(ft != NULL); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 413 | BasicBlock* ft_ft = GetBasicBlock(ft->fall_through); |
| 414 | BasicBlock* ft_tk = GetBasicBlock(ft->taken); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 415 | |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 416 | BasicBlock* tk = GetBasicBlock(bb->taken); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 417 | DCHECK(tk != NULL); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 418 | BasicBlock* tk_ft = GetBasicBlock(tk->fall_through); |
| 419 | BasicBlock* tk_tk = GetBasicBlock(tk->taken); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 420 | |
| 421 | /* |
| 422 | * In the select pattern, the taken edge goes to a block that unconditionally |
| 423 | * transfers to the rejoin block and the fall_though edge goes to a block that |
| 424 | * unconditionally falls through to the rejoin block. |
| 425 | */ |
| 426 | if ((tk_ft == NULL) && (ft_tk == NULL) && (tk_tk == ft_ft) && |
| 427 | (Predecessors(tk) == 1) && (Predecessors(ft) == 1)) { |
| 428 | /* |
| 429 | * Okay - we have the basic diamond shape. At the very least, we can eliminate the |
| 430 | * suspend check on the taken-taken branch back to the join point. |
| 431 | */ |
| 432 | if (SelectKind(tk->last_mir_insn) == kSelectGoto) { |
| 433 | tk->last_mir_insn->optimization_flags |= (MIR_IGNORE_SUSPEND_CHECK); |
| 434 | } |
| 435 | // Are the block bodies something we can handle? |
| 436 | if ((ft->first_mir_insn == ft->last_mir_insn) && |
| 437 | (tk->first_mir_insn != tk->last_mir_insn) && |
| 438 | (tk->first_mir_insn->next == tk->last_mir_insn) && |
| 439 | ((SelectKind(ft->first_mir_insn) == kSelectMove) || |
| 440 | (SelectKind(ft->first_mir_insn) == kSelectConst)) && |
| 441 | (SelectKind(ft->first_mir_insn) == SelectKind(tk->first_mir_insn)) && |
| 442 | (SelectKind(tk->last_mir_insn) == kSelectGoto)) { |
| 443 | // Almost there. Are the instructions targeting the same vreg? |
| 444 | MIR* if_true = tk->first_mir_insn; |
| 445 | MIR* if_false = ft->first_mir_insn; |
| 446 | // It's possible that the target of the select isn't used - skip those (rare) cases. |
| 447 | MIR* phi = FindPhi(tk_tk, if_true->ssa_rep->defs[0]); |
| 448 | if ((phi != NULL) && (if_true->dalvikInsn.vA == if_false->dalvikInsn.vA)) { |
| 449 | /* |
| 450 | * We'll convert the IF_EQZ/IF_NEZ to a SELECT. We need to find the |
| 451 | * Phi node in the merge block and delete it (while using the SSA name |
| 452 | * of the merge as the target of the SELECT. Delete both taken and |
| 453 | * fallthrough blocks, and set fallthrough to merge block. |
| 454 | * NOTE: not updating other dataflow info (no longer used at this point). |
| 455 | * If this changes, need to update i_dom, etc. here (and in CombineBlocks). |
| 456 | */ |
Vladimir Marko | a1a7074 | 2014-03-03 10:28:05 +0000 | [diff] [blame] | 457 | mir->meta.ccode = ConditionCodeForIfCcZ(mir->dalvikInsn.opcode); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 458 | mir->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpSelect); |
| 459 | bool const_form = (SelectKind(if_true) == kSelectConst); |
| 460 | if ((SelectKind(if_true) == kSelectMove)) { |
| 461 | if (IsConst(if_true->ssa_rep->uses[0]) && |
| 462 | IsConst(if_false->ssa_rep->uses[0])) { |
| 463 | const_form = true; |
| 464 | if_true->dalvikInsn.vB = ConstantValue(if_true->ssa_rep->uses[0]); |
| 465 | if_false->dalvikInsn.vB = ConstantValue(if_false->ssa_rep->uses[0]); |
| 466 | } |
| 467 | } |
| 468 | if (const_form) { |
Razvan A Lupusoru | e27b3bf | 2014-01-23 09:41:45 -0800 | [diff] [blame] | 469 | /* |
| 470 | * TODO: If both constants are the same value, then instead of generating |
| 471 | * a select, we should simply generate a const bytecode. This should be |
| 472 | * considered after inlining which can lead to CFG of this form. |
| 473 | */ |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 474 | // "true" set val in vB |
| 475 | mir->dalvikInsn.vB = if_true->dalvikInsn.vB; |
| 476 | // "false" set val in vC |
| 477 | mir->dalvikInsn.vC = if_false->dalvikInsn.vB; |
| 478 | } else { |
| 479 | DCHECK_EQ(SelectKind(if_true), kSelectMove); |
| 480 | DCHECK_EQ(SelectKind(if_false), kSelectMove); |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 481 | int* src_ssa = |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 482 | static_cast<int*>(arena_->Alloc(sizeof(int) * 3, kArenaAllocDFInfo)); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 483 | src_ssa[0] = mir->ssa_rep->uses[0]; |
| 484 | src_ssa[1] = if_true->ssa_rep->uses[0]; |
| 485 | src_ssa[2] = if_false->ssa_rep->uses[0]; |
| 486 | mir->ssa_rep->uses = src_ssa; |
| 487 | mir->ssa_rep->num_uses = 3; |
| 488 | } |
| 489 | mir->ssa_rep->num_defs = 1; |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 490 | mir->ssa_rep->defs = |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 491 | static_cast<int*>(arena_->Alloc(sizeof(int) * 1, kArenaAllocDFInfo)); |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 492 | mir->ssa_rep->fp_def = |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 493 | static_cast<bool*>(arena_->Alloc(sizeof(bool) * 1, kArenaAllocDFInfo)); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 494 | mir->ssa_rep->fp_def[0] = if_true->ssa_rep->fp_def[0]; |
buzbee | 817e45a | 2013-05-30 18:59:12 -0700 | [diff] [blame] | 495 | // Match type of uses to def. |
| 496 | mir->ssa_rep->fp_use = |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 497 | static_cast<bool*>(arena_->Alloc(sizeof(bool) * mir->ssa_rep->num_uses, |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 498 | kArenaAllocDFInfo)); |
buzbee | 817e45a | 2013-05-30 18:59:12 -0700 | [diff] [blame] | 499 | for (int i = 0; i < mir->ssa_rep->num_uses; i++) { |
| 500 | mir->ssa_rep->fp_use[i] = mir->ssa_rep->fp_def[0]; |
| 501 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 502 | /* |
| 503 | * There is usually a Phi node in the join block for our two cases. If the |
| 504 | * Phi node only contains our two cases as input, we will use the result |
| 505 | * SSA name of the Phi node as our select result and delete the Phi. If |
| 506 | * the Phi node has more than two operands, we will arbitrarily use the SSA |
| 507 | * name of the "true" path, delete the SSA name of the "false" path from the |
| 508 | * Phi node (and fix up the incoming arc list). |
| 509 | */ |
| 510 | if (phi->ssa_rep->num_uses == 2) { |
| 511 | mir->ssa_rep->defs[0] = phi->ssa_rep->defs[0]; |
| 512 | phi->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpNop); |
| 513 | } else { |
| 514 | int dead_def = if_false->ssa_rep->defs[0]; |
| 515 | int live_def = if_true->ssa_rep->defs[0]; |
| 516 | mir->ssa_rep->defs[0] = live_def; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 517 | BasicBlockId* incoming = phi->meta.phi_incoming; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 518 | for (int i = 0; i < phi->ssa_rep->num_uses; i++) { |
| 519 | if (phi->ssa_rep->uses[i] == live_def) { |
| 520 | incoming[i] = bb->id; |
| 521 | } |
| 522 | } |
| 523 | for (int i = 0; i < phi->ssa_rep->num_uses; i++) { |
| 524 | if (phi->ssa_rep->uses[i] == dead_def) { |
| 525 | int last_slot = phi->ssa_rep->num_uses - 1; |
| 526 | phi->ssa_rep->uses[i] = phi->ssa_rep->uses[last_slot]; |
| 527 | incoming[i] = incoming[last_slot]; |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | phi->ssa_rep->num_uses--; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 532 | bb->taken = NullBasicBlockId; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 533 | tk->block_type = kDead; |
| 534 | for (MIR* tmir = ft->first_mir_insn; tmir != NULL; tmir = tmir->next) { |
| 535 | tmir->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpNop); |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | } |
| 540 | } |
| 541 | } |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 542 | bb = ((cu_->disable_opt & (1 << kSuppressExceptionEdges)) != 0) ? NextDominatedBlock(bb) : NULL; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 543 | } |
| 544 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 545 | return true; |
| 546 | } |
| 547 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 548 | void MIRGraph::NullCheckEliminationInit(struct BasicBlock* bb) { |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 549 | if (bb->data_flow_info != NULL) { |
| 550 | bb->data_flow_info->ending_null_check_v = |
| 551 | new (arena_) ArenaBitVector(arena_, GetNumSSARegs(), false, kBitMapNullCheck); |
| 552 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | /* Collect stats on number of checks removed */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 556 | void MIRGraph::CountChecks(struct BasicBlock* bb) { |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 557 | if (bb->data_flow_info != NULL) { |
| 558 | for (MIR* mir = bb->first_mir_insn; mir != NULL; mir = mir->next) { |
| 559 | if (mir->ssa_rep == NULL) { |
| 560 | continue; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 561 | } |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 562 | uint64_t df_attributes = oat_data_flow_attributes_[mir->dalvikInsn.opcode]; |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 563 | if (df_attributes & DF_HAS_NULL_CHKS) { |
| 564 | checkstats_->null_checks++; |
| 565 | if (mir->optimization_flags & MIR_IGNORE_NULL_CHECK) { |
| 566 | checkstats_->null_checks_eliminated++; |
| 567 | } |
| 568 | } |
| 569 | if (df_attributes & DF_HAS_RANGE_CHKS) { |
| 570 | checkstats_->range_checks++; |
| 571 | if (mir->optimization_flags & MIR_IGNORE_RANGE_CHECK) { |
| 572 | checkstats_->range_checks_eliminated++; |
| 573 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | /* Try to make common case the fallthrough path */ |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 580 | bool MIRGraph::LayoutBlocks(BasicBlock* bb) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 581 | // TODO: For now, just looking for direct throws. Consider generalizing for profile feedback |
| 582 | if (!bb->explicit_throw) { |
| 583 | return false; |
| 584 | } |
| 585 | BasicBlock* walker = bb; |
| 586 | while (true) { |
| 587 | // Check termination conditions |
| 588 | if ((walker->block_type == kEntryBlock) || (Predecessors(walker) != 1)) { |
| 589 | break; |
| 590 | } |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 591 | BasicBlock* prev = GetBasicBlock(walker->predecessors->Get(0)); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 592 | if (prev->conditional_branch) { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 593 | if (GetBasicBlock(prev->fall_through) == walker) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 594 | // Already done - return |
| 595 | break; |
| 596 | } |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 597 | DCHECK_EQ(walker, GetBasicBlock(prev->taken)); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 598 | // Got one. Flip it and exit |
| 599 | Instruction::Code opcode = prev->last_mir_insn->dalvikInsn.opcode; |
| 600 | switch (opcode) { |
| 601 | case Instruction::IF_EQ: opcode = Instruction::IF_NE; break; |
| 602 | case Instruction::IF_NE: opcode = Instruction::IF_EQ; break; |
| 603 | case Instruction::IF_LT: opcode = Instruction::IF_GE; break; |
| 604 | case Instruction::IF_GE: opcode = Instruction::IF_LT; break; |
| 605 | case Instruction::IF_GT: opcode = Instruction::IF_LE; break; |
| 606 | case Instruction::IF_LE: opcode = Instruction::IF_GT; break; |
| 607 | case Instruction::IF_EQZ: opcode = Instruction::IF_NEZ; break; |
| 608 | case Instruction::IF_NEZ: opcode = Instruction::IF_EQZ; break; |
| 609 | case Instruction::IF_LTZ: opcode = Instruction::IF_GEZ; break; |
| 610 | case Instruction::IF_GEZ: opcode = Instruction::IF_LTZ; break; |
| 611 | case Instruction::IF_GTZ: opcode = Instruction::IF_LEZ; break; |
| 612 | case Instruction::IF_LEZ: opcode = Instruction::IF_GTZ; break; |
| 613 | default: LOG(FATAL) << "Unexpected opcode " << opcode; |
| 614 | } |
| 615 | prev->last_mir_insn->dalvikInsn.opcode = opcode; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 616 | BasicBlockId t_bb = prev->taken; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 617 | prev->taken = prev->fall_through; |
| 618 | prev->fall_through = t_bb; |
| 619 | break; |
| 620 | } |
| 621 | walker = prev; |
| 622 | } |
| 623 | return false; |
| 624 | } |
| 625 | |
| 626 | /* Combine any basic blocks terminated by instructions that we now know can't throw */ |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 627 | void MIRGraph::CombineBlocks(struct BasicBlock* bb) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 628 | // Loop here to allow combining a sequence of blocks |
| 629 | while (true) { |
| 630 | // Check termination conditions |
| 631 | if ((bb->first_mir_insn == NULL) |
| 632 | || (bb->data_flow_info == NULL) |
| 633 | || (bb->block_type == kExceptionHandling) |
| 634 | || (bb->block_type == kExitBlock) |
| 635 | || (bb->block_type == kDead) |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 636 | || (bb->taken == NullBasicBlockId) |
| 637 | || (GetBasicBlock(bb->taken)->block_type != kExceptionHandling) |
| 638 | || (bb->successor_block_list_type != kNotUsed) |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 639 | || (static_cast<int>(bb->last_mir_insn->dalvikInsn.opcode) != kMirOpCheck)) { |
| 640 | break; |
| 641 | } |
| 642 | |
| 643 | // Test the kMirOpCheck instruction |
| 644 | MIR* mir = bb->last_mir_insn; |
| 645 | // Grab the attributes from the paired opcode |
| 646 | MIR* throw_insn = mir->meta.throw_insn; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 647 | uint64_t df_attributes = oat_data_flow_attributes_[throw_insn->dalvikInsn.opcode]; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 648 | bool can_combine = true; |
| 649 | if (df_attributes & DF_HAS_NULL_CHKS) { |
| 650 | can_combine &= ((throw_insn->optimization_flags & MIR_IGNORE_NULL_CHECK) != 0); |
| 651 | } |
| 652 | if (df_attributes & DF_HAS_RANGE_CHKS) { |
| 653 | can_combine &= ((throw_insn->optimization_flags & MIR_IGNORE_RANGE_CHECK) != 0); |
| 654 | } |
| 655 | if (!can_combine) { |
| 656 | break; |
| 657 | } |
| 658 | // OK - got one. Combine |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 659 | BasicBlock* bb_next = GetBasicBlock(bb->fall_through); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 660 | DCHECK(!bb_next->catch_entry); |
| 661 | DCHECK_EQ(Predecessors(bb_next), 1U); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 662 | // Overwrite the kOpCheck insn with the paired opcode |
| 663 | DCHECK_EQ(bb_next->first_mir_insn, throw_insn); |
| 664 | *bb->last_mir_insn = *throw_insn; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 665 | // Use the successor info from the next block |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 666 | bb->successor_block_list_type = bb_next->successor_block_list_type; |
| 667 | bb->successor_blocks = bb_next->successor_blocks; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 668 | // Use the ending block linkage from the next block |
| 669 | bb->fall_through = bb_next->fall_through; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 670 | GetBasicBlock(bb->taken)->block_type = kDead; // Kill the unused exception block |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 671 | bb->taken = bb_next->taken; |
| 672 | // Include the rest of the instructions |
| 673 | bb->last_mir_insn = bb_next->last_mir_insn; |
| 674 | /* |
| 675 | * If lower-half of pair of blocks to combine contained a return, move the flag |
| 676 | * to the newly combined block. |
| 677 | */ |
| 678 | bb->terminated_by_return = bb_next->terminated_by_return; |
| 679 | |
| 680 | /* |
| 681 | * NOTE: we aren't updating all dataflow info here. Should either make sure this pass |
| 682 | * happens after uses of i_dominated, dom_frontier or update the dataflow info here. |
| 683 | */ |
| 684 | |
| 685 | // Kill bb_next and remap now-dead id to parent |
| 686 | bb_next->block_type = kDead; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 687 | block_id_map_.Overwrite(bb_next->id, bb->id); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 688 | |
| 689 | // Now, loop back and see if we can keep going |
| 690 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 691 | } |
| 692 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 693 | /* |
| 694 | * Eliminate unnecessary null checks for a basic block. Also, while we're doing |
| 695 | * an iterative walk go ahead and perform type and size inference. |
| 696 | */ |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 697 | bool MIRGraph::EliminateNullChecksAndInferTypes(BasicBlock* bb) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 698 | if (bb->data_flow_info == NULL) return false; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 699 | bool infer_changed = false; |
| 700 | bool do_nce = ((cu_->disable_opt & (1 << kNullCheckElimination)) == 0); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 701 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 702 | if (do_nce) { |
| 703 | /* |
| 704 | * Set initial state. Be conservative with catch |
| 705 | * blocks and start with no assumptions about null check |
| 706 | * status (except for "this"). |
| 707 | */ |
| 708 | if ((bb->block_type == kEntryBlock) | bb->catch_entry) { |
| 709 | temp_ssa_register_v_->ClearAllBits(); |
| 710 | // Assume all ins are objects. |
| 711 | for (uint16_t in_reg = cu_->num_dalvik_registers - cu_->num_ins; |
| 712 | in_reg < cu_->num_dalvik_registers; in_reg++) { |
| 713 | temp_ssa_register_v_->SetBit(in_reg); |
| 714 | } |
| 715 | if ((cu_->access_flags & kAccStatic) == 0) { |
| 716 | // If non-static method, mark "this" as non-null |
| 717 | int this_reg = cu_->num_dalvik_registers - cu_->num_ins; |
| 718 | temp_ssa_register_v_->ClearBit(this_reg); |
| 719 | } |
| 720 | } else if (bb->predecessors->Size() == 1) { |
| 721 | BasicBlock* pred_bb = GetBasicBlock(bb->predecessors->Get(0)); |
| 722 | temp_ssa_register_v_->Copy(pred_bb->data_flow_info->ending_null_check_v); |
| 723 | if (pred_bb->block_type == kDalvikByteCode) { |
| 724 | // Check to see if predecessor had an explicit null-check. |
| 725 | MIR* last_insn = pred_bb->last_mir_insn; |
| 726 | Instruction::Code last_opcode = last_insn->dalvikInsn.opcode; |
| 727 | if (last_opcode == Instruction::IF_EQZ) { |
| 728 | if (pred_bb->fall_through == bb->id) { |
| 729 | // The fall-through of a block following a IF_EQZ, set the vA of the IF_EQZ to show that |
| 730 | // it can't be null. |
| 731 | temp_ssa_register_v_->ClearBit(last_insn->ssa_rep->uses[0]); |
| 732 | } |
| 733 | } else if (last_opcode == Instruction::IF_NEZ) { |
| 734 | if (pred_bb->taken == bb->id) { |
| 735 | // The taken block following a IF_NEZ, set the vA of the IF_NEZ to show that it can't be |
| 736 | // null. |
| 737 | temp_ssa_register_v_->ClearBit(last_insn->ssa_rep->uses[0]); |
| 738 | } |
Ian Rogers | 22fd6a0 | 2013-06-13 15:06:54 -0700 | [diff] [blame] | 739 | } |
| 740 | } |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 741 | } else { |
| 742 | // Starting state is union of all incoming arcs |
| 743 | GrowableArray<BasicBlockId>::Iterator iter(bb->predecessors); |
| 744 | BasicBlock* pred_bb = GetBasicBlock(iter.Next()); |
| 745 | DCHECK(pred_bb != NULL); |
| 746 | temp_ssa_register_v_->Copy(pred_bb->data_flow_info->ending_null_check_v); |
| 747 | while (true) { |
| 748 | pred_bb = GetBasicBlock(iter.Next()); |
| 749 | if (!pred_bb) break; |
| 750 | if ((pred_bb->data_flow_info == NULL) || |
| 751 | (pred_bb->data_flow_info->ending_null_check_v == NULL)) { |
| 752 | continue; |
| 753 | } |
| 754 | temp_ssa_register_v_->Union(pred_bb->data_flow_info->ending_null_check_v); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 755 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 756 | } |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 757 | // At this point, temp_ssa_register_v_ shows which sregs have an object definition with |
| 758 | // no intervening uses. |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | // Walk through the instruction in the block, updating as necessary |
| 762 | for (MIR* mir = bb->first_mir_insn; mir != NULL; mir = mir->next) { |
| 763 | if (mir->ssa_rep == NULL) { |
| 764 | continue; |
| 765 | } |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 766 | |
| 767 | // Propagate type info. |
| 768 | infer_changed = InferTypeAndSize(bb, mir, infer_changed); |
| 769 | if (!do_nce) { |
| 770 | continue; |
| 771 | } |
| 772 | |
| 773 | uint64_t df_attributes = oat_data_flow_attributes_[mir->dalvikInsn.opcode]; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 774 | |
Bill Buzbee | 0b1191c | 2013-10-28 22:11:59 +0000 | [diff] [blame] | 775 | // Might need a null check? |
| 776 | if (df_attributes & DF_HAS_NULL_CHKS) { |
| 777 | int src_idx; |
| 778 | if (df_attributes & DF_NULL_CHK_1) { |
| 779 | src_idx = 1; |
| 780 | } else if (df_attributes & DF_NULL_CHK_2) { |
| 781 | src_idx = 2; |
| 782 | } else { |
| 783 | src_idx = 0; |
| 784 | } |
| 785 | int src_sreg = mir->ssa_rep->uses[src_idx]; |
| 786 | if (!temp_ssa_register_v_->IsBitSet(src_sreg)) { |
| 787 | // Eliminate the null check. |
| 788 | mir->optimization_flags |= MIR_IGNORE_NULL_CHECK; |
| 789 | } else { |
| 790 | // Do the null check. |
| 791 | mir->optimization_flags &= ~MIR_IGNORE_NULL_CHECK; |
| 792 | // Mark s_reg as null-checked |
| 793 | temp_ssa_register_v_->ClearBit(src_sreg); |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | if ((df_attributes & DF_A_WIDE) || |
| 798 | (df_attributes & (DF_REF_A | DF_SETS_CONST | DF_NULL_TRANSFER)) == 0) { |
| 799 | continue; |
| 800 | } |
| 801 | |
| 802 | /* |
| 803 | * First, mark all object definitions as requiring null check. |
| 804 | * Note: we can't tell if a CONST definition might be used as an object, so treat |
| 805 | * them all as object definitions. |
| 806 | */ |
| 807 | if (((df_attributes & (DF_DA | DF_REF_A)) == (DF_DA | DF_REF_A)) || |
| 808 | (df_attributes & DF_SETS_CONST)) { |
Ian Rogers | 31aa97c | 2013-10-25 23:07:29 +0000 | [diff] [blame] | 809 | temp_ssa_register_v_->SetBit(mir->ssa_rep->defs[0]); |
buzbee | 4db179d | 2013-10-23 12:16:39 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Bill Buzbee | 0b1191c | 2013-10-28 22:11:59 +0000 | [diff] [blame] | 812 | // Now, remove mark from all object definitions we know are non-null. |
| 813 | if (df_attributes & DF_NON_NULL_DST) { |
| 814 | // Mark target of NEW* as non-null |
| 815 | temp_ssa_register_v_->ClearBit(mir->ssa_rep->defs[0]); |
| 816 | } |
| 817 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 818 | // Mark non-null returns from invoke-style NEW* |
| 819 | if (df_attributes & DF_NON_NULL_RET) { |
| 820 | MIR* next_mir = mir->next; |
| 821 | // Next should be an MOVE_RESULT_OBJECT |
| 822 | if (next_mir && |
| 823 | next_mir->dalvikInsn.opcode == Instruction::MOVE_RESULT_OBJECT) { |
| 824 | // Mark as null checked |
Bill Buzbee | 0b1191c | 2013-10-28 22:11:59 +0000 | [diff] [blame] | 825 | temp_ssa_register_v_->ClearBit(next_mir->ssa_rep->defs[0]); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 826 | } else { |
| 827 | if (next_mir) { |
| 828 | LOG(WARNING) << "Unexpected opcode following new: " << next_mir->dalvikInsn.opcode; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 829 | } else if (bb->fall_through != NullBasicBlockId) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 830 | // Look in next basic block |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 831 | struct BasicBlock* next_bb = GetBasicBlock(bb->fall_through); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 832 | for (MIR* tmir = next_bb->first_mir_insn; tmir != NULL; |
| 833 | tmir =tmir->next) { |
| 834 | if (static_cast<int>(tmir->dalvikInsn.opcode) >= static_cast<int>(kMirOpFirst)) { |
| 835 | continue; |
| 836 | } |
| 837 | // First non-pseudo should be MOVE_RESULT_OBJECT |
| 838 | if (tmir->dalvikInsn.opcode == Instruction::MOVE_RESULT_OBJECT) { |
| 839 | // Mark as null checked |
Bill Buzbee | 0b1191c | 2013-10-28 22:11:59 +0000 | [diff] [blame] | 840 | temp_ssa_register_v_->ClearBit(tmir->ssa_rep->defs[0]); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 841 | } else { |
| 842 | LOG(WARNING) << "Unexpected op after new: " << tmir->dalvikInsn.opcode; |
| 843 | } |
| 844 | break; |
| 845 | } |
| 846 | } |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | /* |
| 851 | * Propagate nullcheck state on register copies (including |
| 852 | * Phi pseudo copies. For the latter, nullcheck state is |
Bill Buzbee | 0b1191c | 2013-10-28 22:11:59 +0000 | [diff] [blame] | 853 | * the "or" of all the Phi's operands. |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 854 | */ |
| 855 | if (df_attributes & (DF_NULL_TRANSFER_0 | DF_NULL_TRANSFER_N)) { |
| 856 | int tgt_sreg = mir->ssa_rep->defs[0]; |
| 857 | int operands = (df_attributes & DF_NULL_TRANSFER_0) ? 1 : |
| 858 | mir->ssa_rep->num_uses; |
Bill Buzbee | 0b1191c | 2013-10-28 22:11:59 +0000 | [diff] [blame] | 859 | bool needs_null_check = false; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 860 | for (int i = 0; i < operands; i++) { |
Bill Buzbee | 0b1191c | 2013-10-28 22:11:59 +0000 | [diff] [blame] | 861 | needs_null_check |= temp_ssa_register_v_->IsBitSet(mir->ssa_rep->uses[i]); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 862 | } |
Bill Buzbee | 0b1191c | 2013-10-28 22:11:59 +0000 | [diff] [blame] | 863 | if (needs_null_check) { |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 864 | temp_ssa_register_v_->SetBit(tgt_sreg); |
Bill Buzbee | 0b1191c | 2013-10-28 22:11:59 +0000 | [diff] [blame] | 865 | } else { |
| 866 | temp_ssa_register_v_->ClearBit(tgt_sreg); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 867 | } |
| 868 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | // Did anything change? |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 872 | bool nce_changed = do_nce && !temp_ssa_register_v_->Equal(bb->data_flow_info->ending_null_check_v); |
| 873 | if (nce_changed) { |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 874 | bb->data_flow_info->ending_null_check_v->Copy(temp_ssa_register_v_); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 875 | } |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 876 | return infer_changed | nce_changed; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 877 | } |
| 878 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 879 | void MIRGraph::DumpCheckStats() { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 880 | Checkstats* stats = |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 881 | static_cast<Checkstats*>(arena_->Alloc(sizeof(Checkstats), kArenaAllocDFInfo)); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 882 | checkstats_ = stats; |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 883 | AllNodesIterator iter(this); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 884 | for (BasicBlock* bb = iter.Next(); bb != NULL; bb = iter.Next()) { |
| 885 | CountChecks(bb); |
| 886 | } |
| 887 | if (stats->null_checks > 0) { |
| 888 | float eliminated = static_cast<float>(stats->null_checks_eliminated); |
| 889 | float checks = static_cast<float>(stats->null_checks); |
| 890 | LOG(INFO) << "Null Checks: " << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " " |
| 891 | << stats->null_checks_eliminated << " of " << stats->null_checks << " -> " |
| 892 | << (eliminated/checks) * 100.0 << "%"; |
| 893 | } |
| 894 | if (stats->range_checks > 0) { |
| 895 | float eliminated = static_cast<float>(stats->range_checks_eliminated); |
| 896 | float checks = static_cast<float>(stats->range_checks); |
| 897 | LOG(INFO) << "Range Checks: " << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " " |
| 898 | << stats->range_checks_eliminated << " of " << stats->range_checks << " -> " |
| 899 | << (eliminated/checks) * 100.0 << "%"; |
| 900 | } |
| 901 | } |
| 902 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 903 | bool MIRGraph::BuildExtendedBBList(struct BasicBlock* bb) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 904 | if (bb->visited) return false; |
| 905 | if (!((bb->block_type == kEntryBlock) || (bb->block_type == kDalvikByteCode) |
| 906 | || (bb->block_type == kExitBlock))) { |
| 907 | // Ignore special blocks |
| 908 | bb->visited = true; |
| 909 | return false; |
| 910 | } |
| 911 | // Must be head of extended basic block. |
| 912 | BasicBlock* start_bb = bb; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 913 | extended_basic_blocks_.push_back(bb->id); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 914 | bool terminated_by_return = false; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 915 | bool do_local_value_numbering = false; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 916 | // Visit blocks strictly dominated by this head. |
| 917 | while (bb != NULL) { |
| 918 | bb->visited = true; |
| 919 | terminated_by_return |= bb->terminated_by_return; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 920 | do_local_value_numbering |= bb->use_lvn; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 921 | bb = NextDominatedBlock(bb); |
| 922 | } |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 923 | if (terminated_by_return || do_local_value_numbering) { |
| 924 | // Do lvn for all blocks in this extended set. |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 925 | bb = start_bb; |
| 926 | while (bb != NULL) { |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 927 | bb->use_lvn = do_local_value_numbering; |
| 928 | bb->dominates_return = terminated_by_return; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 929 | bb = NextDominatedBlock(bb); |
| 930 | } |
| 931 | } |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 932 | return false; // Not iterative - return value will be ignored |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 933 | } |
| 934 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 935 | void MIRGraph::BasicBlockOptimization() { |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 936 | if ((cu_->disable_opt & (1 << kSuppressExceptionEdges)) != 0) { |
| 937 | ClearAllVisitedFlags(); |
| 938 | PreOrderDfsIterator iter2(this); |
| 939 | for (BasicBlock* bb = iter2.Next(); bb != NULL; bb = iter2.Next()) { |
| 940 | BuildExtendedBBList(bb); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 941 | } |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 942 | // Perform extended basic block optimizations. |
| 943 | for (unsigned int i = 0; i < extended_basic_blocks_.size(); i++) { |
| 944 | BasicBlockOpt(GetBasicBlock(extended_basic_blocks_[i])); |
| 945 | } |
| 946 | } else { |
| 947 | PreOrderDfsIterator iter(this); |
| 948 | for (BasicBlock* bb = iter.Next(); bb != NULL; bb = iter.Next()) { |
| 949 | BasicBlockOpt(bb); |
| 950 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 951 | } |
| 952 | } |
| 953 | |
| 954 | } // namespace art |