| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/js-typed-lowering.h" | 5 #include "src/compiler/js-typed-lowering.h" |
| 6 | 6 |
| 7 #include "src/ast/modules.h" | 7 #include "src/ast/modules.h" |
| 8 #include "src/builtins/builtins-utils.h" | 8 #include "src/builtins/builtins-utils.h" |
| 9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
| 10 #include "src/compilation-dependencies.h" | 10 #include "src/compilation-dependencies.h" |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 // - immediately put in type bounds for all new nodes | 481 // - immediately put in type bounds for all new nodes |
| 482 // - relax effects from generic but not-side-effecting operations | 482 // - relax effects from generic but not-side-effecting operations |
| 483 | 483 |
| 484 JSTypedLowering::JSTypedLowering(Editor* editor, | 484 JSTypedLowering::JSTypedLowering(Editor* editor, |
| 485 CompilationDependencies* dependencies, | 485 CompilationDependencies* dependencies, |
| 486 Flags flags, JSGraph* jsgraph, Zone* zone) | 486 Flags flags, JSGraph* jsgraph, Zone* zone) |
| 487 : AdvancedReducer(editor), | 487 : AdvancedReducer(editor), |
| 488 dependencies_(dependencies), | 488 dependencies_(dependencies), |
| 489 flags_(flags), | 489 flags_(flags), |
| 490 jsgraph_(jsgraph), | 490 jsgraph_(jsgraph), |
| 491 pointer_comparable_type_(Type::Union( | 491 empty_string_type_( |
| 492 Type::Oddball(), | 492 Type::HeapConstant(factory()->empty_string(), graph()->zone())), |
| 493 Type::Union( | 493 pointer_comparable_type_( |
| 494 Type::SymbolOrReceiver(), | 494 Type::Union(Type::Oddball(), |
| 495 Type::HeapConstant(factory()->empty_string(), graph()->zone()), | 495 Type::Union(Type::SymbolOrReceiver(), empty_string_type_, |
| 496 graph()->zone()), | 496 graph()->zone()), |
| 497 graph()->zone())), | 497 graph()->zone())), |
| 498 type_cache_(TypeCache::Get()) { | 498 type_cache_(TypeCache::Get()) { |
| 499 for (size_t k = 0; k < arraysize(shifted_int32_ranges_); ++k) { | 499 for (size_t k = 0; k < arraysize(shifted_int32_ranges_); ++k) { |
| 500 double min = kMinInt / (1 << k); | 500 double min = kMinInt / (1 << k); |
| 501 double max = kMaxInt / (1 << k); | 501 double max = kMaxInt / (1 << k); |
| 502 shifted_int32_ranges_[k] = Type::Range(min, max, graph()->zone()); | 502 shifted_int32_ranges_[k] = Type::Range(min, max, graph()->zone()); |
| 503 } | 503 } |
| 504 } | 504 } |
| 505 | 505 |
| 506 Reduction JSTypedLowering::ReduceSpeculativeNumberAdd(Node* node) { | 506 Reduction JSTypedLowering::ReduceSpeculativeNumberAdd(Node* node) { |
| 507 JSBinopReduction r(this, node); | 507 JSBinopReduction r(this, node); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 528 !(flags() & kDeoptimizationEnabled)) && | 528 !(flags() & kDeoptimizationEnabled)) && |
| 529 r.NeitherInputCanBe(Type::StringOrReceiver())) { | 529 r.NeitherInputCanBe(Type::StringOrReceiver())) { |
| 530 // JSAdd(x:-string, y:-string) => NumberAdd(ToNumber(x), ToNumber(y)) | 530 // JSAdd(x:-string, y:-string) => NumberAdd(ToNumber(x), ToNumber(y)) |
| 531 r.ConvertInputsToNumber(); | 531 r.ConvertInputsToNumber(); |
| 532 return r.ChangeToPureOperator(simplified()->NumberAdd(), Type::Number()); | 532 return r.ChangeToPureOperator(simplified()->NumberAdd(), Type::Number()); |
| 533 } | 533 } |
| 534 if (r.OneInputIs(Type::String())) { | 534 if (r.OneInputIs(Type::String())) { |
| 535 if (r.ShouldCreateConsString()) { | 535 if (r.ShouldCreateConsString()) { |
| 536 return ReduceCreateConsString(node); | 536 return ReduceCreateConsString(node); |
| 537 } | 537 } |
| 538 // Eliminate useless concatenation of empty string. |
| 539 if ((flags() & kDeoptimizationEnabled) && |
| 540 BinaryOperationHintOf(node->op()) == BinaryOperationHint::kString) { |
| 541 Node* effect = NodeProperties::GetEffectInput(node); |
| 542 Node* control = NodeProperties::GetControlInput(node); |
| 543 if (r.LeftInputIs(empty_string_type_)) { |
| 544 Node* value = effect = graph()->NewNode(simplified()->CheckString(), |
| 545 r.right(), effect, control); |
| 546 ReplaceWithValue(node, value, effect, control); |
| 547 return Replace(value); |
| 548 } else if (r.RightInputIs(empty_string_type_)) { |
| 549 Node* value = effect = graph()->NewNode(simplified()->CheckString(), |
| 550 r.left(), effect, control); |
| 551 ReplaceWithValue(node, value, effect, control); |
| 552 return Replace(value); |
| 553 } |
| 554 } |
| 538 StringAddFlags flags = STRING_ADD_CHECK_NONE; | 555 StringAddFlags flags = STRING_ADD_CHECK_NONE; |
| 539 if (!r.LeftInputIs(Type::String())) { | 556 if (!r.LeftInputIs(Type::String())) { |
| 540 flags = STRING_ADD_CONVERT_LEFT; | 557 flags = STRING_ADD_CONVERT_LEFT; |
| 541 } else if (!r.RightInputIs(Type::String())) { | 558 } else if (!r.RightInputIs(Type::String())) { |
| 542 flags = STRING_ADD_CONVERT_RIGHT; | 559 flags = STRING_ADD_CONVERT_RIGHT; |
| 543 } | 560 } |
| 544 Operator::Properties properties = node->op()->properties(); | 561 Operator::Properties properties = node->op()->properties(); |
| 545 if (r.NeitherInputCanBe(Type::Receiver())) { | 562 if (r.NeitherInputCanBe(Type::Receiver())) { |
| 546 // Both sides are already strings, so we know that the | 563 // Both sides are already strings, so we know that the |
| 547 // string addition will not cause any observable side | 564 // string addition will not cause any observable side |
| (...skipping 1727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2275 } | 2292 } |
| 2276 | 2293 |
| 2277 | 2294 |
| 2278 CompilationDependencies* JSTypedLowering::dependencies() const { | 2295 CompilationDependencies* JSTypedLowering::dependencies() const { |
| 2279 return dependencies_; | 2296 return dependencies_; |
| 2280 } | 2297 } |
| 2281 | 2298 |
| 2282 } // namespace compiler | 2299 } // namespace compiler |
| 2283 } // namespace internal | 2300 } // namespace internal |
| 2284 } // namespace v8 | 2301 } // namespace v8 |
| OLD | NEW |