| 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/constant_propagator.h" | 5 #include "vm/constant_propagator.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/flow_graph_builder.h" | 8 #include "vm/flow_graph_builder.h" |
| 9 #include "vm/flow_graph_compiler.h" | 9 #include "vm/flow_graph_compiler.h" |
| 10 #include "vm/flow_graph_range_analysis.h" | 10 #include "vm/flow_graph_range_analysis.h" |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 Definition* def = instr->value()->definition(); | 674 Definition* def = instr->value()->definition(); |
| 675 const Object& value = def->constant_value(); | 675 const Object& value = def->constant_value(); |
| 676 if (IsNonConstant(value)) { | 676 if (IsNonConstant(value)) { |
| 677 const AbstractType& checked_type = instr->type(); | 677 const AbstractType& checked_type = instr->type(); |
| 678 intptr_t value_cid = instr->value()->definition()->Type()->ToCid(); | 678 intptr_t value_cid = instr->value()->definition()->Type()->ToCid(); |
| 679 Representation rep = def->representation(); | 679 Representation rep = def->representation(); |
| 680 if ((checked_type.IsFloat32x4Type() && (rep == kUnboxedFloat32x4)) || | 680 if ((checked_type.IsFloat32x4Type() && (rep == kUnboxedFloat32x4)) || |
| 681 (checked_type.IsInt32x4Type() && (rep == kUnboxedInt32x4)) || | 681 (checked_type.IsInt32x4Type() && (rep == kUnboxedInt32x4)) || |
| 682 (checked_type.IsDoubleType() && (rep == kUnboxedDouble) && | 682 (checked_type.IsDoubleType() && (rep == kUnboxedDouble) && |
| 683 FlowGraphCompiler::SupportsUnboxedDoubles()) || | 683 FlowGraphCompiler::SupportsUnboxedDoubles()) || |
| 684 (checked_type.IsIntType() && (rep == kUnboxedMint))) { | 684 (checked_type.IsIntType() && (rep == kUnboxedInt64))) { |
| 685 // Ensure that compile time type matches representation. | 685 // Ensure that compile time type matches representation. |
| 686 ASSERT(((rep == kUnboxedFloat32x4) && (value_cid == kFloat32x4Cid)) || | 686 ASSERT(((rep == kUnboxedFloat32x4) && (value_cid == kFloat32x4Cid)) || |
| 687 ((rep == kUnboxedInt32x4) && (value_cid == kInt32x4Cid)) || | 687 ((rep == kUnboxedInt32x4) && (value_cid == kInt32x4Cid)) || |
| 688 ((rep == kUnboxedDouble) && (value_cid == kDoubleCid)) || | 688 ((rep == kUnboxedDouble) && (value_cid == kDoubleCid)) || |
| 689 ((rep == kUnboxedMint) && (value_cid == kMintCid))); | 689 ((rep == kUnboxedInt64) && (value_cid == kMintCid))); |
| 690 // The representation guarantees the type check to be true. | 690 // The representation guarantees the type check to be true. |
| 691 SetValue(instr, Bool::True()); | 691 SetValue(instr, Bool::True()); |
| 692 } else { | 692 } else { |
| 693 SetValue(instr, non_constant_); | 693 SetValue(instr, non_constant_); |
| 694 } | 694 } |
| 695 } else if (IsConstant(value)) { | 695 } else if (IsConstant(value)) { |
| 696 if (value.IsInstance()) { | 696 if (value.IsInstance()) { |
| 697 const Instance& instance = Instance::Cast(value); | 697 const Instance& instance = Instance::Cast(value); |
| 698 const AbstractType& checked_type = instr->type(); | 698 const AbstractType& checked_type = instr->type(); |
| 699 if (instr->instantiator_type_arguments()->BindsToConstantNull() && | 699 if (instr->instantiator_type_arguments()->BindsToConstantNull() && |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 } | 899 } |
| 900 | 900 |
| 901 void ConstantPropagator::VisitBinaryUint32Op(BinaryUint32OpInstr* instr) { | 901 void ConstantPropagator::VisitBinaryUint32Op(BinaryUint32OpInstr* instr) { |
| 902 VisitBinaryIntegerOp(instr); | 902 VisitBinaryIntegerOp(instr); |
| 903 } | 903 } |
| 904 | 904 |
| 905 void ConstantPropagator::VisitShiftUint32Op(ShiftUint32OpInstr* instr) { | 905 void ConstantPropagator::VisitShiftUint32Op(ShiftUint32OpInstr* instr) { |
| 906 VisitBinaryIntegerOp(instr); | 906 VisitBinaryIntegerOp(instr); |
| 907 } | 907 } |
| 908 | 908 |
| 909 void ConstantPropagator::VisitBinaryMintOp(BinaryMintOpInstr* instr) { | 909 void ConstantPropagator::VisitBinaryInt64Op(BinaryInt64OpInstr* instr) { |
| 910 VisitBinaryIntegerOp(instr); | 910 VisitBinaryIntegerOp(instr); |
| 911 } | 911 } |
| 912 | 912 |
| 913 void ConstantPropagator::VisitShiftMintOp(ShiftMintOpInstr* instr) { | 913 void ConstantPropagator::VisitShiftInt64Op(ShiftInt64OpInstr* instr) { |
| 914 VisitBinaryIntegerOp(instr); | 914 VisitBinaryIntegerOp(instr); |
| 915 } | 915 } |
| 916 | 916 |
| 917 void ConstantPropagator::VisitBoxInt64(BoxInt64Instr* instr) { | 917 void ConstantPropagator::VisitBoxInt64(BoxInt64Instr* instr) { |
| 918 // TODO(kmillikin): Handle box operation. | 918 // TODO(kmillikin): Handle box operation. |
| 919 SetValue(instr, non_constant_); | 919 SetValue(instr, non_constant_); |
| 920 } | 920 } |
| 921 | 921 |
| 922 void ConstantPropagator::VisitUnboxInt64(UnboxInt64Instr* instr) { | 922 void ConstantPropagator::VisitUnboxInt64(UnboxInt64Instr* instr) { |
| 923 // TODO(kmillikin): Handle unbox operation. | 923 // TODO(kmillikin): Handle unbox operation. |
| 924 SetValue(instr, non_constant_); | 924 SetValue(instr, non_constant_); |
| 925 } | 925 } |
| 926 | 926 |
| 927 void ConstantPropagator::VisitUnaryIntegerOp(UnaryIntegerOpInstr* unary_op) { | 927 void ConstantPropagator::VisitUnaryIntegerOp(UnaryIntegerOpInstr* unary_op) { |
| 928 const Object& value = unary_op->value()->definition()->constant_value(); | 928 const Object& value = unary_op->value()->definition()->constant_value(); |
| 929 if (IsConstant(value) && value.IsInteger()) { | 929 if (IsConstant(value) && value.IsInteger()) { |
| 930 const Integer& value_int = Integer::Cast(value); | 930 const Integer& value_int = Integer::Cast(value); |
| 931 const Integer& result = Integer::Handle(Z, unary_op->Evaluate(value_int)); | 931 const Integer& result = Integer::Handle(Z, unary_op->Evaluate(value_int)); |
| 932 if (!result.IsNull()) { | 932 if (!result.IsNull()) { |
| 933 SetValue(unary_op, Integer::ZoneHandle(Z, result.raw())); | 933 SetValue(unary_op, Integer::ZoneHandle(Z, result.raw())); |
| 934 return; | 934 return; |
| 935 } | 935 } |
| 936 } | 936 } |
| 937 | 937 |
| 938 SetValue(unary_op, non_constant_); | 938 SetValue(unary_op, non_constant_); |
| 939 } | 939 } |
| 940 | 940 |
| 941 void ConstantPropagator::VisitUnaryMintOp(UnaryMintOpInstr* instr) { | 941 void ConstantPropagator::VisitUnaryInt64Op(UnaryInt64OpInstr* instr) { |
| 942 VisitUnaryIntegerOp(instr); | 942 VisitUnaryIntegerOp(instr); |
| 943 } | 943 } |
| 944 | 944 |
| 945 void ConstantPropagator::VisitUnarySmiOp(UnarySmiOpInstr* instr) { | 945 void ConstantPropagator::VisitUnarySmiOp(UnarySmiOpInstr* instr) { |
| 946 VisitUnaryIntegerOp(instr); | 946 VisitUnaryIntegerOp(instr); |
| 947 } | 947 } |
| 948 | 948 |
| 949 void ConstantPropagator::VisitUnaryDoubleOp(UnaryDoubleOpInstr* instr) { | 949 void ConstantPropagator::VisitUnaryDoubleOp(UnaryDoubleOpInstr* instr) { |
| 950 const Object& value = instr->value()->definition()->constant_value(); | 950 const Object& value = instr->value()->definition()->constant_value(); |
| 951 if (IsNonConstant(value)) { | 951 if (IsNonConstant(value)) { |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1577 GrowableArray<BitVector*> dominance_frontier; | 1577 GrowableArray<BitVector*> dominance_frontier; |
| 1578 graph_->ComputeDominators(&dominance_frontier); | 1578 graph_->ComputeDominators(&dominance_frontier); |
| 1579 | 1579 |
| 1580 if (FLAG_trace_constant_propagation && | 1580 if (FLAG_trace_constant_propagation && |
| 1581 FlowGraphPrinter::ShouldPrint(graph_->function())) { | 1581 FlowGraphPrinter::ShouldPrint(graph_->function())) { |
| 1582 FlowGraphPrinter::PrintGraph("After CP", graph_); | 1582 FlowGraphPrinter::PrintGraph("After CP", graph_); |
| 1583 } | 1583 } |
| 1584 } | 1584 } |
| 1585 | 1585 |
| 1586 } // namespace dart | 1586 } // namespace dart |
| OLD | NEW |