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/cpu.h" | 9 #include "vm/cpu.h" |
10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
(...skipping 8232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8243 } | 8243 } |
8244 | 8244 |
8245 | 8245 |
8246 void ConstantPropagator::HandleBinaryOp(Definition* instr, | 8246 void ConstantPropagator::HandleBinaryOp(Definition* instr, |
8247 Token::Kind op_kind, | 8247 Token::Kind op_kind, |
8248 const Value& left_val, | 8248 const Value& left_val, |
8249 const Value& right_val) { | 8249 const Value& right_val) { |
8250 const Object& left = left_val.definition()->constant_value(); | 8250 const Object& left = left_val.definition()->constant_value(); |
8251 const Object& right = right_val.definition()->constant_value(); | 8251 const Object& right = right_val.definition()->constant_value(); |
8252 if (IsNonConstant(left) || IsNonConstant(right)) { | 8252 if (IsNonConstant(left) || IsNonConstant(right)) { |
8253 // TODO(srdjan): Add arithemtic simplifications, e.g, add with 0. | 8253 // TODO(srdjan): Add arithmetic simplifications, e.g, add with 0. |
8254 SetValue(instr, non_constant_); | 8254 SetValue(instr, non_constant_); |
8255 } else if (IsConstant(left) && IsConstant(right)) { | 8255 } else if (IsConstant(left) && IsConstant(right)) { |
8256 if (left.IsInteger() && right.IsInteger()) { | 8256 if (left.IsInteger() && right.IsInteger()) { |
8257 const Integer& left_int = Integer::Cast(left); | 8257 const Integer& left_int = Integer::Cast(left); |
8258 const Integer& right_int = Integer::Cast(right); | 8258 const Integer& right_int = Integer::Cast(right); |
8259 switch (op_kind) { | 8259 switch (op_kind) { |
8260 case Token::kTRUNCDIV: | 8260 case Token::kTRUNCDIV: |
8261 case Token::kMOD: | 8261 case Token::kMOD: |
8262 // Check right value for zero. | 8262 // Check right value for zero. |
8263 if (right_int.AsInt64Value() == 0) { | 8263 if (right_int.AsInt64Value() == 0) { |
8264 SetValue(instr, non_constant_); | 8264 SetValue(instr, non_constant_); |
8265 break; | 8265 break; |
8266 } | 8266 } |
8267 // Fall through. | 8267 // Fall through. |
8268 case Token::kADD: | 8268 case Token::kADD: |
8269 case Token::kSUB: | 8269 case Token::kSUB: |
8270 case Token::kMUL: { | 8270 case Token::kMUL: { |
8271 Instance& result = Integer::ZoneHandle(I, | 8271 Instance& result = Integer::ZoneHandle(I, |
8272 left_int.ArithmeticOp(op_kind, right_int)); | 8272 left_int.ArithmeticOp(op_kind, right_int)); |
| 8273 if (result.IsNull()) { |
| 8274 // TODO(regis): A bigint operation is required. Invoke dart? |
| 8275 // Punt for now. |
| 8276 SetValue(instr, non_constant_); |
| 8277 break; |
| 8278 } |
8273 result = result.CheckAndCanonicalize(NULL); | 8279 result = result.CheckAndCanonicalize(NULL); |
8274 ASSERT(!result.IsNull()); | 8280 ASSERT(!result.IsNull()); |
8275 SetValue(instr, result); | 8281 SetValue(instr, result); |
8276 break; | 8282 break; |
8277 } | 8283 } |
8278 case Token::kSHL: | 8284 case Token::kSHL: |
8279 case Token::kSHR: | 8285 case Token::kSHR: |
8280 if (left.IsSmi() && right.IsSmi()) { | 8286 if (left.IsSmi() && right.IsSmi()) { |
8281 Instance& result = Integer::ZoneHandle(I, | 8287 Instance& result = Integer::ZoneHandle(I, |
8282 Smi::Cast(left_int).ShiftOp(op_kind, Smi::Cast(right_int))); | 8288 Smi::Cast(left_int).ShiftOp(op_kind, Smi::Cast(right_int))); |
| 8289 if (result.IsNull()) { |
| 8290 // TODO(regis): A bigint operation is required. Invoke dart? |
| 8291 // Punt for now. |
| 8292 SetValue(instr, non_constant_); |
| 8293 break; |
| 8294 } |
8283 result = result.CheckAndCanonicalize(NULL); | 8295 result = result.CheckAndCanonicalize(NULL); |
8284 ASSERT(!result.IsNull()); | 8296 ASSERT(!result.IsNull()); |
8285 SetValue(instr, result); | 8297 SetValue(instr, result); |
8286 } else { | 8298 } else { |
8287 SetValue(instr, non_constant_); | 8299 SetValue(instr, non_constant_); |
8288 } | 8300 } |
8289 break; | 8301 break; |
8290 case Token::kBIT_AND: | 8302 case Token::kBIT_AND: |
8291 case Token::kBIT_OR: | 8303 case Token::kBIT_OR: |
8292 case Token::kBIT_XOR: { | 8304 case Token::kBIT_XOR: { |
(...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10040 | 10052 |
10041 // Insert materializations at environment uses. | 10053 // Insert materializations at environment uses. |
10042 for (intptr_t i = 0; i < exits_collector_.exits().length(); i++) { | 10054 for (intptr_t i = 0; i < exits_collector_.exits().length(); i++) { |
10043 CreateMaterializationAt( | 10055 CreateMaterializationAt( |
10044 exits_collector_.exits()[i], alloc, alloc->cls(), *slots); | 10056 exits_collector_.exits()[i], alloc, alloc->cls(), *slots); |
10045 } | 10057 } |
10046 } | 10058 } |
10047 | 10059 |
10048 | 10060 |
10049 } // namespace dart | 10061 } // namespace dart |
OLD | NEW |