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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 BailoutId bailout_id(42); | 323 BailoutId bailout_id(42); |
324 | 324 |
325 Node* function_node = m.Parameter(0); | 325 Node* function_node = m.Parameter(0); |
326 Node* receiver = m.Parameter(1); | 326 Node* receiver = m.Parameter(1); |
327 | 327 |
328 Node* parameters = m.NewNode(m.common()->StateValues(1), m.Int32Constant(1)); | 328 Node* parameters = m.NewNode(m.common()->StateValues(1), m.Int32Constant(1)); |
329 Node* locals = m.NewNode(m.common()->StateValues(0)); | 329 Node* locals = m.NewNode(m.common()->StateValues(0)); |
330 Node* stack = m.NewNode(m.common()->StateValues(0)); | 330 Node* stack = m.NewNode(m.common()->StateValues(0)); |
331 Node* context_dummy = m.Int32Constant(0); | 331 Node* context_dummy = m.Int32Constant(0); |
332 | 332 |
333 Node* state_node = m.NewNode(m.common()->FrameState(bailout_id, kPushOutput), | 333 Node* state_node = |
334 parameters, locals, stack, context_dummy); | 334 m.NewNode(m.common()->FrameState(bailout_id, kPushOutput), parameters, |
| 335 locals, stack, context_dummy, m.UndefinedConstant()); |
335 Node* call = m.CallJS0(function_node, receiver, state_node); | 336 Node* call = m.CallJS0(function_node, receiver, state_node); |
336 m.Return(call); | 337 m.Return(call); |
337 | 338 |
338 Stream s = m.Build(kAllExceptNopInstructions); | 339 Stream s = m.Build(kAllExceptNopInstructions); |
339 | 340 |
340 // Skip until kArchCallJSFunction. | 341 // Skip until kArchCallJSFunction. |
341 size_t index = 0; | 342 size_t index = 0; |
342 for (; index < s.size() && s[index]->arch_opcode() != kArchCallJSFunction; | 343 for (; index < s.size() && s[index]->arch_opcode() != kArchCallJSFunction; |
343 index++) { | 344 index++) { |
344 } | 345 } |
(...skipping 15 matching lines...) Expand all Loading... |
360 | 361 |
361 // Some arguments for the call node. | 362 // Some arguments for the call node. |
362 Node* function_node = m.Parameter(0); | 363 Node* function_node = m.Parameter(0); |
363 Node* receiver = m.Parameter(1); | 364 Node* receiver = m.Parameter(1); |
364 Node* context = m.Int32Constant(1); // Context is ignored. | 365 Node* context = m.Int32Constant(1); // Context is ignored. |
365 | 366 |
366 // Build frame state for the state before the call. | 367 // Build frame state for the state before the call. |
367 Node* parameters = m.NewNode(m.common()->StateValues(1), m.Int32Constant(43)); | 368 Node* parameters = m.NewNode(m.common()->StateValues(1), m.Int32Constant(43)); |
368 Node* locals = m.NewNode(m.common()->StateValues(1), m.Int32Constant(44)); | 369 Node* locals = m.NewNode(m.common()->StateValues(1), m.Int32Constant(44)); |
369 Node* stack = m.NewNode(m.common()->StateValues(1), m.Int32Constant(45)); | 370 Node* stack = m.NewNode(m.common()->StateValues(1), m.Int32Constant(45)); |
| 371 |
370 Node* context_sentinel = m.Int32Constant(0); | 372 Node* context_sentinel = m.Int32Constant(0); |
371 Node* frame_state_before = | 373 Node* frame_state_before = m.NewNode( |
372 m.NewNode(m.common()->FrameState(bailout_id_before, kPushOutput), | 374 m.common()->FrameState(bailout_id_before, kPushOutput), parameters, |
373 parameters, locals, stack, context_sentinel); | 375 locals, stack, context_sentinel, m.UndefinedConstant()); |
374 | 376 |
375 // Build the call. | 377 // Build the call. |
376 Node* call = m.CallFunctionStub0(function_node, receiver, context, | 378 Node* call = m.CallFunctionStub0(function_node, receiver, context, |
377 frame_state_before, CALL_AS_METHOD); | 379 frame_state_before, CALL_AS_METHOD); |
378 | 380 |
379 m.Return(call); | 381 m.Return(call); |
380 | 382 |
381 Stream s = m.Build(kAllExceptNopInstructions); | 383 Stream s = m.Build(kAllExceptNopInstructions); |
382 | 384 |
383 // Skip until kArchCallJSFunction. | 385 // Skip until kArchCallJSFunction. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 // Function. | 421 // Function. |
420 EXPECT_EQ(function_node->id(), s.ToVreg(call_instr->InputAt(6))); | 422 EXPECT_EQ(function_node->id(), s.ToVreg(call_instr->InputAt(6))); |
421 // Context. | 423 // Context. |
422 EXPECT_EQ(context->id(), s.ToVreg(call_instr->InputAt(7))); | 424 EXPECT_EQ(context->id(), s.ToVreg(call_instr->InputAt(7))); |
423 | 425 |
424 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); | 426 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); |
425 | 427 |
426 EXPECT_EQ(index, s.size()); | 428 EXPECT_EQ(index, s.size()); |
427 } | 429 } |
428 | 430 |
| 431 |
| 432 TARGET_TEST_F(InstructionSelectorTest, |
| 433 CallFunctionStubDeoptRecursiveFrameState) { |
| 434 StreamBuilder m(this, kMachAnyTagged, kMachAnyTagged, kMachAnyTagged, |
| 435 kMachAnyTagged); |
| 436 |
| 437 BailoutId bailout_id_before(42); |
| 438 BailoutId bailout_id_parent(62); |
| 439 |
| 440 // Some arguments for the call node. |
| 441 Node* function_node = m.Parameter(0); |
| 442 Node* receiver = m.Parameter(1); |
| 443 Node* context = m.Int32Constant(66); |
| 444 |
| 445 // Build frame state for the state before the call. |
| 446 Node* parameters = m.NewNode(m.common()->StateValues(1), m.Int32Constant(63)); |
| 447 Node* locals = m.NewNode(m.common()->StateValues(1), m.Int32Constant(64)); |
| 448 Node* stack = m.NewNode(m.common()->StateValues(1), m.Int32Constant(65)); |
| 449 Node* frame_state_parent = |
| 450 m.NewNode(m.common()->FrameState(bailout_id_parent, kIgnoreOutput), |
| 451 parameters, locals, stack, context, m.UndefinedConstant()); |
| 452 |
| 453 Node* context2 = m.Int32Constant(46); |
| 454 Node* parameters2 = |
| 455 m.NewNode(m.common()->StateValues(1), m.Int32Constant(43)); |
| 456 Node* locals2 = m.NewNode(m.common()->StateValues(1), m.Int32Constant(44)); |
| 457 Node* stack2 = m.NewNode(m.common()->StateValues(1), m.Int32Constant(45)); |
| 458 Node* frame_state_before = |
| 459 m.NewNode(m.common()->FrameState(bailout_id_before, kPushOutput), |
| 460 parameters2, locals2, stack2, context2, frame_state_parent); |
| 461 |
| 462 // Build the call. |
| 463 Node* call = m.CallFunctionStub0(function_node, receiver, context2, |
| 464 frame_state_before, CALL_AS_METHOD); |
| 465 |
| 466 m.Return(call); |
| 467 |
| 468 Stream s = m.Build(kAllExceptNopInstructions); |
| 469 |
| 470 // Skip until kArchCallJSFunction. |
| 471 size_t index = 0; |
| 472 for (; index < s.size() && s[index]->arch_opcode() != kArchCallCodeObject; |
| 473 index++) { |
| 474 } |
| 475 // Now we should have three instructions: call, return. |
| 476 EXPECT_EQ(index + 2, s.size()); |
| 477 |
| 478 // Check the call instruction |
| 479 const Instruction* call_instr = s[index++]; |
| 480 EXPECT_EQ(kArchCallCodeObject, call_instr->arch_opcode()); |
| 481 size_t num_operands = |
| 482 1 + // Code object. |
| 483 1 + // Frame state deopt id |
| 484 4 + // One input for each value in frame state + context. |
| 485 4 + // One input for each value in the parent frame state + context. |
| 486 1 + // Function. |
| 487 1; // Context. |
| 488 EXPECT_EQ(num_operands, call_instr->InputCount()); |
| 489 // Code object. |
| 490 EXPECT_TRUE(call_instr->InputAt(0)->IsImmediate()); |
| 491 |
| 492 // Deoptimization id. |
| 493 int32_t deopt_id_before = s.ToInt32(call_instr->InputAt(1)); |
| 494 FrameStateDescriptor* desc_before = |
| 495 s.GetFrameStateDescriptor(deopt_id_before); |
| 496 EXPECT_EQ(bailout_id_before, desc_before->bailout_id()); |
| 497 EXPECT_EQ(1, desc_before->parameters_count()); |
| 498 EXPECT_EQ(1, desc_before->locals_count()); |
| 499 EXPECT_EQ(1, desc_before->stack_count()); |
| 500 EXPECT_EQ(63, s.ToInt32(call_instr->InputAt(2))); |
| 501 // Context: |
| 502 EXPECT_EQ(66, s.ToInt32(call_instr->InputAt(3))); |
| 503 EXPECT_EQ(64, s.ToInt32(call_instr->InputAt(4))); |
| 504 EXPECT_EQ(65, s.ToInt32(call_instr->InputAt(5))); |
| 505 // Values from parent environment should follow. |
| 506 EXPECT_EQ(43, s.ToInt32(call_instr->InputAt(6))); |
| 507 EXPECT_EQ(46, s.ToInt32(call_instr->InputAt(7))); |
| 508 EXPECT_EQ(44, s.ToInt32(call_instr->InputAt(8))); |
| 509 EXPECT_EQ(45, s.ToInt32(call_instr->InputAt(9))); |
| 510 |
| 511 // Function. |
| 512 EXPECT_EQ(function_node->id(), s.ToVreg(call_instr->InputAt(10))); |
| 513 // Context. |
| 514 EXPECT_EQ(context2->id(), s.ToVreg(call_instr->InputAt(11))); |
| 515 // Continuation. |
| 516 |
| 517 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); |
| 518 EXPECT_EQ(index, s.size()); |
| 519 } |
| 520 |
429 } // namespace compiler | 521 } // namespace compiler |
430 } // namespace internal | 522 } // namespace internal |
431 } // namespace v8 | 523 } // namespace v8 |
OLD | NEW |