Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [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 | #include "dead_code_elimination.h" |
| 18 | |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 19 | #include "base/array_ref.h" |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 20 | #include "base/bit_vector-inl.h" |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 21 | #include "base/stl_util.h" |
David Brazdil | 84daae5 | 2015-05-18 12:06:52 +0100 | [diff] [blame] | 22 | #include "ssa_phi_elimination.h" |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 23 | |
| 24 | namespace art { |
| 25 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 26 | static void MarkReachableBlocks(HGraph* graph, ArenaBitVector* visited) { |
Vladimir Marko | 3ea5a97 | 2016-05-09 20:23:34 +0100 | [diff] [blame] | 27 | ArenaVector<HBasicBlock*> worklist(graph->GetArena()->Adapter(kArenaAllocDCE)); |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 28 | constexpr size_t kDefaultWorlistSize = 8; |
| 29 | worklist.reserve(kDefaultWorlistSize); |
| 30 | visited->SetBit(graph->GetEntryBlock()->GetBlockId()); |
| 31 | worklist.push_back(graph->GetEntryBlock()); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 32 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 33 | while (!worklist.empty()) { |
| 34 | HBasicBlock* block = worklist.back(); |
| 35 | worklist.pop_back(); |
| 36 | int block_id = block->GetBlockId(); |
| 37 | DCHECK(visited->IsBitSet(block_id)); |
| 38 | |
| 39 | ArrayRef<HBasicBlock* const> live_successors(block->GetSuccessors()); |
| 40 | HInstruction* last_instruction = block->GetLastInstruction(); |
| 41 | if (last_instruction->IsIf()) { |
| 42 | HIf* if_instruction = last_instruction->AsIf(); |
| 43 | HInstruction* condition = if_instruction->InputAt(0); |
| 44 | if (condition->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 45 | if (condition->AsIntConstant()->IsTrue()) { |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 46 | live_successors = live_successors.SubArray(0u, 1u); |
| 47 | DCHECK_EQ(live_successors[0], if_instruction->IfTrueSuccessor()); |
| 48 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 49 | DCHECK(condition->AsIntConstant()->IsFalse()) << condition->AsIntConstant()->GetValue(); |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 50 | live_successors = live_successors.SubArray(1u, 1u); |
| 51 | DCHECK_EQ(live_successors[0], if_instruction->IfFalseSuccessor()); |
| 52 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 53 | } |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 54 | } else if (last_instruction->IsPackedSwitch()) { |
| 55 | HPackedSwitch* switch_instruction = last_instruction->AsPackedSwitch(); |
| 56 | HInstruction* switch_input = switch_instruction->InputAt(0); |
| 57 | if (switch_input->IsIntConstant()) { |
| 58 | int32_t switch_value = switch_input->AsIntConstant()->GetValue(); |
| 59 | int32_t start_value = switch_instruction->GetStartValue(); |
Vladimir Marko | 430c4f5 | 2015-09-25 17:10:15 +0100 | [diff] [blame] | 60 | // Note: Though the spec forbids packed-switch values to wrap around, we leave |
| 61 | // that task to the verifier and use unsigned arithmetic with it's "modulo 2^32" |
| 62 | // semantics to check if the value is in range, wrapped or not. |
| 63 | uint32_t switch_index = |
| 64 | static_cast<uint32_t>(switch_value) - static_cast<uint32_t>(start_value); |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 65 | if (switch_index < switch_instruction->GetNumEntries()) { |
| 66 | live_successors = live_successors.SubArray(switch_index, 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 67 | DCHECK_EQ(live_successors[0], block->GetSuccessors()[switch_index]); |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 68 | } else { |
| 69 | live_successors = live_successors.SubArray(switch_instruction->GetNumEntries(), 1u); |
| 70 | DCHECK_EQ(live_successors[0], switch_instruction->GetDefaultBlock()); |
| 71 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 72 | } |
| 73 | } |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 74 | |
| 75 | for (HBasicBlock* successor : live_successors) { |
| 76 | // Add only those successors that have not been visited yet. |
| 77 | if (!visited->IsBitSet(successor->GetBlockId())) { |
| 78 | visited->SetBit(successor->GetBlockId()); |
| 79 | worklist.push_back(successor); |
| 80 | } |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void HDeadCodeElimination::MaybeRecordDeadBlock(HBasicBlock* block) { |
| 86 | if (stats_ != nullptr) { |
| 87 | stats_->RecordStat(MethodCompilationStat::kRemovedDeadInstruction, |
| 88 | block->GetPhis().CountSize() + block->GetInstructions().CountSize()); |
| 89 | } |
| 90 | } |
| 91 | |
Nicolas Geoffray | dac9b19 | 2016-07-15 10:46:17 +0100 | [diff] [blame] | 92 | void HDeadCodeElimination::MaybeRecordSimplifyIf() { |
| 93 | if (stats_ != nullptr) { |
| 94 | stats_->RecordStat(MethodCompilationStat::kSimplifyIf); |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 95 | } |
Nicolas Geoffray | dac9b19 | 2016-07-15 10:46:17 +0100 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | static bool HasInput(HCondition* instruction, HInstruction* input) { |
| 99 | return (instruction->InputAt(0) == input) || |
| 100 | (instruction->InputAt(1) == input); |
| 101 | } |
| 102 | |
| 103 | static bool HasEquality(IfCondition condition) { |
| 104 | switch (condition) { |
| 105 | case kCondEQ: |
| 106 | case kCondLE: |
| 107 | case kCondGE: |
| 108 | case kCondBE: |
| 109 | case kCondAE: |
| 110 | return true; |
| 111 | case kCondNE: |
| 112 | case kCondLT: |
| 113 | case kCondGT: |
| 114 | case kCondB: |
| 115 | case kCondA: |
| 116 | return false; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | static HConstant* Evaluate(HCondition* condition, HInstruction* left, HInstruction* right) { |
| 121 | if (left == right && !Primitive::IsFloatingPointType(left->GetType())) { |
| 122 | return condition->GetBlock()->GetGraph()->GetIntConstant( |
| 123 | HasEquality(condition->GetCondition()) ? 1 : 0); |
| 124 | } |
| 125 | |
| 126 | if (!left->IsConstant() || !right->IsConstant()) { |
| 127 | return nullptr; |
| 128 | } |
| 129 | |
| 130 | if (left->IsIntConstant()) { |
| 131 | return condition->Evaluate(left->AsIntConstant(), right->AsIntConstant()); |
| 132 | } else if (left->IsNullConstant()) { |
| 133 | return condition->Evaluate(left->AsNullConstant(), right->AsNullConstant()); |
| 134 | } else if (left->IsLongConstant()) { |
| 135 | return condition->Evaluate(left->AsLongConstant(), right->AsLongConstant()); |
| 136 | } else if (left->IsFloatConstant()) { |
| 137 | return condition->Evaluate(left->AsFloatConstant(), right->AsFloatConstant()); |
| 138 | } else { |
| 139 | DCHECK(left->IsDoubleConstant()); |
| 140 | return condition->Evaluate(left->AsDoubleConstant(), right->AsDoubleConstant()); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | // Simplify the pattern: |
| 145 | // |
| 146 | // B1 B2 ... |
| 147 | // goto goto goto |
| 148 | // \ | / |
| 149 | // \ | / |
| 150 | // B3 |
| 151 | // i1 = phi(input, input) |
| 152 | // (i2 = condition on i1) |
| 153 | // if i1 (or i2) |
| 154 | // / \ |
| 155 | // / \ |
| 156 | // B4 B5 |
| 157 | // |
| 158 | // Into: |
| 159 | // |
| 160 | // B1 B2 ... |
| 161 | // | | | |
| 162 | // B4 B5 B? |
| 163 | // |
| 164 | // This simplification cannot be applied for loop headers, as they |
| 165 | // contain a suspend check. |
| 166 | // |
| 167 | // Note that we rely on the dead code elimination to get rid of B3. |
| 168 | bool HDeadCodeElimination::SimplifyIfs() { |
| 169 | bool simplified_one_or_more_ifs = false; |
| 170 | bool rerun_dominance_and_loop_analysis = false; |
| 171 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 172 | for (HBasicBlock* block : graph_->GetReversePostOrder()) { |
Nicolas Geoffray | dac9b19 | 2016-07-15 10:46:17 +0100 | [diff] [blame] | 173 | HInstruction* last = block->GetLastInstruction(); |
| 174 | HInstruction* first = block->GetFirstInstruction(); |
| 175 | if (last->IsIf() && |
| 176 | block->HasSinglePhi() && |
| 177 | block->GetFirstPhi()->HasOnlyOneNonEnvironmentUse()) { |
| 178 | bool has_only_phi_and_if = (last == first) && (last->InputAt(0) == block->GetFirstPhi()); |
| 179 | bool has_only_phi_condition_and_if = |
| 180 | !has_only_phi_and_if && |
| 181 | first->IsCondition() && |
| 182 | HasInput(first->AsCondition(), block->GetFirstPhi()) && |
| 183 | (first->GetNext() == last) && |
| 184 | (last->InputAt(0) == first) && |
| 185 | first->HasOnlyOneNonEnvironmentUse(); |
| 186 | |
| 187 | if (has_only_phi_and_if || has_only_phi_condition_and_if) { |
| 188 | DCHECK(!block->IsLoopHeader()); |
| 189 | HPhi* phi = block->GetFirstPhi()->AsPhi(); |
| 190 | bool phi_input_is_left = (first->InputAt(0) == phi); |
| 191 | |
| 192 | // Walk over all inputs of the phis and update the control flow of |
| 193 | // predecessors feeding constants to the phi. |
| 194 | // Note that phi->InputCount() may change inside the loop. |
| 195 | for (size_t i = 0; i < phi->InputCount();) { |
| 196 | HInstruction* input = phi->InputAt(i); |
| 197 | HInstruction* value_to_check = nullptr; |
| 198 | if (has_only_phi_and_if) { |
| 199 | if (input->IsIntConstant()) { |
| 200 | value_to_check = input; |
| 201 | } |
| 202 | } else { |
| 203 | DCHECK(has_only_phi_condition_and_if); |
| 204 | if (phi_input_is_left) { |
| 205 | value_to_check = Evaluate(first->AsCondition(), input, first->InputAt(1)); |
| 206 | } else { |
| 207 | value_to_check = Evaluate(first->AsCondition(), first->InputAt(0), input); |
| 208 | } |
| 209 | } |
| 210 | if (value_to_check == nullptr) { |
| 211 | // Could not evaluate to a constant, continue iterating over the inputs. |
| 212 | ++i; |
| 213 | } else { |
| 214 | HBasicBlock* predecessor_to_update = block->GetPredecessors()[i]; |
| 215 | HBasicBlock* successor_to_update = nullptr; |
| 216 | if (value_to_check->AsIntConstant()->IsTrue()) { |
| 217 | successor_to_update = last->AsIf()->IfTrueSuccessor(); |
| 218 | } else { |
| 219 | DCHECK(value_to_check->AsIntConstant()->IsFalse()) |
| 220 | << value_to_check->AsIntConstant()->GetValue(); |
| 221 | successor_to_update = last->AsIf()->IfFalseSuccessor(); |
| 222 | } |
| 223 | predecessor_to_update->ReplaceSuccessor(block, successor_to_update); |
| 224 | phi->RemoveInputAt(i); |
| 225 | simplified_one_or_more_ifs = true; |
| 226 | if (block->IsInLoop()) { |
| 227 | rerun_dominance_and_loop_analysis = true; |
| 228 | } |
| 229 | // For simplicity, don't create a dead block, let the dead code elimination |
| 230 | // pass deal with it. |
| 231 | if (phi->InputCount() == 1) { |
| 232 | break; |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | if (block->GetPredecessors().size() == 1) { |
| 237 | phi->ReplaceWith(phi->InputAt(0)); |
| 238 | block->RemovePhi(phi); |
| 239 | if (has_only_phi_condition_and_if) { |
| 240 | // Evaluate here (and not wait for a constant folding pass) to open |
| 241 | // more opportunities for DCE. |
| 242 | HInstruction* result = first->AsCondition()->TryStaticEvaluation(); |
| 243 | if (result != nullptr) { |
| 244 | first->ReplaceWith(result); |
| 245 | block->RemoveInstruction(first); |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | if (simplified_one_or_more_ifs) { |
| 250 | MaybeRecordSimplifyIf(); |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | // We need to re-analyze the graph in order to run DCE afterwards. |
| 256 | if (simplified_one_or_more_ifs) { |
| 257 | if (rerun_dominance_and_loop_analysis) { |
| 258 | graph_->ClearLoopInformation(); |
| 259 | graph_->ClearDominanceInformation(); |
| 260 | graph_->BuildDominatorTree(); |
| 261 | } else { |
| 262 | graph_->ClearDominanceInformation(); |
| 263 | // We have introduced critical edges, remove them. |
| 264 | graph_->SimplifyCFG(); |
| 265 | graph_->ComputeDominanceInformation(); |
| 266 | graph_->ComputeTryBlockInformation(); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | return simplified_one_or_more_ifs; |
| 271 | } |
| 272 | |
| 273 | void HDeadCodeElimination::ConnectSuccessiveBlocks() { |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 274 | // Order does not matter. Skip the entry block by starting at index 1 in reverse post order. |
| 275 | for (size_t i = 1u, size = graph_->GetReversePostOrder().size(); i != size; ++i) { |
| 276 | HBasicBlock* block = graph_->GetReversePostOrder()[i]; |
| 277 | DCHECK(!block->IsEntryBlock()); |
| 278 | while (block->GetLastInstruction()->IsGoto()) { |
| 279 | HBasicBlock* successor = block->GetSingleSuccessor(); |
| 280 | if (successor->IsExitBlock() || successor->GetPredecessors().size() != 1u) { |
| 281 | break; |
| 282 | } |
| 283 | DCHECK_LT(i, IndexOfElement(graph_->GetReversePostOrder(), successor)); |
| 284 | block->MergeWith(successor); |
| 285 | --size; |
| 286 | DCHECK_EQ(size, graph_->GetReversePostOrder().size()); |
| 287 | DCHECK_EQ(block, graph_->GetReversePostOrder()[i]); |
| 288 | // Reiterate on this block in case it can be merged with its new successor. |
Nicolas Geoffray | dac9b19 | 2016-07-15 10:46:17 +0100 | [diff] [blame] | 289 | } |
Nicolas Geoffray | dac9b19 | 2016-07-15 10:46:17 +0100 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
| 293 | bool HDeadCodeElimination::RemoveDeadBlocks() { |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 294 | // Classify blocks as reachable/unreachable. |
| 295 | ArenaAllocator* allocator = graph_->GetArena(); |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 296 | ArenaBitVector live_blocks(allocator, graph_->GetBlocks().size(), false, kArenaAllocDCE); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 297 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 298 | MarkReachableBlocks(graph_, &live_blocks); |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 299 | bool removed_one_or_more_blocks = false; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 300 | bool rerun_dominance_and_loop_analysis = false; |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 301 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 302 | // Remove all dead blocks. Iterate in post order because removal needs the |
| 303 | // block's chain of dominators and nested loops need to be updated from the |
| 304 | // inside out. |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 305 | for (HBasicBlock* block : graph_->GetPostOrder()) { |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 306 | int id = block->GetBlockId(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 307 | if (!live_blocks.IsBitSet(id)) { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 308 | MaybeRecordDeadBlock(block); |
| 309 | block->DisconnectAndDelete(); |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 310 | removed_one_or_more_blocks = true; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 311 | if (block->IsInLoop()) { |
| 312 | rerun_dominance_and_loop_analysis = true; |
| 313 | } |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 314 | } |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 315 | } |
| 316 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 317 | // If we removed at least one block, we need to recompute the full |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 318 | // dominator tree and try block membership. |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 319 | if (removed_one_or_more_blocks) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 320 | if (rerun_dominance_and_loop_analysis) { |
| 321 | graph_->ClearLoopInformation(); |
| 322 | graph_->ClearDominanceInformation(); |
| 323 | graph_->BuildDominatorTree(); |
| 324 | } else { |
| 325 | graph_->ClearDominanceInformation(); |
| 326 | graph_->ComputeDominanceInformation(); |
| 327 | graph_->ComputeTryBlockInformation(); |
| 328 | } |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 329 | } |
Nicolas Geoffray | dac9b19 | 2016-07-15 10:46:17 +0100 | [diff] [blame] | 330 | return removed_one_or_more_blocks; |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | void HDeadCodeElimination::RemoveDeadInstructions() { |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 334 | // Process basic blocks in post-order in the dominator tree, so that |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 335 | // a dead instruction depending on another dead instruction is removed. |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 336 | for (HBasicBlock* block : graph_->GetPostOrder()) { |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 337 | // Traverse this block's instructions in backward order and remove |
| 338 | // the unused ones. |
| 339 | HBackwardInstructionIterator i(block->GetInstructions()); |
| 340 | // Skip the first iteration, as the last instruction of a block is |
| 341 | // a branching instruction. |
| 342 | DCHECK(i.Current()->IsControlFlow()); |
| 343 | for (i.Advance(); !i.Done(); i.Advance()) { |
| 344 | HInstruction* inst = i.Current(); |
| 345 | DCHECK(!inst->IsControlFlow()); |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 346 | if (inst->IsDeadAndRemovable()) { |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 347 | block->RemoveInstruction(inst); |
Calin Juravle | 8f20bdb | 2015-04-21 14:07:50 +0100 | [diff] [blame] | 348 | MaybeRecordStat(MethodCompilationStat::kRemovedDeadInstruction); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 354 | void HDeadCodeElimination::Run() { |
Nicolas Geoffray | dac9b19 | 2016-07-15 10:46:17 +0100 | [diff] [blame] | 355 | // Do not eliminate dead blocks if the graph has irreducible loops. We could |
| 356 | // support it, but that would require changes in our loop representation to handle |
| 357 | // multiple entry points. We decided it was not worth the complexity. |
| 358 | if (!graph_->HasIrreducibleLoops()) { |
| 359 | // Simplify graph to generate more dead block patterns. |
| 360 | ConnectSuccessiveBlocks(); |
| 361 | bool did_any_simplification = false; |
| 362 | did_any_simplification |= SimplifyIfs(); |
| 363 | did_any_simplification |= RemoveDeadBlocks(); |
| 364 | if (did_any_simplification) { |
| 365 | // Connect successive blocks created by dead branches. |
| 366 | ConnectSuccessiveBlocks(); |
| 367 | } |
| 368 | } |
David Brazdil | 84daae5 | 2015-05-18 12:06:52 +0100 | [diff] [blame] | 369 | SsaRedundantPhiElimination(graph_).Run(); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 370 | RemoveDeadInstructions(); |
| 371 | } |
| 372 | |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 373 | } // namespace art |