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

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

Issue 1419373007: [Interpreter] Adds implementation of bytecode graph builder for LoadICSloppy/Strict (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Removes FrameStateBeforeAndAfter and adds a function to replace framestate inputs with emtpy frame … Created 5 years, 1 month 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"
11 #include "src/compiler/instruction-selector.h" 11 #include "src/compiler/instruction-selector.h"
12 #include "src/compiler/js-graph.h" 12 #include "src/compiler/js-graph.h"
13 #include "src/compiler/js-operator.h" 13 #include "src/compiler/js-operator.h"
14 #include "src/compiler/linkage.h"
14 #include "src/interpreter/bytecode-array-builder.h" 15 #include "src/interpreter/bytecode-array-builder.h"
16 #include "src/interpreter/interpreter.h"
15 #include "src/parser.h" 17 #include "src/parser.h"
16 #include "test/unittests/compiler/compiler-test-utils.h" 18 #include "test/unittests/compiler/compiler-test-utils.h"
17 #include "test/unittests/compiler/graph-unittest.h" 19 #include "test/unittests/compiler/graph-unittest.h"
18 #include "test/unittests/compiler/node-test-utils.h" 20 #include "test/unittests/compiler/node-test-utils.h"
19 #include "test/unittests/test-utils.h" 21 #include "test/unittests/test-utils.h"
20 22
21 using ::testing::_; 23 using ::testing::_;
22 24
23 namespace v8 { 25 namespace v8 {
24 namespace internal { 26 namespace internal {
25 namespace compiler { 27 namespace compiler {
26 28
29 #define SPACE()
30
31 #define REPEAT_2(SEP, ...) __VA_ARGS__ SEP() __VA_ARGS__
32 #define REPEAT_4(SEP, ...) \
33 REPEAT_2(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__)
34 #define REPEAT_8(SEP, ...) \
35 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_4(SEP, __VA_ARGS__)
36 #define REPEAT_16(SEP, ...) \
37 REPEAT_8(SEP, __VA_ARGS__) SEP() REPEAT_8(SEP, __VA_ARGS__)
38 #define REPEAT_32(SEP, ...) \
39 REPEAT_16(SEP, __VA_ARGS__) SEP() REPEAT_16(SEP, __VA_ARGS__)
40 #define REPEAT_64(SEP, ...) \
41 REPEAT_32(SEP, __VA_ARGS__) SEP() REPEAT_32(SEP, __VA_ARGS__)
42 #define REPEAT_128(SEP, ...) \
43 REPEAT_64(SEP, __VA_ARGS__) SEP() REPEAT_64(SEP, __VA_ARGS__)
44 #define REPEAT_256(SEP, ...) \
45 REPEAT_128(SEP, __VA_ARGS__) SEP() REPEAT_128(SEP, __VA_ARGS__)
46
47 #define REPEAT_127(SEP, ...) \
48 REPEAT_64(SEP, __VA_ARGS__) \
49 SEP() \
50 REPEAT_32(SEP, __VA_ARGS__) \
51 SEP() \
52 REPEAT_16(SEP, __VA_ARGS__) \
53 SEP() \
54 REPEAT_8(SEP, __VA_ARGS__) \
55 SEP() \
56 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) SEP() __VA_ARGS__
57
58 static const char* kFunctionName = "f";
59
60 class GraphGeneratorHelper {
61 public:
62 GraphGeneratorHelper(Isolate* isolate, Zone* zone, const char* script)
63 : GraphGeneratorHelper(isolate, zone, script,
64 MaybeHandle<BytecodeArray>()) {}
65
66 GraphGeneratorHelper(Isolate* isolate, Zone* zone,
67 MaybeHandle<BytecodeArray> bytecode)
68 : GraphGeneratorHelper(isolate, zone, nullptr, bytecode) {}
69
70 Graph* GetCompletedGraph() {
71 ParseInfo parse_info(zone_);
72 if (script_) {
73 v8::Context::New(v8::Isolate::GetCurrent())->Enter();
74 v8::Local<v8::Context> context =
75 v8::Isolate::GetCurrent()->GetCurrentContext();
76 CompileRun(script_);
77
78 Local<Function> api_function =
79 Local<Function>::Cast(context->Global()
80 ->Get(context, v8_str(kFunctionName))
81 .ToLocalChecked());
82 Handle<JSFunction> function =
83 Handle<JSFunction>::cast(v8::Utils::OpenHandle(*api_function));
84 CHECK(function->shared()->HasBytecodeArray());
85
86 context->Exit();
87 ParseInfo p(zone_, function);
rmcilroy 2015/11/11 14:10:06 don't use single letter variable names - also, no
mythria 2015/11/11 15:32:50 Done.
88 parse_info = p;
89 } else {
90 DCHECK(!bytecode_.is_null());
91 Handle<String> name =
92 isolate_->factory()->NewStringFromAsciiChecked(kFunctionName);
93 std::string script_str("function " + std::string(kFunctionName) +
94 "() {}");
95 Handle<String> script =
96 isolate_->factory()->NewStringFromAsciiChecked(script_str.c_str());
97 Handle<SharedFunctionInfo> shared_info =
98 isolate_->factory()->NewSharedFunctionInfo(name, MaybeHandle<Code>());
99 shared_info->set_script(*isolate_->factory()->NewScript(script));
100 ParseInfo p(zone_, shared_info);
rmcilroy 2015/11/11 14:10:06 ditto
mythria 2015/11/11 15:32:50 Done.
101 parse_info = p;
102 }
103
104 CompilationInfo info(&parse_info);
105 if (!bytecode_.is_null()) {
106 info.shared_info()->set_function_data(*bytecode_.ToHandleChecked());
107 }
108
109 MachineOperatorBuilder* machine = new (zone_) MachineOperatorBuilder(
110 zone_, kMachPtr, InstructionSelector::SupportedMachineOperatorFlags());
111 CommonOperatorBuilder* common = new (zone_) CommonOperatorBuilder(zone_);
112 JSOperatorBuilder* javascript = new (zone_) JSOperatorBuilder(zone_);
113 Graph* graph = new (zone_) Graph(zone_);
114 JSGraph* jsgraph = new (zone_)
115 JSGraph(isolate_, graph, common, javascript, nullptr, machine);
116
117 BytecodeGraphBuilder graph_builder(zone_, &info, jsgraph);
118 graph_builder.CreateGraph();
119 return graph;
120 }
121
122 static Handle<String> GetName(Isolate* isolate, const char* name) {
123 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(name);
124 return isolate->factory()->string_table()->LookupString(isolate, result);
125 }
126
127 private:
128 GraphGeneratorHelper(Isolate* isolate, Zone* zone, const char* script,
129 MaybeHandle<BytecodeArray> bytecode)
130 : isolate_(isolate), zone_(zone), script_(script), bytecode_(bytecode) {
131 i::FLAG_ignition = true;
132 i::FLAG_always_opt = false;
133 i::FLAG_vector_stores = true;
134 // Set ignition filter flag via SetFlagsFromString to avoid double-free
135 // (or potential leak with StrDup() based on ownership confusion).
136 ScopedVector<char> ignition_filter(64);
137 SNPrintF(ignition_filter, "--ignition-filter=%s", kFunctionName);
138 FlagList::SetFlagsFromString(ignition_filter.start(),
139 ignition_filter.length());
140 // Ensure handler table is generated.
141 isolate_->interpreter()->Initialize();
142 }
143
144 static v8::Local<v8::String> v8_str(const char* string) {
145 v8::Local<v8::String> v8_string =
146 v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), string,
147 v8::NewStringType::kNormal)
148 .ToLocalChecked();
149 return v8_string;
150 }
151
152 static Local<Value> CompileRun(const char* source) {
153 v8::Local<v8::Context> context =
154 v8::Isolate::GetCurrent()->GetCurrentContext();
155 v8::Local<v8::Script> compiled_script =
156 (v8::Script::Compile(context, v8_str(source)).ToLocalChecked());
157 return compiled_script->Run(context).ToLocalChecked();
158 }
159
160 Isolate* isolate_;
161 Zone* zone_;
162 const char* script_;
163 MaybeHandle<BytecodeArray> bytecode_;
164 };
165
166
27 class BytecodeGraphBuilderTest : public TestWithIsolateAndZone { 167 class BytecodeGraphBuilderTest : public TestWithIsolateAndZone {
28 public: 168 public:
29 BytecodeGraphBuilderTest() : array_builder_(isolate(), zone()) {} 169 BytecodeGraphBuilderTest() : array_builder_(isolate(), zone()) {}
30 170
31 Graph* GetCompletedGraph();
32
33 Matcher<Node*> IsUndefinedConstant(); 171 Matcher<Node*> IsUndefinedConstant();
34 Matcher<Node*> IsNullConstant(); 172 Matcher<Node*> IsNullConstant();
35 Matcher<Node*> IsTheHoleConstant(); 173 Matcher<Node*> IsTheHoleConstant();
36 Matcher<Node*> IsFalseConstant(); 174 Matcher<Node*> IsFalseConstant();
37 Matcher<Node*> IsTrueConstant(); 175 Matcher<Node*> IsTrueConstant();
176 Matcher<Node*> IsIntPtrConstant(int value);
177 Matcher<Node*> IsFeedbackVector(Node* effect, Node* control);
38 178
39 interpreter::BytecodeArrayBuilder* array_builder() { return &array_builder_; } 179 interpreter::BytecodeArrayBuilder* array_builder() { return &array_builder_; }
40 180
41 private: 181 private:
42 interpreter::BytecodeArrayBuilder array_builder_; 182 interpreter::BytecodeArrayBuilder array_builder_;
43 183
44 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilderTest); 184 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilderTest);
45 }; 185 };
46 186
47 187
48 Graph* BytecodeGraphBuilderTest::GetCompletedGraph() {
49 MachineOperatorBuilder* machine = new (zone()) MachineOperatorBuilder(
50 zone(), kMachPtr, InstructionSelector::SupportedMachineOperatorFlags());
51 CommonOperatorBuilder* common = new (zone()) CommonOperatorBuilder(zone());
52 JSOperatorBuilder* javascript = new (zone()) JSOperatorBuilder(zone());
53 Graph* graph = new (zone()) Graph(zone());
54 JSGraph* jsgraph = new (zone())
55 JSGraph(isolate(), graph, common, javascript, nullptr, machine);
56
57 Handle<String> name = factory()->NewStringFromStaticChars("test");
58 Handle<String> script = factory()->NewStringFromStaticChars("test() {}");
59 Handle<SharedFunctionInfo> shared_info =
60 factory()->NewSharedFunctionInfo(name, MaybeHandle<Code>());
61 shared_info->set_script(*factory()->NewScript(script));
62
63 ParseInfo parse_info(zone(), shared_info);
64 CompilationInfo info(&parse_info);
65 Handle<BytecodeArray> bytecode_array = array_builder()->ToBytecodeArray();
66 info.shared_info()->set_function_data(*bytecode_array);
67
68 BytecodeGraphBuilder graph_builder(zone(), &info, jsgraph);
69 graph_builder.CreateGraph();
70 return graph;
71 }
72
73
74 Matcher<Node*> BytecodeGraphBuilderTest::IsUndefinedConstant() { 188 Matcher<Node*> BytecodeGraphBuilderTest::IsUndefinedConstant() {
75 return IsHeapConstant(factory()->undefined_value()); 189 return IsHeapConstant(factory()->undefined_value());
76 } 190 }
77 191
78 192
79 Matcher<Node*> BytecodeGraphBuilderTest::IsNullConstant() { 193 Matcher<Node*> BytecodeGraphBuilderTest::IsNullConstant() {
80 return IsHeapConstant(factory()->null_value()); 194 return IsHeapConstant(factory()->null_value());
81 } 195 }
82 196
83 197
84 Matcher<Node*> BytecodeGraphBuilderTest::IsTheHoleConstant() { 198 Matcher<Node*> BytecodeGraphBuilderTest::IsTheHoleConstant() {
85 return IsHeapConstant(factory()->the_hole_value()); 199 return IsHeapConstant(factory()->the_hole_value());
86 } 200 }
87 201
88 202
89 Matcher<Node*> BytecodeGraphBuilderTest::IsFalseConstant() { 203 Matcher<Node*> BytecodeGraphBuilderTest::IsFalseConstant() {
90 return IsHeapConstant(factory()->false_value()); 204 return IsHeapConstant(factory()->false_value());
91 } 205 }
92 206
93 207
94 Matcher<Node*> BytecodeGraphBuilderTest::IsTrueConstant() { 208 Matcher<Node*> BytecodeGraphBuilderTest::IsTrueConstant() {
95 return IsHeapConstant(factory()->true_value()); 209 return IsHeapConstant(factory()->true_value());
96 } 210 }
97 211
98 212
213 Matcher<Node*> BytecodeGraphBuilderTest::IsIntPtrConstant(int value) {
214 if (kPointerSize == 8) {
215 return IsInt64Constant(value);
216 } else {
217 return IsInt32Constant(value);
218 }
219 }
220
221
222 Matcher<Node*> BytecodeGraphBuilderTest::IsFeedbackVector(Node* effect,
223 Node* control) {
224 int offset = SharedFunctionInfo::kFeedbackVectorOffset - kHeapObjectTag;
225 int offset1 = JSFunction::kSharedFunctionInfoOffset - kHeapObjectTag;
226
227 return IsLoad(kMachAnyTagged,
228 IsLoad(kMachAnyTagged,
229 IsParameter(Linkage::kJSFunctionCallClosureParamIndex),
230 IsIntPtrConstant(offset1), effect, control),
231 IsIntPtrConstant(offset), effect, control);
232 }
233
234
99 TEST_F(BytecodeGraphBuilderTest, ReturnUndefined) { 235 TEST_F(BytecodeGraphBuilderTest, ReturnUndefined) {
100 array_builder()->set_locals_count(0); 236 array_builder()->set_locals_count(0);
101 array_builder()->set_context_count(0); 237 array_builder()->set_context_count(0);
102 array_builder()->set_parameter_count(1); 238 array_builder()->set_parameter_count(1);
103 array_builder()->LoadUndefined().Return(); 239 array_builder()->LoadUndefined().Return();
104 240
105 Graph* graph = GetCompletedGraph(); 241 GraphGeneratorHelper helper(isolate(), zone(),
242 array_builder()->ToBytecodeArray());
243 Graph* graph = helper.GetCompletedGraph();
106 Node* end = graph->end(); 244 Node* end = graph->end();
107 EXPECT_EQ(1, end->InputCount()); 245 EXPECT_EQ(1, end->InputCount());
108 Node* ret = end->InputAt(0); 246 Node* ret = end->InputAt(0);
109 Node* effect = graph->start(); 247 Node* effect = graph->start();
110 Node* control = graph->start(); 248 Node* control = graph->start();
111 EXPECT_THAT(ret, IsReturn(IsUndefinedConstant(), effect, control)); 249 EXPECT_THAT(ret, IsReturn(IsUndefinedConstant(), effect, control));
112 } 250 }
113 251
114 252
115 TEST_F(BytecodeGraphBuilderTest, ReturnNull) { 253 TEST_F(BytecodeGraphBuilderTest, ReturnNull) {
116 array_builder()->set_locals_count(0); 254 array_builder()->set_locals_count(0);
117 array_builder()->set_context_count(0); 255 array_builder()->set_context_count(0);
118 array_builder()->set_parameter_count(1); 256 array_builder()->set_parameter_count(1);
119 array_builder()->LoadNull().Return(); 257 array_builder()->LoadNull().Return();
120 258
121 Graph* graph = GetCompletedGraph(); 259 GraphGeneratorHelper helper(isolate(), zone(),
260 array_builder()->ToBytecodeArray());
261 Graph* graph = helper.GetCompletedGraph();
122 Node* end = graph->end(); 262 Node* end = graph->end();
123 EXPECT_EQ(1, end->InputCount()); 263 EXPECT_EQ(1, end->InputCount());
124 Node* ret = end->InputAt(0); 264 Node* ret = end->InputAt(0);
125 EXPECT_THAT(ret, IsReturn(IsNullConstant(), graph->start(), graph->start())); 265 EXPECT_THAT(ret, IsReturn(IsNullConstant(), graph->start(), graph->start()));
126 } 266 }
127 267
128 268
129 TEST_F(BytecodeGraphBuilderTest, ReturnTheHole) { 269 TEST_F(BytecodeGraphBuilderTest, ReturnTheHole) {
130 array_builder()->set_locals_count(0); 270 array_builder()->set_locals_count(0);
131 array_builder()->set_context_count(0); 271 array_builder()->set_context_count(0);
132 array_builder()->set_parameter_count(1); 272 array_builder()->set_parameter_count(1);
133 array_builder()->LoadTheHole().Return(); 273 array_builder()->LoadTheHole().Return();
134 274
135 Graph* graph = GetCompletedGraph(); 275 GraphGeneratorHelper helper(isolate(), zone(),
276 array_builder()->ToBytecodeArray());
277 Graph* graph = helper.GetCompletedGraph();
136 Node* end = graph->end(); 278 Node* end = graph->end();
137 EXPECT_EQ(1, end->InputCount()); 279 EXPECT_EQ(1, end->InputCount());
138 Node* ret = end->InputAt(0); 280 Node* ret = end->InputAt(0);
139 Node* effect = graph->start(); 281 Node* effect = graph->start();
140 Node* control = graph->start(); 282 Node* control = graph->start();
141 EXPECT_THAT(ret, IsReturn(IsTheHoleConstant(), effect, control)); 283 EXPECT_THAT(ret, IsReturn(IsTheHoleConstant(), effect, control));
142 } 284 }
143 285
144 286
145 TEST_F(BytecodeGraphBuilderTest, ReturnTrue) { 287 TEST_F(BytecodeGraphBuilderTest, ReturnTrue) {
146 array_builder()->set_locals_count(0); 288 array_builder()->set_locals_count(0);
147 array_builder()->set_context_count(0); 289 array_builder()->set_context_count(0);
148 array_builder()->set_parameter_count(1); 290 array_builder()->set_parameter_count(1);
149 array_builder()->LoadTrue().Return(); 291 array_builder()->LoadTrue().Return();
150 292
151 Graph* graph = GetCompletedGraph(); 293 GraphGeneratorHelper helper(isolate(), zone(),
294 array_builder()->ToBytecodeArray());
295 Graph* graph = helper.GetCompletedGraph();
152 Node* end = graph->end(); 296 Node* end = graph->end();
153 EXPECT_EQ(1, end->InputCount()); 297 EXPECT_EQ(1, end->InputCount());
154 Node* ret = end->InputAt(0); 298 Node* ret = end->InputAt(0);
155 Node* effect = graph->start(); 299 Node* effect = graph->start();
156 Node* control = graph->start(); 300 Node* control = graph->start();
157 EXPECT_THAT(ret, IsReturn(IsTrueConstant(), effect, control)); 301 EXPECT_THAT(ret, IsReturn(IsTrueConstant(), effect, control));
158 } 302 }
159 303
160 304
161 TEST_F(BytecodeGraphBuilderTest, ReturnFalse) { 305 TEST_F(BytecodeGraphBuilderTest, ReturnFalse) {
162 array_builder()->set_locals_count(0); 306 array_builder()->set_locals_count(0);
163 array_builder()->set_context_count(0); 307 array_builder()->set_context_count(0);
164 array_builder()->set_parameter_count(1); 308 array_builder()->set_parameter_count(1);
165 array_builder()->LoadFalse().Return(); 309 array_builder()->LoadFalse().Return();
166 310
167 Graph* graph = GetCompletedGraph(); 311 GraphGeneratorHelper helper(isolate(), zone(),
312 array_builder()->ToBytecodeArray());
313 Graph* graph = helper.GetCompletedGraph();
168 Node* end = graph->end(); 314 Node* end = graph->end();
169 EXPECT_EQ(1, end->InputCount()); 315 EXPECT_EQ(1, end->InputCount());
170 Node* ret = end->InputAt(0); 316 Node* ret = end->InputAt(0);
171 Node* effect = graph->start(); 317 Node* effect = graph->start();
172 Node* control = graph->start(); 318 Node* control = graph->start();
173 EXPECT_THAT(ret, IsReturn(IsFalseConstant(), effect, control)); 319 EXPECT_THAT(ret, IsReturn(IsFalseConstant(), effect, control));
174 } 320 }
175 321
176 322
177 TEST_F(BytecodeGraphBuilderTest, ReturnInt8) { 323 TEST_F(BytecodeGraphBuilderTest, ReturnInt8) {
178 static const int kValue = 3; 324 static const int kValue = 3;
179 array_builder()->set_locals_count(0); 325 array_builder()->set_locals_count(0);
180 array_builder()->set_context_count(0); 326 array_builder()->set_context_count(0);
181 array_builder()->set_parameter_count(1); 327 array_builder()->set_parameter_count(1);
182 array_builder()->LoadLiteral(Smi::FromInt(kValue)).Return(); 328 array_builder()->LoadLiteral(Smi::FromInt(kValue)).Return();
183 329
184 Graph* graph = GetCompletedGraph(); 330 GraphGeneratorHelper helper(isolate(), zone(),
331 array_builder()->ToBytecodeArray());
332 Graph* graph = helper.GetCompletedGraph();
185 Node* end = graph->end(); 333 Node* end = graph->end();
186 EXPECT_EQ(1, end->InputCount()); 334 EXPECT_EQ(1, end->InputCount());
187 Node* ret = end->InputAt(0); 335 Node* ret = end->InputAt(0);
188 Node* effect = graph->start(); 336 Node* effect = graph->start();
189 Node* control = graph->start(); 337 Node* control = graph->start();
190 EXPECT_THAT(ret, IsReturn(IsNumberConstant(kValue), effect, control)); 338 EXPECT_THAT(ret, IsReturn(IsNumberConstant(kValue), effect, control));
191 } 339 }
192 340
193 341
194 TEST_F(BytecodeGraphBuilderTest, ReturnDouble) { 342 TEST_F(BytecodeGraphBuilderTest, ReturnDouble) {
195 const double kValue = 0.123456789; 343 const double kValue = 0.123456789;
196 array_builder()->set_locals_count(0); 344 array_builder()->set_locals_count(0);
197 array_builder()->set_context_count(0); 345 array_builder()->set_context_count(0);
198 array_builder()->set_parameter_count(1); 346 array_builder()->set_parameter_count(1);
199 array_builder()->LoadLiteral(factory()->NewHeapNumber(kValue)); 347 array_builder()->LoadLiteral(factory()->NewHeapNumber(kValue));
200 array_builder()->Return(); 348 array_builder()->Return();
201 349
202 Graph* graph = GetCompletedGraph(); 350 GraphGeneratorHelper helper(isolate(), zone(),
351 array_builder()->ToBytecodeArray());
352 Graph* graph = helper.GetCompletedGraph();
203 Node* end = graph->end(); 353 Node* end = graph->end();
204 EXPECT_EQ(1, end->InputCount()); 354 EXPECT_EQ(1, end->InputCount());
205 Node* ret = end->InputAt(0); 355 Node* ret = end->InputAt(0);
206 Node* effect = graph->start(); 356 Node* effect = graph->start();
207 Node* control = graph->start(); 357 Node* control = graph->start();
208 EXPECT_THAT(ret, IsReturn(IsNumberConstant(kValue), effect, control)); 358 EXPECT_THAT(ret, IsReturn(IsNumberConstant(kValue), effect, control));
209 } 359 }
210 360
211 361
212 TEST_F(BytecodeGraphBuilderTest, SimpleExpressionWithParameters) { 362 TEST_F(BytecodeGraphBuilderTest, SimpleExpressionWithParameters) {
213 array_builder()->set_locals_count(1); 363 array_builder()->set_locals_count(1);
214 array_builder()->set_context_count(0); 364 array_builder()->set_context_count(0);
215 array_builder()->set_parameter_count(3); 365 array_builder()->set_parameter_count(3);
216 array_builder() 366 array_builder()
217 ->LoadAccumulatorWithRegister(array_builder()->Parameter(1)) 367 ->LoadAccumulatorWithRegister(array_builder()->Parameter(1))
218 .BinaryOperation(Token::Value::ADD, array_builder()->Parameter(2), 368 .BinaryOperation(Token::Value::ADD, array_builder()->Parameter(2),
219 Strength::WEAK) 369 Strength::WEAK)
220 .StoreAccumulatorInRegister(interpreter::Register(0)) 370 .StoreAccumulatorInRegister(interpreter::Register(0))
221 .Return(); 371 .Return();
222 372
223 Graph* graph = GetCompletedGraph(); 373 GraphGeneratorHelper helper(isolate(), zone(),
374 array_builder()->ToBytecodeArray());
375 Graph* graph = helper.GetCompletedGraph();
224 Node* end = graph->end(); 376 Node* end = graph->end();
225 EXPECT_EQ(1, end->InputCount()); 377 EXPECT_EQ(1, end->InputCount());
226 Node* ret = end->InputAt(0); 378 Node* ret = end->InputAt(0);
227 // NB binary operation is <reg> <op> <acc>. The register represents 379 // NB binary operation is <reg> <op> <acc>. The register represents
228 // the left-hand side, which is why parameters appear in opposite 380 // the left-hand side, which is why parameters appear in opposite
229 // order to construction via the builder. 381 // order to construction via the builder.
230 EXPECT_THAT(ret, IsReturn(IsJSAdd(IsParameter(2), IsParameter(1)), _, _)); 382 EXPECT_THAT(ret, IsReturn(IsJSAdd(IsParameter(2), IsParameter(1)), _, _));
231 } 383 }
232 384
233 385
234 TEST_F(BytecodeGraphBuilderTest, SimpleExpressionWithRegister) { 386 TEST_F(BytecodeGraphBuilderTest, SimpleExpressionWithRegister) {
235 static const int kLeft = -655371; 387 static const int kLeft = -655371;
236 static const int kRight = +2000000; 388 static const int kRight = +2000000;
237 array_builder()->set_locals_count(1); 389 array_builder()->set_locals_count(1);
238 array_builder()->set_context_count(0); 390 array_builder()->set_context_count(0);
239 array_builder()->set_parameter_count(1); 391 array_builder()->set_parameter_count(1);
240 array_builder() 392 array_builder()
241 ->LoadLiteral(Smi::FromInt(kLeft)) 393 ->LoadLiteral(Smi::FromInt(kLeft))
242 .StoreAccumulatorInRegister(interpreter::Register(0)) 394 .StoreAccumulatorInRegister(interpreter::Register(0))
243 .LoadLiteral(Smi::FromInt(kRight)) 395 .LoadLiteral(Smi::FromInt(kRight))
244 .BinaryOperation(Token::Value::ADD, interpreter::Register(0), 396 .BinaryOperation(Token::Value::ADD, interpreter::Register(0),
245 Strength::WEAK) 397 Strength::WEAK)
246 .Return(); 398 .Return();
247 399
248 Graph* graph = GetCompletedGraph(); 400 GraphGeneratorHelper helper(isolate(), zone(),
401 array_builder()->ToBytecodeArray());
402 Graph* graph = helper.GetCompletedGraph();
249 Node* end = graph->end(); 403 Node* end = graph->end();
250 EXPECT_EQ(1, end->InputCount()); 404 EXPECT_EQ(1, end->InputCount());
251 Node* ret = end->InputAt(0); 405 Node* ret = end->InputAt(0);
252 EXPECT_THAT( 406 EXPECT_THAT(
253 ret, IsReturn(IsJSAdd(IsNumberConstant(kLeft), IsNumberConstant(kRight)), 407 ret, IsReturn(IsJSAdd(IsNumberConstant(kLeft), IsNumberConstant(kRight)),
254 _, _)); 408 _, _));
255 } 409 }
256 410
411
412 TEST_F(BytecodeGraphBuilderTest, NamedLoadSloppy) {
413 const char* code_snippet = "function f(p1) {return p1.val;}; f({val:10});";
414 GraphGeneratorHelper helper(isolate(), zone(), code_snippet);
415 Graph* graph = helper.GetCompletedGraph();
416
417 Node* ret = graph->end()->InputAt(0);
418 Node* start = graph->start();
419
420 Handle<Name> name = GraphGeneratorHelper::GetName(isolate(), "val");
421 Matcher<Node*> feedback_vector_matcher = IsFeedbackVector(start, start);
422 Matcher<Node*> load_named_matcher = IsJSLoadNamed(
423 name, IsParameter(1), feedback_vector_matcher, start, start);
424
425 EXPECT_THAT(ret, IsReturn(load_named_matcher, _, _));
426 }
427
428
429 TEST_F(BytecodeGraphBuilderTest, NamedLoadStrict) {
430 const char* code_snippet =
431 "function f(p1) {'use strict'; return p1.val;}; f({val:10});";
432 GraphGeneratorHelper helper(isolate(), zone(), code_snippet);
433 Graph* graph = helper.GetCompletedGraph();
434
435 Node* ret = graph->end()->InputAt(0);
436 Node* start = graph->start();
437
438 Handle<Name> name = GraphGeneratorHelper::GetName(isolate(), "val");
439 Matcher<Node*> feedback_vector_matcher = IsFeedbackVector(start, start);
440 Matcher<Node*> load_named_matcher = IsJSLoadNamed(
441 name, IsParameter(1), feedback_vector_matcher, start, start);
442
443 EXPECT_THAT(ret, IsReturn(load_named_matcher, _, _));
444 }
445
446
447 TEST_F(BytecodeGraphBuilderTest, NamedLoadSloppyWide) {
448 const char code_snippet[] = "function f(p1) {var b; "
449 REPEAT_127(SPACE, " b = p1.val_prev; ")
450 "return p1.val;}; f({val:10, val_prev:20});";
451 GraphGeneratorHelper helper(isolate(), zone(), code_snippet);
452 Graph* graph = helper.GetCompletedGraph();
453
454 Node* ret = graph->end()->InputAt(0);
455 Node* start = graph->start();
456
457 Handle<Name> name = GraphGeneratorHelper::GetName(isolate(), "val");
458 Matcher<Node*> feedback_vector_matcher = IsFeedbackVector(start, start);
459 Matcher<Node*> preceeding_load = IsJSLoadNamed(
460 GraphGeneratorHelper::GetName(isolate(), "val_prev"), _, _, _, _);
461 Matcher<Node*> load_named_matcher_wide =
462 IsJSLoadNamed(name, IsParameter(1), feedback_vector_matcher,
463 preceeding_load, IsIfSuccess(_));
464
465 EXPECT_THAT(ret, IsReturn(load_named_matcher_wide, _, _));
466 }
467
468
469 TEST_F(BytecodeGraphBuilderTest, NamedLoadStrictWide) {
470 const char code_snippet[] = "function f(p1) {'use strict'; var b;"
471 REPEAT_127(SPACE, " b = p1.val_prev; ")
472 "return p1.val;}; f({val:10, val_prev:20});";
473 GraphGeneratorHelper helper(isolate(), zone(), code_snippet);
474 Graph* graph = helper.GetCompletedGraph();
475
476 Node* ret = graph->end()->InputAt(0);
477 Node* start = graph->start();
478
479 Handle<Name> name = GraphGeneratorHelper::GetName(isolate(), "val");
480 Matcher<Node*> feedback_vector_matcher = IsFeedbackVector(start, start);
481 Matcher<Node*> preceeding_load = IsJSLoadNamed(
482 GraphGeneratorHelper::GetName(isolate(), "val_prev"), _, _, _, _);
483 Matcher<Node*> load_named_matcher_wide =
484 IsJSLoadNamed(name, IsParameter(1), feedback_vector_matcher,
485 preceeding_load, IsIfSuccess(_));
486
487 EXPECT_THAT(ret, IsReturn(load_named_matcher_wide, _, _));
488 }
489
257 } // namespace compiler 490 } // namespace compiler
258 } // namespace internal 491 } // namespace internal
259 } // namespace v8 492 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698