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 3143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3154 if (pre_header == NULL) continue; | 3154 if (pre_header == NULL) continue; |
3155 | 3155 |
3156 for (BitVector::Iterator loop_it(header->loop_info()); | 3156 for (BitVector::Iterator loop_it(header->loop_info()); |
3157 !loop_it.Done(); | 3157 !loop_it.Done(); |
3158 loop_it.Advance()) { | 3158 loop_it.Advance()) { |
3159 BlockEntryInstr* block = flow_graph()->preorder()[loop_it.Current()]; | 3159 BlockEntryInstr* block = flow_graph()->preorder()[loop_it.Current()]; |
3160 for (ForwardInstructionIterator it(block); | 3160 for (ForwardInstructionIterator it(block); |
3161 !it.Done(); | 3161 !it.Done(); |
3162 it.Advance()) { | 3162 it.Advance()) { |
3163 Instruction* current = it.Current(); | 3163 Instruction* current = it.Current(); |
3164 if (!current->IsPushArgument() && | 3164 if (current->AllowsCSE() && |
3165 current->AllowsCSE() && | |
3166 flow_graph()->block_effects()->CanBeMovedTo(current, pre_header)) { | 3165 flow_graph()->block_effects()->CanBeMovedTo(current, pre_header)) { |
3167 bool inputs_loop_invariant = true; | 3166 bool inputs_loop_invariant = true; |
3168 for (int i = 0; i < current->InputCount(); ++i) { | 3167 for (int i = 0; i < current->InputCount(); ++i) { |
3169 Definition* input_def = current->InputAt(i)->definition(); | 3168 Definition* input_def = current->InputAt(i)->definition(); |
3170 if (!input_def->GetBlock()->Dominates(pre_header)) { | 3169 if (!input_def->GetBlock()->Dominates(pre_header)) { |
3171 inputs_loop_invariant = false; | 3170 inputs_loop_invariant = false; |
3172 break; | 3171 break; |
3173 } | 3172 } |
3174 } | 3173 } |
3175 if (inputs_loop_invariant && | 3174 if (inputs_loop_invariant && |
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4369 if (reachable_->Contains( | 4368 if (reachable_->Contains( |
4370 block->PredecessorAt(pred_idx)->preorder_number())) { | 4369 block->PredecessorAt(pred_idx)->preorder_number())) { |
4371 Join(&value, | 4370 Join(&value, |
4372 instr->InputAt(pred_idx)->definition()->constant_value()); | 4371 instr->InputAt(pred_idx)->definition()->constant_value()); |
4373 } | 4372 } |
4374 } | 4373 } |
4375 SetValue(instr, value); | 4374 SetValue(instr, value); |
4376 } | 4375 } |
4377 | 4376 |
4378 | 4377 |
| 4378 void ConstantPropagator::VisitRedefinition(RedefinitionInstr* instr) { |
| 4379 SetValue(instr, instr->value()->definition()->constant_value()); |
| 4380 } |
| 4381 |
| 4382 |
4379 void ConstantPropagator::VisitParameter(ParameterInstr* instr) { | 4383 void ConstantPropagator::VisitParameter(ParameterInstr* instr) { |
4380 SetValue(instr, non_constant_); | 4384 SetValue(instr, non_constant_); |
4381 } | 4385 } |
4382 | 4386 |
4383 | 4387 |
4384 void ConstantPropagator::VisitPushArgument(PushArgumentInstr* instr) { | 4388 void ConstantPropagator::VisitPushArgument(PushArgumentInstr* instr) { |
4385 SetValue(instr, instr->value()->definition()->constant_value()); | 4389 SetValue(instr, instr->value()->definition()->constant_value()); |
4386 } | 4390 } |
4387 | 4391 |
4388 | 4392 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4643 AllocateObjectWithBoundsCheckInstr* instr) { | 4647 AllocateObjectWithBoundsCheckInstr* instr) { |
4644 SetValue(instr, non_constant_); | 4648 SetValue(instr, non_constant_); |
4645 } | 4649 } |
4646 | 4650 |
4647 | 4651 |
4648 void ConstantPropagator::VisitLoadUntagged(LoadUntaggedInstr* instr) { | 4652 void ConstantPropagator::VisitLoadUntagged(LoadUntaggedInstr* instr) { |
4649 SetValue(instr, non_constant_); | 4653 SetValue(instr, non_constant_); |
4650 } | 4654 } |
4651 | 4655 |
4652 | 4656 |
| 4657 void ConstantPropagator::VisitLoadClassId(LoadClassIdInstr* instr) { |
| 4658 SetValue(instr, non_constant_); |
| 4659 } |
| 4660 |
| 4661 |
4653 void ConstantPropagator::VisitLoadField(LoadFieldInstr* instr) { | 4662 void ConstantPropagator::VisitLoadField(LoadFieldInstr* instr) { |
4654 if ((instr->recognized_kind() == MethodRecognizer::kObjectArrayLength) && | 4663 if ((instr->recognized_kind() == MethodRecognizer::kObjectArrayLength) && |
4655 (instr->value()->definition()->IsCreateArray())) { | 4664 (instr->value()->definition()->IsCreateArray())) { |
4656 const intptr_t length = | 4665 const intptr_t length = |
4657 instr->value()->definition()->AsCreateArray()->num_elements(); | 4666 instr->value()->definition()->AsCreateArray()->num_elements(); |
4658 const Object& result = Smi::ZoneHandle(Smi::New(length)); | 4667 const Object& result = Smi::ZoneHandle(Smi::New(length)); |
4659 SetValue(instr, result); | 4668 SetValue(instr, result); |
4660 return; | 4669 return; |
4661 } | 4670 } |
4662 | 4671 |
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5576 if (changed) { | 5585 if (changed) { |
5577 // We may have changed the block order and the dominator tree. | 5586 // We may have changed the block order and the dominator tree. |
5578 flow_graph->DiscoverBlocks(); | 5587 flow_graph->DiscoverBlocks(); |
5579 GrowableArray<BitVector*> dominance_frontier; | 5588 GrowableArray<BitVector*> dominance_frontier; |
5580 flow_graph->ComputeDominators(&dominance_frontier); | 5589 flow_graph->ComputeDominators(&dominance_frontier); |
5581 } | 5590 } |
5582 } | 5591 } |
5583 | 5592 |
5584 | 5593 |
5585 } // namespace dart | 5594 } // namespace dart |
OLD | NEW |