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 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 SetValue(instr, non_constant_); | 950 SetValue(instr, non_constant_); |
951 } | 951 } |
952 | 952 |
953 | 953 |
954 void ConstantPropagator::VisitUnboxInt64(UnboxInt64Instr* instr) { | 954 void ConstantPropagator::VisitUnboxInt64(UnboxInt64Instr* instr) { |
955 // TODO(kmillikin): Handle unbox operation. | 955 // TODO(kmillikin): Handle unbox operation. |
956 SetValue(instr, non_constant_); | 956 SetValue(instr, non_constant_); |
957 } | 957 } |
958 | 958 |
959 | 959 |
| 960 void ConstantPropagator::VisitUnaryIntegerOp(UnaryIntegerOpInstr* unary_op) { |
| 961 const Object& value = unary_op->value()->definition()->constant_value(); |
| 962 if (IsConstant(value) && value.IsInteger()) { |
| 963 const Integer& value_int = Integer::Cast(value); |
| 964 const Integer& result = |
| 965 Integer::Handle(I, unary_op->Evaluate(value_int)); |
| 966 if (!result.IsNull()) { |
| 967 SetValue(unary_op, Integer::ZoneHandle(I, result.raw())); |
| 968 return; |
| 969 } |
| 970 } |
| 971 |
| 972 SetValue(unary_op, non_constant_); |
| 973 } |
| 974 |
| 975 |
960 void ConstantPropagator::VisitUnaryMintOp(UnaryMintOpInstr* instr) { | 976 void ConstantPropagator::VisitUnaryMintOp(UnaryMintOpInstr* instr) { |
961 // TODO(kmillikin): Handle unary operations. | 977 VisitUnaryIntegerOp(instr); |
962 SetValue(instr, non_constant_); | |
963 } | 978 } |
964 | 979 |
965 | 980 |
966 void ConstantPropagator::VisitUnarySmiOp(UnarySmiOpInstr* instr) { | 981 void ConstantPropagator::VisitUnarySmiOp(UnarySmiOpInstr* instr) { |
967 const Object& value = instr->value()->definition()->constant_value(); | 982 VisitUnaryIntegerOp(instr); |
968 if (IsNonConstant(value)) { | |
969 SetValue(instr, non_constant_); | |
970 } else if (IsConstant(value)) { | |
971 // TODO(kmillikin): Handle unary operations. | |
972 SetValue(instr, non_constant_); | |
973 } | |
974 } | 983 } |
975 | 984 |
976 | 985 |
977 void ConstantPropagator::VisitUnaryDoubleOp(UnaryDoubleOpInstr* instr) { | 986 void ConstantPropagator::VisitUnaryDoubleOp(UnaryDoubleOpInstr* instr) { |
978 const Object& value = instr->value()->definition()->constant_value(); | 987 const Object& value = instr->value()->definition()->constant_value(); |
979 if (IsNonConstant(value)) { | 988 if (IsNonConstant(value)) { |
980 SetValue(instr, non_constant_); | 989 SetValue(instr, non_constant_); |
981 } else if (IsConstant(value)) { | 990 } else if (IsConstant(value)) { |
982 // TODO(kmillikin): Handle unary operations. | 991 // TODO(kmillikin): Handle unary operations. |
983 SetValue(instr, non_constant_); | 992 SetValue(instr, non_constant_); |
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1653 graph_->ComputeDominators(&dominance_frontier); | 1662 graph_->ComputeDominators(&dominance_frontier); |
1654 | 1663 |
1655 if (FLAG_trace_constant_propagation) { | 1664 if (FLAG_trace_constant_propagation) { |
1656 OS::Print("\n==== After constant propagation ====\n"); | 1665 OS::Print("\n==== After constant propagation ====\n"); |
1657 FlowGraphPrinter printer(*graph_); | 1666 FlowGraphPrinter printer(*graph_); |
1658 printer.PrintBlocks(); | 1667 printer.PrintBlocks(); |
1659 } | 1668 } |
1660 } | 1669 } |
1661 | 1670 |
1662 } // namespace dart | 1671 } // namespace dart |
OLD | NEW |