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 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 return Replace(jsgraph()->Constant( | 865 return Replace(jsgraph()->Constant( |
866 Object::TypeOf(isolate(), type->AsHeapConstant()->Value()))); | 866 Object::TypeOf(isolate(), type->AsHeapConstant()->Value()))); |
867 } else if (type->IsOtherNumberConstant()) { | 867 } else if (type->IsOtherNumberConstant()) { |
868 return Replace(jsgraph()->Constant(f->number_string())); | 868 return Replace(jsgraph()->Constant(f->number_string())); |
869 } | 869 } |
870 | 870 |
871 return NoChange(); | 871 return NoChange(); |
872 } | 872 } |
873 | 873 |
874 Reduction JSTypedLowering::ReduceJSEqualTypeOf(Node* node, bool invert) { | 874 Reduction JSTypedLowering::ReduceJSEqualTypeOf(Node* node, bool invert) { |
| 875 Node* input; |
| 876 Handle<String> type; |
875 HeapObjectBinopMatcher m(node); | 877 HeapObjectBinopMatcher m(node); |
876 if (m.left().IsJSTypeOf() && m.right().HasValue() && | 878 if (m.left().IsJSTypeOf() && m.right().HasValue() && |
877 m.right().Value()->IsString()) { | 879 m.right().Value()->IsString()) { |
878 Node* replacement; | 880 input = m.left().InputAt(0); |
879 Node* input = m.left().InputAt(0); | 881 type = Handle<String>::cast(m.right().Value()); |
880 Handle<String> value = Handle<String>::cast(m.right().Value()); | 882 } else if (m.right().IsJSTypeOf() && m.left().HasValue() && |
881 if (String::Equals(value, factory()->boolean_string())) { | 883 m.left().Value()->IsString()) { |
882 replacement = | 884 input = m.right().InputAt(0); |
883 graph()->NewNode(common()->Select(MachineRepresentation::kTagged), | 885 type = Handle<String>::cast(m.left().Value()); |
884 graph()->NewNode(simplified()->ReferenceEqual(), | 886 } else { |
885 input, jsgraph()->TrueConstant()), | 887 return NoChange(); |
886 jsgraph()->TrueConstant(), | |
887 graph()->NewNode(simplified()->ReferenceEqual(), | |
888 input, jsgraph()->FalseConstant())); | |
889 } else if (String::Equals(value, factory()->function_string())) { | |
890 replacement = graph()->NewNode(simplified()->ObjectIsCallable(), input); | |
891 } else if (String::Equals(value, factory()->number_string())) { | |
892 replacement = graph()->NewNode(simplified()->ObjectIsNumber(), input); | |
893 } else if (String::Equals(value, factory()->string_string())) { | |
894 replacement = graph()->NewNode(simplified()->ObjectIsString(), input); | |
895 } else if (String::Equals(value, factory()->undefined_string())) { | |
896 replacement = graph()->NewNode( | |
897 common()->Select(MachineRepresentation::kTagged), | |
898 graph()->NewNode(simplified()->ReferenceEqual(), input, | |
899 jsgraph()->NullConstant()), | |
900 jsgraph()->FalseConstant(), | |
901 graph()->NewNode(simplified()->ObjectIsUndetectable(), input)); | |
902 } else { | |
903 return NoChange(); | |
904 } | |
905 if (invert) { | |
906 replacement = graph()->NewNode(simplified()->BooleanNot(), replacement); | |
907 } | |
908 ReplaceWithValue(node, replacement); | |
909 return Replace(replacement); | |
910 } | 888 } |
911 return NoChange(); | 889 Node* value; |
| 890 if (String::Equals(type, factory()->boolean_string())) { |
| 891 value = |
| 892 graph()->NewNode(common()->Select(MachineRepresentation::kTagged), |
| 893 graph()->NewNode(simplified()->ReferenceEqual(), input, |
| 894 jsgraph()->TrueConstant()), |
| 895 jsgraph()->TrueConstant(), |
| 896 graph()->NewNode(simplified()->ReferenceEqual(), input, |
| 897 jsgraph()->FalseConstant())); |
| 898 } else if (String::Equals(type, factory()->function_string())) { |
| 899 value = graph()->NewNode(simplified()->ObjectIsCallable(), input); |
| 900 } else if (String::Equals(type, factory()->number_string())) { |
| 901 value = graph()->NewNode(simplified()->ObjectIsNumber(), input); |
| 902 } else if (String::Equals(type, factory()->string_string())) { |
| 903 value = graph()->NewNode(simplified()->ObjectIsString(), input); |
| 904 } else if (String::Equals(type, factory()->undefined_string())) { |
| 905 value = graph()->NewNode( |
| 906 common()->Select(MachineRepresentation::kTagged), |
| 907 graph()->NewNode(simplified()->ReferenceEqual(), input, |
| 908 jsgraph()->NullConstant()), |
| 909 jsgraph()->FalseConstant(), |
| 910 graph()->NewNode(simplified()->ObjectIsUndetectable(), input)); |
| 911 } else { |
| 912 return NoChange(); |
| 913 } |
| 914 if (invert) { |
| 915 value = graph()->NewNode(simplified()->BooleanNot(), value); |
| 916 } |
| 917 ReplaceWithValue(node, value); |
| 918 return Replace(value); |
912 } | 919 } |
913 | 920 |
914 Reduction JSTypedLowering::ReduceJSEqual(Node* node, bool invert) { | 921 Reduction JSTypedLowering::ReduceJSEqual(Node* node, bool invert) { |
915 Reduction const reduction = ReduceJSEqualTypeOf(node, invert); | 922 Reduction const reduction = ReduceJSEqualTypeOf(node, invert); |
916 if (reduction.Changed()) return reduction; | 923 if (reduction.Changed()) return reduction; |
917 | 924 |
918 JSBinopReduction r(this, node); | 925 JSBinopReduction r(this, node); |
919 | 926 |
920 if (r.BothInputsAre(Type::UniqueName())) { | 927 if (r.BothInputsAre(Type::UniqueName())) { |
921 return r.ChangeToPureOperator(simplified()->ReferenceEqual(), invert); | 928 return r.ChangeToPureOperator(simplified()->ReferenceEqual(), invert); |
(...skipping 1490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2412 } | 2419 } |
2413 | 2420 |
2414 | 2421 |
2415 CompilationDependencies* JSTypedLowering::dependencies() const { | 2422 CompilationDependencies* JSTypedLowering::dependencies() const { |
2416 return dependencies_; | 2423 return dependencies_; |
2417 } | 2424 } |
2418 | 2425 |
2419 } // namespace compiler | 2426 } // namespace compiler |
2420 } // namespace internal | 2427 } // namespace internal |
2421 } // namespace v8 | 2428 } // namespace v8 |
OLD | NEW |