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/code-factory.h" | 5 #include "src/code-factory.h" |
6 #include "src/compilation-dependencies.h" | 6 #include "src/compilation-dependencies.h" |
7 #include "src/compiler/access-builder.h" | 7 #include "src/compiler/access-builder.h" |
8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
9 #include "src/compiler/js-typed-lowering.h" | 9 #include "src/compiler/js-typed-lowering.h" |
10 #include "src/compiler/linkage.h" | 10 #include "src/compiler/linkage.h" |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 Node* vfalse = NodeProperties::GetValueInput(input, 2); | 773 Node* vfalse = NodeProperties::GetValueInput(input, 2); |
774 Type* vfalse_type = NodeProperties::GetType(vfalse); | 774 Type* vfalse_type = NodeProperties::GetType(vfalse); |
775 if (vtrue_type->Is(Type::Undefined()) && vfalse_type->Is(Type::Number())) { | 775 if (vtrue_type->Is(Type::Undefined()) && vfalse_type->Is(Type::Number())) { |
776 if (check->opcode() == IrOpcode::kNumberIsHoleNaN && | 776 if (check->opcode() == IrOpcode::kNumberIsHoleNaN && |
777 check->InputAt(0) == vfalse) { | 777 check->InputAt(0) == vfalse) { |
778 // JSToNumber(Select(NumberIsHoleNaN(x), y:undefined, x:number)) => x | 778 // JSToNumber(Select(NumberIsHoleNaN(x), y:undefined, x:number)) => x |
779 return Replace(vfalse); | 779 return Replace(vfalse); |
780 } | 780 } |
781 } | 781 } |
782 } | 782 } |
783 // Check if we have a cached conversion. | 783 // Try constant-folding of JSToNumber with constant inputs. |
784 Type* input_type = NodeProperties::GetType(input); | 784 Type* input_type = NodeProperties::GetType(input); |
| 785 if (input_type->IsConstant()) { |
| 786 Handle<Object> input_value = input_type->AsConstant()->Value(); |
| 787 if (input_value->IsString()) { |
| 788 return Replace(jsgraph()->Constant( |
| 789 String::ToNumber(Handle<String>::cast(input_value)))); |
| 790 } else if (input_value->IsOddball()) { |
| 791 return Replace(jsgraph()->Constant( |
| 792 Oddball::ToNumber(Handle<Oddball>::cast(input_value)))); |
| 793 } |
| 794 } |
785 if (input_type->Is(Type::Number())) { | 795 if (input_type->Is(Type::Number())) { |
786 // JSToNumber(x:number) => x | 796 // JSToNumber(x:number) => x |
787 return Changed(input); | 797 return Changed(input); |
788 } | 798 } |
789 if (input_type->Is(Type::Undefined())) { | 799 if (input_type->Is(Type::Undefined())) { |
790 // JSToNumber(undefined) => #NaN | 800 // JSToNumber(undefined) => #NaN |
791 return Replace(jsgraph()->NaNConstant()); | 801 return Replace(jsgraph()->NaNConstant()); |
792 } | 802 } |
793 if (input_type->Is(Type::Null())) { | 803 if (input_type->Is(Type::Null())) { |
794 // JSToNumber(null) => #0 | 804 // JSToNumber(null) => #0 |
(...skipping 1876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2671 } | 2681 } |
2672 | 2682 |
2673 | 2683 |
2674 CompilationDependencies* JSTypedLowering::dependencies() const { | 2684 CompilationDependencies* JSTypedLowering::dependencies() const { |
2675 return dependencies_; | 2685 return dependencies_; |
2676 } | 2686 } |
2677 | 2687 |
2678 } // namespace compiler | 2688 } // namespace compiler |
2679 } // namespace internal | 2689 } // namespace internal |
2680 } // namespace v8 | 2690 } // namespace v8 |
OLD | NEW |