Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: test/unittests/compiler/bytecode-graph-builder-unittest.cc

Issue 1458603012: [Interpreter] Add CreateClosure to BytecodeGraphBuilder. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove unneeded includes. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 22 matching lines...) Expand all
33 Handle<TypeFeedbackMetadata> vector_metadata = 33 Handle<TypeFeedbackMetadata> vector_metadata =
34 TypeFeedbackMetadata::New(isolate, spec); 34 TypeFeedbackMetadata::New(isolate, spec);
35 return TypeFeedbackVector::New(isolate, vector_metadata); 35 return TypeFeedbackVector::New(isolate, vector_metadata);
36 } 36 }
37 37
38 38
39 class BytecodeGraphBuilderTest : public TestWithIsolateAndZone { 39 class BytecodeGraphBuilderTest : public TestWithIsolateAndZone {
40 public: 40 public:
41 BytecodeGraphBuilderTest() {} 41 BytecodeGraphBuilderTest() {}
42 42
43 std::pair<Graph*, Handle<SharedFunctionInfo>> GetCompletedGraphAndSharedInfo(
44 Handle<BytecodeArray> bytecode_array,
45 MaybeHandle<TypeFeedbackVector> feedback_vector =
46 MaybeHandle<TypeFeedbackVector>(),
47 LanguageMode language_mode = LanguageMode::SLOPPY);
48
43 Graph* GetCompletedGraph(Handle<BytecodeArray> bytecode_array, 49 Graph* GetCompletedGraph(Handle<BytecodeArray> bytecode_array,
44 MaybeHandle<TypeFeedbackVector> feedback_vector = 50 MaybeHandle<TypeFeedbackVector> feedback_vector =
45 MaybeHandle<TypeFeedbackVector>(), 51 MaybeHandle<TypeFeedbackVector>(),
46 LanguageMode language_mode = LanguageMode::SLOPPY); 52 LanguageMode language_mode = LanguageMode::SLOPPY);
47 53
48 Matcher<Node*> IsUndefinedConstant(); 54 Matcher<Node*> IsUndefinedConstant();
49 Matcher<Node*> IsNullConstant(); 55 Matcher<Node*> IsNullConstant();
50 Matcher<Node*> IsTheHoleConstant(); 56 Matcher<Node*> IsTheHoleConstant();
51 Matcher<Node*> IsFalseConstant(); 57 Matcher<Node*> IsFalseConstant();
52 Matcher<Node*> IsTrueConstant(); 58 Matcher<Node*> IsTrueConstant();
53 Matcher<Node*> IsIntPtrConstant(int value); 59 Matcher<Node*> IsIntPtrConstant(int value);
54 Matcher<Node*> IsFeedbackVector(Node* effect, Node* control); 60 Matcher<Node*> IsFeedbackVector(Node* effect, Node* control);
55 61
56 static Handle<String> GetName(Isolate* isolate, const char* name) { 62 static Handle<String> GetName(Isolate* isolate, const char* name) {
57 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(name); 63 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(name);
58 return isolate->factory()->string_table()->LookupString(isolate, result); 64 return isolate->factory()->string_table()->LookupString(isolate, result);
59 } 65 }
60 66
61 private: 67 private:
62 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilderTest); 68 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilderTest);
63 }; 69 };
64 70
65 71
66 Graph* BytecodeGraphBuilderTest::GetCompletedGraph( 72 std::pair<Graph*, Handle<SharedFunctionInfo>>
73 BytecodeGraphBuilderTest::GetCompletedGraphAndSharedInfo(
67 Handle<BytecodeArray> bytecode_array, 74 Handle<BytecodeArray> bytecode_array,
68 MaybeHandle<TypeFeedbackVector> feedback_vector, 75 MaybeHandle<TypeFeedbackVector> feedback_vector,
69 LanguageMode language_mode) { 76 LanguageMode language_mode) {
70 MachineOperatorBuilder* machine = new (zone()) MachineOperatorBuilder( 77 MachineOperatorBuilder* machine = new (zone()) MachineOperatorBuilder(
71 zone(), kMachPtr, InstructionSelector::SupportedMachineOperatorFlags()); 78 zone(), kMachPtr, InstructionSelector::SupportedMachineOperatorFlags());
72 CommonOperatorBuilder* common = new (zone()) CommonOperatorBuilder(zone()); 79 CommonOperatorBuilder* common = new (zone()) CommonOperatorBuilder(zone());
73 JSOperatorBuilder* javascript = new (zone()) JSOperatorBuilder(zone()); 80 JSOperatorBuilder* javascript = new (zone()) JSOperatorBuilder(zone());
74 Graph* graph = new (zone()) Graph(zone()); 81 Graph* graph = new (zone()) Graph(zone());
75 JSGraph* jsgraph = new (zone()) 82 JSGraph* jsgraph = new (zone())
76 JSGraph(isolate(), graph, common, javascript, nullptr, machine); 83 JSGraph(isolate(), graph, common, javascript, nullptr, machine);
77 84
78 Handle<String> name = factory()->NewStringFromStaticChars("test"); 85 Handle<String> name = factory()->NewStringFromStaticChars("test");
79 Handle<String> script = factory()->NewStringFromStaticChars("test() {}"); 86 Handle<String> script = factory()->NewStringFromStaticChars("test() {}");
80 Handle<SharedFunctionInfo> shared_info = 87 Handle<SharedFunctionInfo> shared_info =
81 factory()->NewSharedFunctionInfo(name, MaybeHandle<Code>()); 88 factory()->NewSharedFunctionInfo(name, MaybeHandle<Code>());
82 shared_info->set_script(*factory()->NewScript(script)); 89 shared_info->set_script(*factory()->NewScript(script));
83 if (!feedback_vector.is_null()) { 90 if (!feedback_vector.is_null()) {
84 shared_info->set_feedback_vector(*feedback_vector.ToHandleChecked()); 91 shared_info->set_feedback_vector(*feedback_vector.ToHandleChecked());
85 } 92 }
86 93
87 ParseInfo parse_info(zone(), shared_info); 94 ParseInfo parse_info(zone(), shared_info);
88 parse_info.set_language_mode(language_mode); 95 parse_info.set_language_mode(language_mode);
89 CompilationInfo info(&parse_info); 96 CompilationInfo info(&parse_info);
90 info.shared_info()->set_function_data(*bytecode_array); 97 info.shared_info()->set_function_data(*bytecode_array);
91 98
92 BytecodeGraphBuilder graph_builder(zone(), &info, jsgraph); 99 BytecodeGraphBuilder graph_builder(zone(), &info, jsgraph);
93 graph_builder.CreateGraph(); 100 graph_builder.CreateGraph();
94 return graph; 101 return std::make_pair(graph_builder.graph(), shared_info);
95 } 102 }
96 103
97 104
105 Graph* BytecodeGraphBuilderTest::GetCompletedGraph(
106 Handle<BytecodeArray> bytecode_array,
107 MaybeHandle<TypeFeedbackVector> feedback_vector,
108 LanguageMode language_mode) {
109 return GetCompletedGraphAndSharedInfo(bytecode_array, feedback_vector,
110 language_mode)
111 .first;
112 }
113
114
98 Matcher<Node*> BytecodeGraphBuilderTest::IsUndefinedConstant() { 115 Matcher<Node*> BytecodeGraphBuilderTest::IsUndefinedConstant() {
99 return IsHeapConstant(factory()->undefined_value()); 116 return IsHeapConstant(factory()->undefined_value());
100 } 117 }
101 118
102 119
103 Matcher<Node*> BytecodeGraphBuilderTest::IsNullConstant() { 120 Matcher<Node*> BytecodeGraphBuilderTest::IsNullConstant() {
104 return IsHeapConstant(factory()->null_value()); 121 return IsHeapConstant(factory()->null_value());
105 } 122 }
106 123
107 124
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 construct_inputs.push_back(IsParameter(1)); 817 construct_inputs.push_back(IsParameter(1));
801 construct_inputs.push_back(IsParameter(2)); 818 construct_inputs.push_back(IsParameter(2));
802 construct_inputs.push_back(IsParameter(3)); 819 construct_inputs.push_back(IsParameter(3));
803 construct_inputs.push_back(IsParameter(4)); 820 construct_inputs.push_back(IsParameter(4));
804 construct_inputs.push_back(IsParameter(1)); 821 construct_inputs.push_back(IsParameter(1));
805 Matcher<Node*> call_construct = 822 Matcher<Node*> call_construct =
806 IsJSCallConstruct(construct_inputs, start, start); 823 IsJSCallConstruct(construct_inputs, start, start);
807 EXPECT_THAT(ret, IsReturn(call_construct, call_construct, IsIfSuccess(_))); 824 EXPECT_THAT(ret, IsReturn(call_construct, call_construct, IsIfSuccess(_)));
808 } 825 }
809 826
827
828 TEST_F(BytecodeGraphBuilderTest, CreateClosure) {
829 PretenureFlag kPretenureFlags[] = {NOT_TENURED, TENURED};
830 TRACED_FOREACH(PretenureFlag, pretenure_flag, kPretenureFlags) {
831 interpreter::BytecodeArrayBuilder inner_builder(isolate(), zone());
832 inner_builder.set_locals_count(0);
833 inner_builder.set_context_count(0);
834 inner_builder.set_parameter_count(3);
835 inner_builder.LoadAccumulatorWithRegister(inner_builder.Parameter(2))
836 .BinaryOperation(Token::Value::ADD, inner_builder.Parameter(1),
837 Strength::WEAK)
838 .Return();
839
840 std::pair<Graph*, Handle<SharedFunctionInfo>> inner_graph_and_shared_info =
841 GetCompletedGraphAndSharedInfo(inner_builder.ToBytecodeArray());
842 Handle<SharedFunctionInfo> shared_info = inner_graph_and_shared_info.second;
843
844 interpreter::BytecodeArrayBuilder builder(isolate(), zone());
845 builder.set_locals_count(4);
846 builder.set_context_count(0);
847 builder.set_parameter_count(3);
848 builder.CreateClosure(shared_info, pretenure_flag).Return();
849
850 Graph* graph = GetCompletedGraph(builder.ToBytecodeArray());
851 Node* start = graph->start();
852 Node* ret = graph->end()->InputAt(0);
853
854 Matcher<Node*> create_closure =
855 IsCreateClosure(shared_info, pretenure_flag, start, start);
856 EXPECT_THAT(ret, IsReturn(create_closure, create_closure, start));
857 }
858 }
859
810 } // namespace compiler 860 } // namespace compiler
811 } // namespace internal 861 } // namespace internal
812 } // namespace v8 862 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/unittests/compiler/node-test-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698