| 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 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 } else if (type->Is(Type::Function())) { | 835 } else if (type->Is(Type::Function())) { |
| 836 return Replace(jsgraph()->Constant(f->function_string())); | 836 return Replace(jsgraph()->Constant(f->function_string())); |
| 837 } else if (type->IsHeapConstant()) { | 837 } else if (type->IsHeapConstant()) { |
| 838 return Replace(jsgraph()->Constant( | 838 return Replace(jsgraph()->Constant( |
| 839 Object::TypeOf(isolate(), type->AsHeapConstant()->Value()))); | 839 Object::TypeOf(isolate(), type->AsHeapConstant()->Value()))); |
| 840 } | 840 } |
| 841 | 841 |
| 842 return NoChange(); | 842 return NoChange(); |
| 843 } | 843 } |
| 844 | 844 |
| 845 Reduction JSTypedLowering::ReduceJSEqualTypeOf(Node* node) { | |
| 846 Node* input; | |
| 847 Handle<String> type; | |
| 848 HeapObjectBinopMatcher m(node); | |
| 849 if (m.left().IsJSTypeOf() && m.right().HasValue() && | |
| 850 m.right().Value()->IsString()) { | |
| 851 input = m.left().InputAt(0); | |
| 852 type = Handle<String>::cast(m.right().Value()); | |
| 853 } else if (m.right().IsJSTypeOf() && m.left().HasValue() && | |
| 854 m.left().Value()->IsString()) { | |
| 855 input = m.right().InputAt(0); | |
| 856 type = Handle<String>::cast(m.left().Value()); | |
| 857 } else { | |
| 858 return NoChange(); | |
| 859 } | |
| 860 Node* value; | |
| 861 if (String::Equals(type, factory()->boolean_string())) { | |
| 862 value = | |
| 863 graph()->NewNode(common()->Select(MachineRepresentation::kTagged), | |
| 864 graph()->NewNode(simplified()->ReferenceEqual(), input, | |
| 865 jsgraph()->TrueConstant()), | |
| 866 jsgraph()->TrueConstant(), | |
| 867 graph()->NewNode(simplified()->ReferenceEqual(), input, | |
| 868 jsgraph()->FalseConstant())); | |
| 869 } else if (String::Equals(type, factory()->function_string())) { | |
| 870 value = graph()->NewNode(simplified()->ObjectIsDetectableCallable(), input); | |
| 871 } else if (String::Equals(type, factory()->number_string())) { | |
| 872 value = graph()->NewNode(simplified()->ObjectIsNumber(), input); | |
| 873 } else if (String::Equals(type, factory()->object_string())) { | |
| 874 value = graph()->NewNode( | |
| 875 common()->Select(MachineRepresentation::kTagged), | |
| 876 graph()->NewNode(simplified()->ObjectIsNonCallable(), input), | |
| 877 jsgraph()->TrueConstant(), | |
| 878 graph()->NewNode(simplified()->ReferenceEqual(), input, | |
| 879 jsgraph()->NullConstant())); | |
| 880 } else if (String::Equals(type, factory()->string_string())) { | |
| 881 value = graph()->NewNode(simplified()->ObjectIsString(), input); | |
| 882 } else if (String::Equals(type, factory()->symbol_string())) { | |
| 883 value = graph()->NewNode(simplified()->ObjectIsSymbol(), input); | |
| 884 } else if (String::Equals(type, factory()->undefined_string())) { | |
| 885 value = graph()->NewNode( | |
| 886 common()->Select(MachineRepresentation::kTagged), | |
| 887 graph()->NewNode(simplified()->ReferenceEqual(), input, | |
| 888 jsgraph()->NullConstant()), | |
| 889 jsgraph()->FalseConstant(), | |
| 890 graph()->NewNode(simplified()->ObjectIsUndetectable(), input)); | |
| 891 } else { | |
| 892 return NoChange(); | |
| 893 } | |
| 894 ReplaceWithValue(node, value); | |
| 895 return Replace(value); | |
| 896 } | |
| 897 | |
| 898 Reduction JSTypedLowering::ReduceJSEqual(Node* node) { | 845 Reduction JSTypedLowering::ReduceJSEqual(Node* node) { |
| 899 Reduction const reduction = ReduceJSEqualTypeOf(node); | |
| 900 if (reduction.Changed()) return reduction; | |
| 901 | |
| 902 JSBinopReduction r(this, node); | 846 JSBinopReduction r(this, node); |
| 903 | 847 |
| 904 if (r.BothInputsAre(Type::UniqueName())) { | 848 if (r.BothInputsAre(Type::UniqueName())) { |
| 905 return r.ChangeToPureOperator(simplified()->ReferenceEqual()); | 849 return r.ChangeToPureOperator(simplified()->ReferenceEqual()); |
| 906 } | 850 } |
| 907 if (r.IsInternalizedStringCompareOperation()) { | 851 if (r.IsInternalizedStringCompareOperation()) { |
| 908 r.CheckInputsToInternalizedString(); | 852 r.CheckInputsToInternalizedString(); |
| 909 return r.ChangeToPureOperator(simplified()->ReferenceEqual()); | 853 return r.ChangeToPureOperator(simplified()->ReferenceEqual()); |
| 910 } | 854 } |
| 911 if (r.BothInputsAre(Type::String())) { | 855 if (r.BothInputsAre(Type::String())) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 // For values with canonical representation (i.e. neither String, nor | 898 // For values with canonical representation (i.e. neither String, nor |
| 955 // Number) an empty type intersection means the values cannot be strictly | 899 // Number) an empty type intersection means the values cannot be strictly |
| 956 // equal. | 900 // equal. |
| 957 if (!r.left_type()->Maybe(r.right_type())) { | 901 if (!r.left_type()->Maybe(r.right_type())) { |
| 958 Node* replacement = jsgraph()->FalseConstant(); | 902 Node* replacement = jsgraph()->FalseConstant(); |
| 959 ReplaceWithValue(node, replacement); | 903 ReplaceWithValue(node, replacement); |
| 960 return Replace(replacement); | 904 return Replace(replacement); |
| 961 } | 905 } |
| 962 } | 906 } |
| 963 | 907 |
| 964 Reduction const reduction = ReduceJSEqualTypeOf(node); | |
| 965 if (reduction.Changed()) return reduction; | |
| 966 | |
| 967 if (r.BothInputsAre(Type::Unique())) { | 908 if (r.BothInputsAre(Type::Unique())) { |
| 968 return r.ChangeToPureOperator(simplified()->ReferenceEqual()); | 909 return r.ChangeToPureOperator(simplified()->ReferenceEqual()); |
| 969 } | 910 } |
| 970 if (r.OneInputIs(pointer_comparable_type_)) { | 911 if (r.OneInputIs(pointer_comparable_type_)) { |
| 971 return r.ChangeToPureOperator(simplified()->ReferenceEqual()); | 912 return r.ChangeToPureOperator(simplified()->ReferenceEqual()); |
| 972 } | 913 } |
| 973 if (r.IsInternalizedStringCompareOperation()) { | 914 if (r.IsInternalizedStringCompareOperation()) { |
| 974 r.CheckInputsToInternalizedString(); | 915 r.CheckInputsToInternalizedString(); |
| 975 return r.ChangeToPureOperator(simplified()->ReferenceEqual()); | 916 return r.ChangeToPureOperator(simplified()->ReferenceEqual()); |
| 976 } | 917 } |
| (...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2448 } | 2389 } |
| 2449 | 2390 |
| 2450 | 2391 |
| 2451 CompilationDependencies* JSTypedLowering::dependencies() const { | 2392 CompilationDependencies* JSTypedLowering::dependencies() const { |
| 2452 return dependencies_; | 2393 return dependencies_; |
| 2453 } | 2394 } |
| 2454 | 2395 |
| 2455 } // namespace compiler | 2396 } // namespace compiler |
| 2456 } // namespace internal | 2397 } // namespace internal |
| 2457 } // namespace v8 | 2398 } // namespace v8 |
| OLD | NEW |