| 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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 converted = new UnboxDoubleInstr(use->CopyWithType(), deopt_id); | 367 converted = new UnboxDoubleInstr(use->CopyWithType(), deopt_id); |
| 368 } | 368 } |
| 369 } else if ((from == kTagged) && (to == kUnboxedFloat32x4)) { | 369 } else if ((from == kTagged) && (to == kUnboxedFloat32x4)) { |
| 370 ASSERT((deopt_target != NULL) || | 370 ASSERT((deopt_target != NULL) || |
| 371 (use->Type()->ToCid() == kFloat32x4Cid)); | 371 (use->Type()->ToCid() == kFloat32x4Cid)); |
| 372 const intptr_t deopt_id = (deopt_target != NULL) ? | 372 const intptr_t deopt_id = (deopt_target != NULL) ? |
| 373 deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId; | 373 deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId; |
| 374 converted = new UnboxFloat32x4Instr(use->CopyWithType(), deopt_id); | 374 converted = new UnboxFloat32x4Instr(use->CopyWithType(), deopt_id); |
| 375 } else if ((from == kUnboxedFloat32x4) && (to == kTagged)) { | 375 } else if ((from == kUnboxedFloat32x4) && (to == kTagged)) { |
| 376 converted = new BoxFloat32x4Instr(use->CopyWithType()); | 376 converted = new BoxFloat32x4Instr(use->CopyWithType()); |
| 377 } else if ((from == kTagged) && (to == kUnboxedUint32x4)) { |
| 378 ASSERT((deopt_target != NULL) || (use->Type()->ToCid() == kUint32x4Cid)); |
| 379 const intptr_t deopt_id = (deopt_target != NULL) ? |
| 380 deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId; |
| 381 converted = new UnboxUint32x4Instr(use->CopyWithType(), deopt_id); |
| 382 } else if ((from == kUnboxedUint32x4) && (to == kTagged)) { |
| 383 converted = new BoxUint32x4Instr(use->CopyWithType()); |
| 377 } | 384 } |
| 378 ASSERT(converted != NULL); | 385 ASSERT(converted != NULL); |
| 379 use->BindTo(converted); | 386 use->BindTo(converted); |
| 380 InsertBefore(insert_before, converted, use->instruction()->env(), | 387 InsertBefore(insert_before, converted, use->instruction()->env(), |
| 381 Definition::kValue); | 388 Definition::kValue); |
| 382 } | 389 } |
| 383 | 390 |
| 384 | 391 |
| 385 void FlowGraphOptimizer::InsertConversionsFor(Definition* def) { | 392 void FlowGraphOptimizer::InsertConversionsFor(Definition* def) { |
| 386 const Representation from_rep = def->representation(); | 393 const Representation from_rep = def->representation(); |
| (...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1722 return BuildByteArrayViewStore( | 1729 return BuildByteArrayViewStore( |
| 1723 call, class_ids[0], kTypedDataFloat64ArrayCid); | 1730 call, class_ids[0], kTypedDataFloat64ArrayCid); |
| 1724 case MethodRecognizer::kByteArrayBaseSetFloat32x4: | 1731 case MethodRecognizer::kByteArrayBaseSetFloat32x4: |
| 1725 return BuildByteArrayViewStore( | 1732 return BuildByteArrayViewStore( |
| 1726 call, class_ids[0], kTypedDataFloat32x4ArrayCid); | 1733 call, class_ids[0], kTypedDataFloat32x4ArrayCid); |
| 1727 default: | 1734 default: |
| 1728 // Unsupported method. | 1735 // Unsupported method. |
| 1729 return false; | 1736 return false; |
| 1730 } | 1737 } |
| 1731 } | 1738 } |
| 1739 |
| 1740 if ((class_ids[0] == kFloat32x4Cid) && (ic_data.NumberOfChecks() == 1)) { |
| 1741 switch (recognized_kind) { |
| 1742 case MethodRecognizer::kFloat32x4Equal: |
| 1743 case MethodRecognizer::kFloat32x4GreaterThan: |
| 1744 case MethodRecognizer::kFloat32x4GreaterThanOrEqual: |
| 1745 case MethodRecognizer::kFloat32x4LessThan: |
| 1746 case MethodRecognizer::kFloat32x4LessThanOrEqual: |
| 1747 case MethodRecognizer::kFloat32x4NotEqual: { |
| 1748 Definition* left = call->ArgumentAt(0); |
| 1749 Definition* right = call->ArgumentAt(1); |
| 1750 // Type check left. |
| 1751 AddCheckClass(left, |
| 1752 ICData::ZoneHandle( |
| 1753 call->ic_data()->AsUnaryClassChecksForArgNr(0)), |
| 1754 call->deopt_id(), |
| 1755 call->env(), |
| 1756 call); |
| 1757 // Replace call. |
| 1758 Float32x4ComparisonInstr* cmp = |
| 1759 new Float32x4ComparisonInstr(recognized_kind, new Value(left), |
| 1760 new Value(right), call); |
| 1761 ReplaceCall(call, cmp); |
| 1762 return true; |
| 1763 } |
| 1764 default: |
| 1765 return false; |
| 1766 } |
| 1767 } |
| 1732 return false; | 1768 return false; |
| 1733 } | 1769 } |
| 1734 | 1770 |
| 1735 | 1771 |
| 1736 bool FlowGraphOptimizer::BuildByteArrayViewLoad( | 1772 bool FlowGraphOptimizer::BuildByteArrayViewLoad( |
| 1737 InstanceCallInstr* call, | 1773 InstanceCallInstr* call, |
| 1738 intptr_t receiver_cid, | 1774 intptr_t receiver_cid, |
| 1739 intptr_t view_cid) { | 1775 intptr_t view_cid) { |
| 1740 Definition* array = call->ArgumentAt(0); | 1776 Definition* array = call->ArgumentAt(0); |
| 1741 PrepareByteArrayViewOp(call, receiver_cid, view_cid, &array); | 1777 PrepareByteArrayViewOp(call, receiver_cid, view_cid, &array); |
| (...skipping 3017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4759 void ConstantPropagator::VisitFloat32x4Zero(Float32x4ZeroInstr* instr) { | 4795 void ConstantPropagator::VisitFloat32x4Zero(Float32x4ZeroInstr* instr) { |
| 4760 SetValue(instr, non_constant_); | 4796 SetValue(instr, non_constant_); |
| 4761 } | 4797 } |
| 4762 | 4798 |
| 4763 | 4799 |
| 4764 void ConstantPropagator::VisitFloat32x4Splat(Float32x4SplatInstr* instr) { | 4800 void ConstantPropagator::VisitFloat32x4Splat(Float32x4SplatInstr* instr) { |
| 4765 SetValue(instr, non_constant_); | 4801 SetValue(instr, non_constant_); |
| 4766 } | 4802 } |
| 4767 | 4803 |
| 4768 | 4804 |
| 4805 void ConstantPropagator::VisitFloat32x4Comparison( |
| 4806 Float32x4ComparisonInstr* instr) { |
| 4807 SetValue(instr, non_constant_); |
| 4808 } |
| 4809 |
| 4810 |
| 4769 void ConstantPropagator::VisitMathSqrt(MathSqrtInstr* instr) { | 4811 void ConstantPropagator::VisitMathSqrt(MathSqrtInstr* instr) { |
| 4770 const Object& value = instr->value()->definition()->constant_value(); | 4812 const Object& value = instr->value()->definition()->constant_value(); |
| 4771 if (IsNonConstant(value)) { | 4813 if (IsNonConstant(value)) { |
| 4772 SetValue(instr, non_constant_); | 4814 SetValue(instr, non_constant_); |
| 4773 } else if (IsConstant(value)) { | 4815 } else if (IsConstant(value)) { |
| 4774 // TODO(kmillikin): Handle sqrt. | 4816 // TODO(kmillikin): Handle sqrt. |
| 4775 SetValue(instr, non_constant_); | 4817 SetValue(instr, non_constant_); |
| 4776 } | 4818 } |
| 4777 } | 4819 } |
| 4778 | 4820 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4814 const Object& value = instr->value()->definition()->constant_value(); | 4856 const Object& value = instr->value()->definition()->constant_value(); |
| 4815 if (IsNonConstant(value)) { | 4857 if (IsNonConstant(value)) { |
| 4816 SetValue(instr, non_constant_); | 4858 SetValue(instr, non_constant_); |
| 4817 } else if (IsConstant(value)) { | 4859 } else if (IsConstant(value)) { |
| 4818 // TODO(kmillikin): Handle conversion. | 4860 // TODO(kmillikin): Handle conversion. |
| 4819 SetValue(instr, non_constant_); | 4861 SetValue(instr, non_constant_); |
| 4820 } | 4862 } |
| 4821 } | 4863 } |
| 4822 | 4864 |
| 4823 | 4865 |
| 4866 void ConstantPropagator::VisitUnboxUint32x4(UnboxUint32x4Instr* instr) { |
| 4867 const Object& value = instr->value()->definition()->constant_value(); |
| 4868 if (IsNonConstant(value)) { |
| 4869 SetValue(instr, non_constant_); |
| 4870 } else if (IsConstant(value)) { |
| 4871 // TODO(kmillikin): Handle conversion. |
| 4872 SetValue(instr, non_constant_); |
| 4873 } |
| 4874 } |
| 4875 |
| 4876 |
| 4877 void ConstantPropagator::VisitBoxUint32x4(BoxUint32x4Instr* instr) { |
| 4878 const Object& value = instr->value()->definition()->constant_value(); |
| 4879 if (IsNonConstant(value)) { |
| 4880 SetValue(instr, non_constant_); |
| 4881 } else if (IsConstant(value)) { |
| 4882 // TODO(kmillikin): Handle conversion. |
| 4883 SetValue(instr, non_constant_); |
| 4884 } |
| 4885 } |
| 4886 |
| 4887 |
| 4824 void ConstantPropagator::Analyze() { | 4888 void ConstantPropagator::Analyze() { |
| 4825 GraphEntryInstr* entry = graph_->graph_entry(); | 4889 GraphEntryInstr* entry = graph_->graph_entry(); |
| 4826 reachable_->Add(entry->preorder_number()); | 4890 reachable_->Add(entry->preorder_number()); |
| 4827 block_worklist_.Add(entry); | 4891 block_worklist_.Add(entry); |
| 4828 | 4892 |
| 4829 while (true) { | 4893 while (true) { |
| 4830 if (block_worklist_.is_empty()) { | 4894 if (block_worklist_.is_empty()) { |
| 4831 if (definition_worklist_.is_empty()) break; | 4895 if (definition_worklist_.is_empty()) break; |
| 4832 Definition* definition = definition_worklist_.RemoveLast(); | 4896 Definition* definition = definition_worklist_.RemoveLast(); |
| 4833 definition_marks_->Remove(definition->ssa_temp_index()); | 4897 definition_marks_->Remove(definition->ssa_temp_index()); |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5383 if (changed) { | 5447 if (changed) { |
| 5384 // We may have changed the block order and the dominator tree. | 5448 // We may have changed the block order and the dominator tree. |
| 5385 flow_graph->DiscoverBlocks(); | 5449 flow_graph->DiscoverBlocks(); |
| 5386 GrowableArray<BitVector*> dominance_frontier; | 5450 GrowableArray<BitVector*> dominance_frontier; |
| 5387 flow_graph->ComputeDominators(&dominance_frontier); | 5451 flow_graph->ComputeDominators(&dominance_frontier); |
| 5388 } | 5452 } |
| 5389 } | 5453 } |
| 5390 | 5454 |
| 5391 | 5455 |
| 5392 } // namespace dart | 5456 } // namespace dart |
| OLD | NEW |