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

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

Issue 1469303006: Revert of Reland "[Interpreter] Add CreateClosure to BytecodeGraphBuilder." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
49 Graph* GetCompletedGraph(Handle<BytecodeArray> bytecode_array, 43 Graph* GetCompletedGraph(Handle<BytecodeArray> bytecode_array,
50 MaybeHandle<TypeFeedbackVector> feedback_vector = 44 MaybeHandle<TypeFeedbackVector> feedback_vector =
51 MaybeHandle<TypeFeedbackVector>(), 45 MaybeHandle<TypeFeedbackVector>(),
52 LanguageMode language_mode = LanguageMode::SLOPPY); 46 LanguageMode language_mode = LanguageMode::SLOPPY);
53 47
54 Matcher<Node*> IsUndefinedConstant(); 48 Matcher<Node*> IsUndefinedConstant();
55 Matcher<Node*> IsNullConstant(); 49 Matcher<Node*> IsNullConstant();
56 Matcher<Node*> IsTheHoleConstant(); 50 Matcher<Node*> IsTheHoleConstant();
57 Matcher<Node*> IsFalseConstant(); 51 Matcher<Node*> IsFalseConstant();
58 Matcher<Node*> IsTrueConstant(); 52 Matcher<Node*> IsTrueConstant();
59 Matcher<Node*> IsIntPtrConstant(int value); 53 Matcher<Node*> IsIntPtrConstant(int value);
60 Matcher<Node*> IsFeedbackVector(Node* effect, Node* control); 54 Matcher<Node*> IsFeedbackVector(Node* effect, Node* control);
61 55
62 static Handle<String> GetName(Isolate* isolate, const char* name) { 56 static Handle<String> GetName(Isolate* isolate, const char* name) {
63 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(name); 57 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(name);
64 return isolate->factory()->string_table()->LookupString(isolate, result); 58 return isolate->factory()->string_table()->LookupString(isolate, result);
65 } 59 }
66 60
67 private: 61 private:
68 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilderTest); 62 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilderTest);
69 }; 63 };
70 64
71 65
72 std::pair<Graph*, Handle<SharedFunctionInfo>> 66 Graph* BytecodeGraphBuilderTest::GetCompletedGraph(
73 BytecodeGraphBuilderTest::GetCompletedGraphAndSharedInfo(
74 Handle<BytecodeArray> bytecode_array, 67 Handle<BytecodeArray> bytecode_array,
75 MaybeHandle<TypeFeedbackVector> feedback_vector, 68 MaybeHandle<TypeFeedbackVector> feedback_vector,
76 LanguageMode language_mode) { 69 LanguageMode language_mode) {
77 MachineOperatorBuilder* machine = new (zone()) MachineOperatorBuilder( 70 MachineOperatorBuilder* machine = new (zone()) MachineOperatorBuilder(
78 zone(), kMachPtr, InstructionSelector::SupportedMachineOperatorFlags()); 71 zone(), kMachPtr, InstructionSelector::SupportedMachineOperatorFlags());
79 CommonOperatorBuilder* common = new (zone()) CommonOperatorBuilder(zone()); 72 CommonOperatorBuilder* common = new (zone()) CommonOperatorBuilder(zone());
80 JSOperatorBuilder* javascript = new (zone()) JSOperatorBuilder(zone()); 73 JSOperatorBuilder* javascript = new (zone()) JSOperatorBuilder(zone());
81 Graph* graph = new (zone()) Graph(zone()); 74 Graph* graph = new (zone()) Graph(zone());
82 JSGraph* jsgraph = new (zone()) 75 JSGraph* jsgraph = new (zone())
83 JSGraph(isolate(), graph, common, javascript, nullptr, machine); 76 JSGraph(isolate(), graph, common, javascript, nullptr, machine);
84 77
85 Handle<String> name = factory()->NewStringFromStaticChars("test"); 78 Handle<String> name = factory()->NewStringFromStaticChars("test");
86 Handle<String> script = factory()->NewStringFromStaticChars("test() {}"); 79 Handle<String> script = factory()->NewStringFromStaticChars("test() {}");
87 Handle<SharedFunctionInfo> shared_info = 80 Handle<SharedFunctionInfo> shared_info =
88 factory()->NewSharedFunctionInfo(name, MaybeHandle<Code>(), true); 81 factory()->NewSharedFunctionInfo(name, MaybeHandle<Code>(), true);
89 shared_info->set_script(*factory()->NewScript(script)); 82 shared_info->set_script(*factory()->NewScript(script));
90 if (!feedback_vector.is_null()) { 83 if (!feedback_vector.is_null()) {
91 shared_info->set_feedback_vector(*feedback_vector.ToHandleChecked()); 84 shared_info->set_feedback_vector(*feedback_vector.ToHandleChecked());
92 } 85 }
93 86
94 ParseInfo parse_info(zone(), shared_info); 87 ParseInfo parse_info(zone(), shared_info);
95 parse_info.set_language_mode(language_mode); 88 parse_info.set_language_mode(language_mode);
96 CompilationInfo info(&parse_info); 89 CompilationInfo info(&parse_info);
97 info.shared_info()->set_function_data(*bytecode_array); 90 info.shared_info()->set_function_data(*bytecode_array);
98 91
99 BytecodeGraphBuilder graph_builder(zone(), &info, jsgraph); 92 BytecodeGraphBuilder graph_builder(zone(), &info, jsgraph);
100 graph_builder.CreateGraph(); 93 graph_builder.CreateGraph();
101 return std::make_pair(graph_builder.graph(), shared_info); 94 return graph;
102 } 95 }
103 96
104 97
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
115 Matcher<Node*> BytecodeGraphBuilderTest::IsUndefinedConstant() { 98 Matcher<Node*> BytecodeGraphBuilderTest::IsUndefinedConstant() {
116 return IsHeapConstant(factory()->undefined_value()); 99 return IsHeapConstant(factory()->undefined_value());
117 } 100 }
118 101
119 102
120 Matcher<Node*> BytecodeGraphBuilderTest::IsNullConstant() { 103 Matcher<Node*> BytecodeGraphBuilderTest::IsNullConstant() {
121 return IsHeapConstant(factory()->null_value()); 104 return IsHeapConstant(factory()->null_value());
122 } 105 }
123 106
124 107
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 construct_inputs.push_back(IsParameter(1)); 800 construct_inputs.push_back(IsParameter(1));
818 construct_inputs.push_back(IsParameter(2)); 801 construct_inputs.push_back(IsParameter(2));
819 construct_inputs.push_back(IsParameter(3)); 802 construct_inputs.push_back(IsParameter(3));
820 construct_inputs.push_back(IsParameter(4)); 803 construct_inputs.push_back(IsParameter(4));
821 construct_inputs.push_back(IsParameter(1)); 804 construct_inputs.push_back(IsParameter(1));
822 Matcher<Node*> call_construct = 805 Matcher<Node*> call_construct =
823 IsJSCallConstruct(construct_inputs, start, start); 806 IsJSCallConstruct(construct_inputs, start, start);
824 EXPECT_THAT(ret, IsReturn(call_construct, call_construct, IsIfSuccess(_))); 807 EXPECT_THAT(ret, IsReturn(call_construct, call_construct, IsIfSuccess(_)));
825 } 808 }
826 809
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
860 } // namespace compiler 810 } // namespace compiler
861 } // namespace internal 811 } // namespace internal
862 } // namespace v8 812 } // 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