| 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/compiler/access-builder.h" | 6 #include "src/compiler/access-builder.h" |
| 7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
| 8 #include "src/compiler/js-operator.h" | 8 #include "src/compiler/js-operator.h" |
| 9 #include "src/compiler/js-typed-lowering.h" | 9 #include "src/compiler/js-typed-lowering.h" |
| 10 #include "src/compiler/machine-operator.h" | 10 #include "src/compiler/machine-operator.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 protected: | 81 protected: |
| 82 Reduction Reduce(Node* node) { | 82 Reduction Reduce(Node* node) { |
| 83 MachineOperatorBuilder machine(zone()); | 83 MachineOperatorBuilder machine(zone()); |
| 84 SimplifiedOperatorBuilder simplified(zone()); | 84 SimplifiedOperatorBuilder simplified(zone()); |
| 85 JSGraph jsgraph(isolate(), graph(), common(), javascript(), &simplified, | 85 JSGraph jsgraph(isolate(), graph(), common(), javascript(), &simplified, |
| 86 &machine); | 86 &machine); |
| 87 // TODO(titzer): mock the GraphReducer here for better unit testing. | 87 // TODO(titzer): mock the GraphReducer here for better unit testing. |
| 88 GraphReducer graph_reducer(zone(), graph()); | 88 GraphReducer graph_reducer(zone(), graph()); |
| 89 JSTypedLowering reducer(&graph_reducer, &deps_, | 89 JSTypedLowering reducer(&graph_reducer, &deps_, |
| 90 JSTypedLowering::kDeoptimizationEnabled, &jsgraph, | 90 JSTypedLowering::kDeoptimizationEnabled | |
| 91 zone()); | 91 JSTypedLowering::kTypeFeedbackEnabled, |
| 92 &jsgraph, zone()); |
| 92 return reducer.Reduce(node); | 93 return reducer.Reduce(node); |
| 93 } | 94 } |
| 94 | 95 |
| 95 Handle<JSArrayBuffer> NewArrayBuffer(void* bytes, size_t byte_length) { | 96 Handle<JSArrayBuffer> NewArrayBuffer(void* bytes, size_t byte_length) { |
| 96 Handle<JSArrayBuffer> buffer = factory()->NewJSArrayBuffer(); | 97 Handle<JSArrayBuffer> buffer = factory()->NewJSArrayBuffer(); |
| 97 JSArrayBuffer::Setup(buffer, isolate(), true, bytes, byte_length); | 98 JSArrayBuffer::Setup(buffer, isolate(), true, bytes, byte_length); |
| 98 return buffer; | 99 return buffer; |
| 99 } | 100 } |
| 100 | 101 |
| 101 Matcher<Node*> IsIntPtrConstant(intptr_t value) { | 102 Matcher<Node*> IsIntPtrConstant(intptr_t value) { |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 Reduce(graph()->NewNode(javascript()->Add(hints), lhs, rhs, context, | 832 Reduce(graph()->NewNode(javascript()->Add(hints), lhs, rhs, context, |
| 832 frame_state0, frame_state1, effect, control)); | 833 frame_state0, frame_state1, effect, control)); |
| 833 ASSERT_TRUE(r.Changed()); | 834 ASSERT_TRUE(r.Changed()); |
| 834 EXPECT_THAT(r.replacement(), | 835 EXPECT_THAT(r.replacement(), |
| 835 IsCall(_, IsHeapConstant(CodeFactory::StringAdd( | 836 IsCall(_, IsHeapConstant(CodeFactory::StringAdd( |
| 836 isolate(), STRING_ADD_CHECK_NONE, | 837 isolate(), STRING_ADD_CHECK_NONE, |
| 837 NOT_TENURED).code()), | 838 NOT_TENURED).code()), |
| 838 lhs, rhs, context, frame_state0, effect, control)); | 839 lhs, rhs, context, frame_state0, effect, control)); |
| 839 } | 840 } |
| 840 | 841 |
| 842 TEST_F(JSTypedLoweringTest, JSAddSmis) { |
| 843 BinaryOperationHints const hints(BinaryOperationHints::kSignedSmall, |
| 844 BinaryOperationHints::kSignedSmall, |
| 845 BinaryOperationHints::kSignedSmall); |
| 846 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
| 847 Node* lhs = Parameter(Type::Number(), 0); |
| 848 Node* rhs = Parameter(Type::Number(), 1); |
| 849 Node* context = Parameter(Type::Any(), 2); |
| 850 Node* frame_state0 = EmptyFrameState(); |
| 851 Node* frame_state1 = EmptyFrameState(); |
| 852 Node* effect = graph()->start(); |
| 853 Node* control = graph()->start(); |
| 854 Reduction r = |
| 855 Reduce(graph()->NewNode(javascript()->Add(hints), lhs, rhs, context, |
| 856 frame_state0, frame_state1, effect, control)); |
| 857 ASSERT_TRUE(r.Changed()); |
| 858 EXPECT_THAT(r.replacement(), |
| 859 IsSpeculativeNumberAdd(BinaryOperationHints::kSignedSmall, lhs, |
| 860 rhs, frame_state1, effect, control)); |
| 861 } |
| 862 } |
| 863 |
| 864 // ----------------------------------------------------------------------------- |
| 865 // JSSubtract |
| 866 |
| 867 TEST_F(JSTypedLoweringTest, JSSubtractSmis) { |
| 868 BinaryOperationHints const hints(BinaryOperationHints::kSignedSmall, |
| 869 BinaryOperationHints::kSignedSmall, |
| 870 BinaryOperationHints::kSignedSmall); |
| 871 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
| 872 Node* lhs = Parameter(Type::Number(), 0); |
| 873 Node* rhs = Parameter(Type::Number(), 1); |
| 874 Node* context = Parameter(Type::Any(), 2); |
| 875 Node* frame_state0 = EmptyFrameState(); |
| 876 Node* frame_state1 = EmptyFrameState(); |
| 877 Node* effect = graph()->start(); |
| 878 Node* control = graph()->start(); |
| 879 Reduction r = Reduce(graph()->NewNode(javascript()->Subtract(hints), lhs, |
| 880 rhs, context, frame_state0, |
| 881 frame_state1, effect, control)); |
| 882 ASSERT_TRUE(r.Changed()); |
| 883 EXPECT_THAT(r.replacement(), IsSpeculativeNumberSubtract( |
| 884 BinaryOperationHints::kSignedSmall, lhs, |
| 885 rhs, frame_state1, effect, control)); |
| 886 } |
| 887 } |
| 841 | 888 |
| 842 // ----------------------------------------------------------------------------- | 889 // ----------------------------------------------------------------------------- |
| 843 // JSInstanceOf | 890 // JSInstanceOf |
| 844 // Test that instanceOf is reduced if and only if the right-hand side is a | 891 // Test that instanceOf is reduced if and only if the right-hand side is a |
| 845 // function constant. Functional correctness is ensured elsewhere. | 892 // function constant. Functional correctness is ensured elsewhere. |
| 846 | 893 |
| 847 | 894 |
| 848 TEST_F(JSTypedLoweringTest, JSInstanceOfSpecializationWithoutSmiCheck) { | 895 TEST_F(JSTypedLoweringTest, JSInstanceOfSpecializationWithoutSmiCheck) { |
| 849 Node* const context = Parameter(Type::Any()); | 896 Node* const context = Parameter(Type::Any()); |
| 850 Node* const frame_state = EmptyFrameState(); | 897 Node* const frame_state = EmptyFrameState(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, | 945 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, |
| 899 frame_state, effect, control); | 946 frame_state, effect, control); |
| 900 Reduction r = Reduce(instanceOf); | 947 Reduction r = Reduce(instanceOf); |
| 901 ASSERT_FALSE(r.Changed()); | 948 ASSERT_FALSE(r.Changed()); |
| 902 ASSERT_EQ(instanceOf, dummy->InputAt(0)); | 949 ASSERT_EQ(instanceOf, dummy->InputAt(0)); |
| 903 } | 950 } |
| 904 | 951 |
| 905 } // namespace compiler | 952 } // namespace compiler |
| 906 } // namespace internal | 953 } // namespace internal |
| 907 } // namespace v8 | 954 } // namespace v8 |
| OLD | NEW |