| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/flow_graph_optimizer.h" | 5 #include "vm/flow_graph_optimizer.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/cha.h" | 8 #include "vm/cha.h" |
| 9 #include "vm/flow_graph_builder.h" | 9 #include "vm/flow_graph_builder.h" |
| 10 #include "vm/flow_graph_compiler.h" | 10 #include "vm/flow_graph_compiler.h" |
| (...skipping 3256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3267 ASSERT((*pred_out_values)[expr_id] != NULL); | 3267 ASSERT((*pred_out_values)[expr_id] != NULL); |
| 3268 | 3268 |
| 3269 // Sets of outgoing values are not linked into use lists so | 3269 // Sets of outgoing values are not linked into use lists so |
| 3270 // they might contain values that were replaced and removed | 3270 // they might contain values that were replaced and removed |
| 3271 // from the graph by this iteration. | 3271 // from the graph by this iteration. |
| 3272 // To prevent using them we additionally mark definitions themselves | 3272 // To prevent using them we additionally mark definitions themselves |
| 3273 // as replaced and store a pointer to the replacement. | 3273 // as replaced and store a pointer to the replacement. |
| 3274 Definition* replacement = (*pred_out_values)[expr_id]->Replacement(); | 3274 Definition* replacement = (*pred_out_values)[expr_id]->Replacement(); |
| 3275 Value* input = new Value(replacement); | 3275 Value* input = new Value(replacement); |
| 3276 phi->SetInputAt(i, input); | 3276 phi->SetInputAt(i, input); |
| 3277 | |
| 3278 // TODO(vegorov): add a helper function to handle input insertion. | |
| 3279 input->set_instruction(phi); | |
| 3280 input->set_use_index(i); | |
| 3281 replacement->AddInputUse(input); | 3277 replacement->AddInputUse(input); |
| 3282 } | 3278 } |
| 3283 | 3279 |
| 3284 phi->set_ssa_temp_index(graph_->alloc_ssa_temp_index()); | 3280 phi->set_ssa_temp_index(graph_->alloc_ssa_temp_index()); |
| 3285 phis_.Add(phi); // Postpone phi insertion until after load forwarding. | 3281 phis_.Add(phi); // Postpone phi insertion until after load forwarding. |
| 3286 | 3282 |
| 3287 return phi; | 3283 return phi; |
| 3288 } | 3284 } |
| 3289 | 3285 |
| 3290 // Iterate over basic blocks and replace exposed loads with incoming | 3286 // Iterate over basic blocks and replace exposed loads with incoming |
| (...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4263 if (phis != NULL) { | 4259 if (phis != NULL) { |
| 4264 intptr_t pred_count = join->PredecessorCount(); | 4260 intptr_t pred_count = join->PredecessorCount(); |
| 4265 intptr_t live_count = 0; | 4261 intptr_t live_count = 0; |
| 4266 for (intptr_t pred_idx = 0; pred_idx < pred_count; ++pred_idx) { | 4262 for (intptr_t pred_idx = 0; pred_idx < pred_count; ++pred_idx) { |
| 4267 if (reachable_->Contains( | 4263 if (reachable_->Contains( |
| 4268 join->PredecessorAt(pred_idx)->preorder_number())) { | 4264 join->PredecessorAt(pred_idx)->preorder_number())) { |
| 4269 if (live_count < pred_idx) { | 4265 if (live_count < pred_idx) { |
| 4270 for (intptr_t phi_idx = 0; phi_idx < phis->length(); ++phi_idx) { | 4266 for (intptr_t phi_idx = 0; phi_idx < phis->length(); ++phi_idx) { |
| 4271 PhiInstr* phi = (*phis)[phi_idx]; | 4267 PhiInstr* phi = (*phis)[phi_idx]; |
| 4272 if (phi == NULL) continue; | 4268 if (phi == NULL) continue; |
| 4273 Value* input = phi->inputs_[pred_idx]; | 4269 phi->SetInputAt(live_count, phi->InputAt(pred_idx)); |
| 4274 input->set_use_index(live_count); | |
| 4275 phi->inputs_[live_count] = input; | |
| 4276 } | 4270 } |
| 4277 } | 4271 } |
| 4278 ++live_count; | 4272 ++live_count; |
| 4279 } else { | 4273 } else { |
| 4280 for (intptr_t phi_idx = 0; phi_idx < phis->length(); ++phi_idx) { | 4274 for (intptr_t phi_idx = 0; phi_idx < phis->length(); ++phi_idx) { |
| 4281 PhiInstr* phi = (*phis)[phi_idx]; | 4275 PhiInstr* phi = (*phis)[phi_idx]; |
| 4282 if (phi == NULL) continue; | 4276 if (phi == NULL) continue; |
| 4283 phi->inputs_[pred_idx]->RemoveFromUseList(); | 4277 phi->InputAt(pred_idx)->RemoveFromUseList(); |
| 4284 } | 4278 } |
| 4285 } | 4279 } |
| 4286 } | 4280 } |
| 4287 if (live_count < pred_count) { | 4281 if (live_count < pred_count) { |
| 4288 for (intptr_t phi_idx = 0; phi_idx < phis->length(); ++phi_idx) { | 4282 for (intptr_t phi_idx = 0; phi_idx < phis->length(); ++phi_idx) { |
| 4289 PhiInstr* phi = (*phis)[phi_idx]; | 4283 PhiInstr* phi = (*phis)[phi_idx]; |
| 4290 if (phi == NULL) continue; | 4284 if (phi == NULL) continue; |
| 4291 if (FLAG_remove_redundant_phis && (live_count == 1)) { | 4285 if (FLAG_remove_redundant_phis && (live_count == 1)) { |
| 4292 Value* input = phi->InputAt(0); | 4286 Value* input = phi->InputAt(0); |
| 4293 phi->ReplaceUsesWith(input->definition()); | 4287 phi->ReplaceUsesWith(input->definition()); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4368 | 4362 |
| 4369 if (FLAG_trace_constant_propagation) { | 4363 if (FLAG_trace_constant_propagation) { |
| 4370 OS::Print("\n==== After constant propagation ====\n"); | 4364 OS::Print("\n==== After constant propagation ====\n"); |
| 4371 FlowGraphPrinter printer(*graph_); | 4365 FlowGraphPrinter printer(*graph_); |
| 4372 printer.PrintBlocks(); | 4366 printer.PrintBlocks(); |
| 4373 } | 4367 } |
| 4374 } | 4368 } |
| 4375 | 4369 |
| 4376 | 4370 |
| 4377 } // namespace dart | 4371 } // namespace dart |
| OLD | NEW |