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/compiler/instruction-selector-unittest.h" | 5 #include "src/compiler/instruction-selector-unittest.h" |
6 | 6 |
7 #include "src/flags.h" | 7 #include "src/flags.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 291 |
292 Node* function_node = m.Parameter(0); | 292 Node* function_node = m.Parameter(0); |
293 Node* receiver = m.Parameter(1); | 293 Node* receiver = m.Parameter(1); |
294 Node* context = m.Parameter(2); | 294 Node* context = m.Parameter(2); |
295 | 295 |
296 Node* parameters = m.NewNode(m.common()->StateValues(1), m.Int32Constant(1)); | 296 Node* parameters = m.NewNode(m.common()->StateValues(1), m.Int32Constant(1)); |
297 Node* locals = m.NewNode(m.common()->StateValues(0)); | 297 Node* locals = m.NewNode(m.common()->StateValues(0)); |
298 Node* stack = m.NewNode(m.common()->StateValues(0)); | 298 Node* stack = m.NewNode(m.common()->StateValues(0)); |
299 Node* context_dummy = m.Int32Constant(0); | 299 Node* context_dummy = m.Int32Constant(0); |
300 | 300 |
301 Node* state_node = m.NewNode(m.common()->FrameState(bailout_id, kPushOutput), | 301 Node* state_node = |
302 parameters, locals, stack, context_dummy); | 302 m.NewNode(m.common()->FrameState(bailout_id, kPushOutput), parameters, |
| 303 locals, stack, context_dummy, m.UndefinedConstant()); |
303 Node* call = m.CallJS0(function_node, receiver, context, state_node); | 304 Node* call = m.CallJS0(function_node, receiver, context, state_node); |
304 m.Return(call); | 305 m.Return(call); |
305 | 306 |
306 Stream s = m.Build(kAllExceptNopInstructions); | 307 Stream s = m.Build(kAllExceptNopInstructions); |
307 | 308 |
308 // Skip until kArchCallJSFunction. | 309 // Skip until kArchCallJSFunction. |
309 size_t index = 0; | 310 size_t index = 0; |
310 for (; index < s.size() && s[index]->arch_opcode() != kArchCallJSFunction; | 311 for (; index < s.size() && s[index]->arch_opcode() != kArchCallJSFunction; |
311 index++) { | 312 index++) { |
312 } | 313 } |
(...skipping 15 matching lines...) Expand all Loading... |
328 | 329 |
329 // Some arguments for the call node. | 330 // Some arguments for the call node. |
330 Node* function_node = m.Parameter(0); | 331 Node* function_node = m.Parameter(0); |
331 Node* receiver = m.Parameter(1); | 332 Node* receiver = m.Parameter(1); |
332 Node* context = m.Int32Constant(1); // Context is ignored. | 333 Node* context = m.Int32Constant(1); // Context is ignored. |
333 | 334 |
334 // Build frame state for the state before the call. | 335 // Build frame state for the state before the call. |
335 Node* parameters = m.NewNode(m.common()->StateValues(1), m.Int32Constant(43)); | 336 Node* parameters = m.NewNode(m.common()->StateValues(1), m.Int32Constant(43)); |
336 Node* locals = m.NewNode(m.common()->StateValues(1), m.Int32Constant(44)); | 337 Node* locals = m.NewNode(m.common()->StateValues(1), m.Int32Constant(44)); |
337 Node* stack = m.NewNode(m.common()->StateValues(1), m.Int32Constant(45)); | 338 Node* stack = m.NewNode(m.common()->StateValues(1), m.Int32Constant(45)); |
| 339 |
338 Node* context_sentinel = m.Int32Constant(0); | 340 Node* context_sentinel = m.Int32Constant(0); |
339 Node* frame_state_before = | 341 Node* frame_state_before = m.NewNode( |
340 m.NewNode(m.common()->FrameState(bailout_id_before, kPushOutput), | 342 m.common()->FrameState(bailout_id_before, kPushOutput), parameters, |
341 parameters, locals, stack, context_sentinel); | 343 locals, stack, context_sentinel, m.UndefinedConstant()); |
342 | 344 |
343 // Build the call. | 345 // Build the call. |
344 Node* call = m.CallFunctionStub0(function_node, receiver, context, | 346 Node* call = m.CallFunctionStub0(function_node, receiver, context, |
345 frame_state_before, CALL_AS_METHOD); | 347 frame_state_before, CALL_AS_METHOD); |
346 | 348 |
347 m.Return(call); | 349 m.Return(call); |
348 | 350 |
349 Stream s = m.Build(kAllExceptNopInstructions); | 351 Stream s = m.Build(kAllExceptNopInstructions); |
350 | 352 |
351 // Skip until kArchCallJSFunction. | 353 // Skip until kArchCallJSFunction. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 // Function. | 389 // Function. |
388 EXPECT_EQ(function_node->id(), s.ToVreg(call_instr->InputAt(6))); | 390 EXPECT_EQ(function_node->id(), s.ToVreg(call_instr->InputAt(6))); |
389 // Context. | 391 // Context. |
390 EXPECT_EQ(context->id(), s.ToVreg(call_instr->InputAt(7))); | 392 EXPECT_EQ(context->id(), s.ToVreg(call_instr->InputAt(7))); |
391 | 393 |
392 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); | 394 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); |
393 | 395 |
394 EXPECT_EQ(index, s.size()); | 396 EXPECT_EQ(index, s.size()); |
395 } | 397 } |
396 | 398 |
| 399 |
| 400 TARGET_TEST_F(InstructionSelectorTest, |
| 401 CallFunctionStubDeoptRecursiveFrameState) { |
| 402 StreamBuilder m(this, kMachAnyTagged, kMachAnyTagged, kMachAnyTagged, |
| 403 kMachAnyTagged); |
| 404 |
| 405 BailoutId bailout_id_before(42); |
| 406 BailoutId bailout_id_parent(62); |
| 407 |
| 408 // Some arguments for the call node. |
| 409 Node* function_node = m.Parameter(0); |
| 410 Node* receiver = m.Parameter(1); |
| 411 Node* context = m.Int32Constant(66); |
| 412 |
| 413 // Build frame state for the state before the call. |
| 414 Node* parameters = m.NewNode(m.common()->StateValues(1), m.Int32Constant(63)); |
| 415 Node* locals = m.NewNode(m.common()->StateValues(1), m.Int32Constant(64)); |
| 416 Node* stack = m.NewNode(m.common()->StateValues(1), m.Int32Constant(65)); |
| 417 Node* frame_state_parent = |
| 418 m.NewNode(m.common()->FrameState(bailout_id_parent, kIgnoreOutput), |
| 419 parameters, locals, stack, context, m.UndefinedConstant()); |
| 420 |
| 421 Node* context2 = m.Int32Constant(46); |
| 422 Node* parameters2 = |
| 423 m.NewNode(m.common()->StateValues(1), m.Int32Constant(43)); |
| 424 Node* locals2 = m.NewNode(m.common()->StateValues(1), m.Int32Constant(44)); |
| 425 Node* stack2 = m.NewNode(m.common()->StateValues(1), m.Int32Constant(45)); |
| 426 Node* frame_state_before = |
| 427 m.NewNode(m.common()->FrameState(bailout_id_before, kPushOutput), |
| 428 parameters2, locals2, stack2, context2, frame_state_parent); |
| 429 |
| 430 // Build the call. |
| 431 Node* call = m.CallFunctionStub0(function_node, receiver, context2, |
| 432 frame_state_before, CALL_AS_METHOD); |
| 433 |
| 434 m.Return(call); |
| 435 |
| 436 Stream s = m.Build(kAllExceptNopInstructions); |
| 437 |
| 438 // Skip until kArchCallJSFunction. |
| 439 size_t index = 0; |
| 440 for (; index < s.size() && s[index]->arch_opcode() != kArchCallCodeObject; |
| 441 index++) { |
| 442 } |
| 443 // Now we should have three instructions: call, return. |
| 444 EXPECT_EQ(index + 2, s.size()); |
| 445 |
| 446 // Check the call instruction |
| 447 const Instruction* call_instr = s[index++]; |
| 448 EXPECT_EQ(kArchCallCodeObject, call_instr->arch_opcode()); |
| 449 size_t num_operands = |
| 450 1 + // Code object. |
| 451 1 + // Frame state deopt id |
| 452 4 + // One input for each value in frame state + context. |
| 453 4 + // One input for each value in the parent frame state + context. |
| 454 1 + // Function. |
| 455 1; // Context. |
| 456 EXPECT_EQ(num_operands, call_instr->InputCount()); |
| 457 // Code object. |
| 458 EXPECT_TRUE(call_instr->InputAt(0)->IsImmediate()); |
| 459 |
| 460 // Deoptimization id. |
| 461 int32_t deopt_id_before = s.ToInt32(call_instr->InputAt(1)); |
| 462 FrameStateDescriptor* desc_before = |
| 463 s.GetFrameStateDescriptor(deopt_id_before); |
| 464 EXPECT_EQ(bailout_id_before, desc_before->bailout_id()); |
| 465 EXPECT_EQ(1, desc_before->parameters_count()); |
| 466 EXPECT_EQ(1, desc_before->locals_count()); |
| 467 EXPECT_EQ(1, desc_before->stack_count()); |
| 468 EXPECT_EQ(63, s.ToInt32(call_instr->InputAt(2))); |
| 469 // Context: |
| 470 EXPECT_EQ(66, s.ToInt32(call_instr->InputAt(3))); |
| 471 EXPECT_EQ(64, s.ToInt32(call_instr->InputAt(4))); |
| 472 EXPECT_EQ(65, s.ToInt32(call_instr->InputAt(5))); |
| 473 // Values from parent environment should follow. |
| 474 EXPECT_EQ(43, s.ToInt32(call_instr->InputAt(6))); |
| 475 EXPECT_EQ(46, s.ToInt32(call_instr->InputAt(7))); |
| 476 EXPECT_EQ(44, s.ToInt32(call_instr->InputAt(8))); |
| 477 EXPECT_EQ(45, s.ToInt32(call_instr->InputAt(9))); |
| 478 |
| 479 // Function. |
| 480 EXPECT_EQ(function_node->id(), s.ToVreg(call_instr->InputAt(10))); |
| 481 // Context. |
| 482 EXPECT_EQ(context2->id(), s.ToVreg(call_instr->InputAt(11))); |
| 483 // Continuation. |
| 484 |
| 485 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); |
| 486 EXPECT_EQ(index, s.size()); |
| 487 } |
| 488 |
397 } // namespace compiler | 489 } // namespace compiler |
398 } // namespace internal | 490 } // namespace internal |
399 } // namespace v8 | 491 } // namespace v8 |
OLD | NEW |