OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 <iostream> | 5 #include <iostream> |
6 | 6 |
7 #include "src/compiler/bytecode-graph-builder.h" | 7 #include "src/compiler/bytecode-graph-builder.h" |
8 #include "src/compiler/common-operator.h" | 8 #include "src/compiler/common-operator.h" |
9 #include "src/compiler/graph-visualizer.h" | 9 #include "src/compiler/graph-visualizer.h" |
10 #include "src/compiler/instruction.h" | 10 #include "src/compiler/instruction.h" |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 Matcher<Node*> feedback_vector_matcher = IsFeedbackVector(start, start); | 714 Matcher<Node*> feedback_vector_matcher = IsFeedbackVector(start, start); |
715 Matcher<Node*> store_keyed_matcher = IsJSStoreProperty( | 715 Matcher<Node*> store_keyed_matcher = IsJSStoreProperty( |
716 IsParameter(1), IsNumberConstant(kKey), IsNumberConstant(kValue), | 716 IsParameter(1), IsNumberConstant(kKey), IsNumberConstant(kValue), |
717 feedback_vector_matcher, start, start); | 717 feedback_vector_matcher, start, start); |
718 | 718 |
719 EXPECT_THAT(ret, IsReturn(_, store_keyed_matcher, _)); | 719 EXPECT_THAT(ret, IsReturn(_, store_keyed_matcher, _)); |
720 } | 720 } |
721 } | 721 } |
722 } | 722 } |
723 | 723 |
| 724 |
| 725 TEST_F(BytecodeGraphBuilderTest, CallRuntime) { |
| 726 interpreter::BytecodeArrayBuilder array_builder(isolate(), zone()); |
| 727 array_builder.set_locals_count(2); |
| 728 array_builder.set_context_count(0); |
| 729 array_builder.set_parameter_count(3); |
| 730 |
| 731 array_builder.LoadAccumulatorWithRegister(array_builder.Parameter(1)) |
| 732 .StoreAccumulatorInRegister(interpreter::Register(0)) |
| 733 .LoadAccumulatorWithRegister(array_builder.Parameter(2)) |
| 734 .StoreAccumulatorInRegister(interpreter::Register(1)) |
| 735 .CallRuntime(Runtime::kAdd, interpreter::Register(0), 2) |
| 736 .Return(); |
| 737 |
| 738 Graph* graph = GetCompletedGraph(array_builder.ToBytecodeArray()); |
| 739 Node* start = graph->start(); |
| 740 Node* ret = graph->end()->InputAt(0); |
| 741 std::vector<Matcher<Node*>> call_inputs; |
| 742 call_inputs.push_back(IsParameter(1)); |
| 743 call_inputs.push_back(IsParameter(2)); |
| 744 Matcher<Node*> call_js_runtime = IsJSCallRuntime(call_inputs, start, start); |
| 745 |
| 746 EXPECT_THAT(ret, IsReturn(call_js_runtime, call_js_runtime, IsIfSuccess(_))); |
| 747 } |
| 748 |
| 749 |
| 750 TEST_F(BytecodeGraphBuilderTest, CallJSRuntime) { |
| 751 interpreter::BytecodeArrayBuilder array_builder(isolate(), zone()); |
| 752 array_builder.set_locals_count(1); |
| 753 array_builder.set_context_count(1); |
| 754 array_builder.set_parameter_count(2); |
| 755 |
| 756 // function f(arg) { return %spread_arguments(arg0); } |
| 757 interpreter::Register reg0 = interpreter::Register(0); |
| 758 array_builder.LoadAccumulatorWithRegister(array_builder.Parameter(1)) |
| 759 .StoreAccumulatorInRegister(reg0) |
| 760 .CallJSRuntime(Context::SPREAD_ARGUMENTS_INDEX, reg0, 1) |
| 761 .Return(); |
| 762 |
| 763 Graph* graph = GetCompletedGraph(array_builder.ToBytecodeArray()); |
| 764 Node* ret = graph->end()->InputAt(0); |
| 765 Matcher<Node*> load_context = |
| 766 IsLoadContext(ContextAccess(0, Context::SPREAD_ARGUMENTS_INDEX, true), _); |
| 767 std::vector<Matcher<Node*>> call_inputs; |
| 768 call_inputs.push_back(load_context); |
| 769 call_inputs.push_back(IsParameter(1)); |
| 770 Matcher<Node*> call_js_function = |
| 771 IsJSCallFunction(call_inputs, load_context, graph->start()); |
| 772 |
| 773 EXPECT_THAT(ret, |
| 774 IsReturn(call_js_function, call_js_function, IsIfSuccess(_))); |
| 775 } |
| 776 |
| 777 |
| 778 TEST_F(BytecodeGraphBuilderTest, New) { |
| 779 interpreter::BytecodeArrayBuilder array_builder(isolate(), zone()); |
| 780 array_builder.set_locals_count(4); |
| 781 array_builder.set_context_count(0); |
| 782 array_builder.set_parameter_count(5); |
| 783 |
| 784 array_builder.LoadAccumulatorWithRegister(array_builder.Parameter(1)) |
| 785 .StoreAccumulatorInRegister(interpreter::Register(0)) |
| 786 .LoadAccumulatorWithRegister(array_builder.Parameter(2)) |
| 787 .StoreAccumulatorInRegister(interpreter::Register(1)) |
| 788 .LoadAccumulatorWithRegister(array_builder.Parameter(3)) |
| 789 .StoreAccumulatorInRegister(interpreter::Register(2)) |
| 790 .LoadAccumulatorWithRegister(array_builder.Parameter(4)) |
| 791 .StoreAccumulatorInRegister(interpreter::Register(3)) |
| 792 .New(interpreter::Register(0), interpreter::Register(1), 3) |
| 793 .Return(); |
| 794 auto bytecode_array = array_builder.ToBytecodeArray(); |
| 795 Graph* graph = GetCompletedGraph(bytecode_array); |
| 796 |
| 797 Node* start = graph->start(); |
| 798 Node* ret = graph->end()->InputAt(0); |
| 799 std::vector<Matcher<Node*>> construct_inputs; |
| 800 construct_inputs.push_back(IsParameter(1)); |
| 801 construct_inputs.push_back(IsParameter(2)); |
| 802 construct_inputs.push_back(IsParameter(3)); |
| 803 construct_inputs.push_back(IsParameter(4)); |
| 804 construct_inputs.push_back(IsParameter(1)); |
| 805 Matcher<Node*> call_construct = |
| 806 IsJSCallConstruct(construct_inputs, start, start); |
| 807 EXPECT_THAT(ret, IsReturn(call_construct, call_construct, IsIfSuccess(_))); |
| 808 } |
| 809 |
724 } // namespace compiler | 810 } // namespace compiler |
725 } // namespace internal | 811 } // namespace internal |
726 } // namespace v8 | 812 } // namespace v8 |
OLD | NEW |