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 "test/unittests/compiler/instruction-selector-unittest.h" | 5 #include "test/unittests/compiler/instruction-selector-unittest.h" |
6 | 6 |
7 #include "src/flags.h" | 7 #include "src/flags.h" |
8 #include "test/unittests/compiler/compiler-test-utils.h" | 8 #include "test/unittests/compiler/compiler-test-utils.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 350 |
351 BailoutId bailout_id_before(42); | 351 BailoutId bailout_id_before(42); |
352 | 352 |
353 // Some arguments for the call node. | 353 // Some arguments for the call node. |
354 Node* function_node = m.Parameter(0); | 354 Node* function_node = m.Parameter(0); |
355 Node* receiver = m.Parameter(1); | 355 Node* receiver = m.Parameter(1); |
356 Node* context = m.Int32Constant(1); // Context is ignored. | 356 Node* context = m.Int32Constant(1); // Context is ignored. |
357 | 357 |
358 // Build frame state for the state before the call. | 358 // Build frame state for the state before the call. |
359 Node* parameters = m.NewNode(m.common()->StateValues(1), m.Int32Constant(43)); | 359 Node* parameters = m.NewNode(m.common()->StateValues(1), m.Int32Constant(43)); |
360 Node* locals = m.NewNode(m.common()->StateValues(1), m.Int32Constant(44)); | 360 Node* locals = m.NewNode(m.common()->StateValues(1), m.Float64Constant(0.5)); |
361 Node* stack = m.NewNode(m.common()->StateValues(1), m.Int32Constant(45)); | 361 Node* stack = m.NewNode(m.common()->StateValues(1), m.UndefinedConstant()); |
362 | 362 |
363 Node* context_sentinel = m.Int32Constant(0); | 363 Node* context_sentinel = m.Int32Constant(0); |
364 Node* frame_state_before = m.NewNode( | 364 Node* frame_state_before = m.NewNode( |
365 m.common()->FrameState(JS_FRAME, bailout_id_before, | 365 m.common()->FrameState(JS_FRAME, bailout_id_before, |
366 OutputFrameStateCombine::Push()), | 366 OutputFrameStateCombine::Push()), |
367 parameters, locals, stack, context_sentinel, m.UndefinedConstant()); | 367 parameters, locals, stack, context_sentinel, m.UndefinedConstant()); |
368 | 368 |
369 // Build the call. | 369 // Build the call. |
370 Node* call = m.CallFunctionStub0(function_node, receiver, context, | 370 Node* call = m.CallFunctionStub0(function_node, receiver, context, |
371 frame_state_before, CALL_AS_METHOD); | 371 frame_state_before, CALL_AS_METHOD); |
(...skipping 28 matching lines...) Expand all Loading... |
400 int32_t deopt_id_before = s.ToInt32(call_instr->InputAt(1)); | 400 int32_t deopt_id_before = s.ToInt32(call_instr->InputAt(1)); |
401 FrameStateDescriptor* desc_before = | 401 FrameStateDescriptor* desc_before = |
402 s.GetFrameStateDescriptor(deopt_id_before); | 402 s.GetFrameStateDescriptor(deopt_id_before); |
403 EXPECT_EQ(bailout_id_before, desc_before->bailout_id()); | 403 EXPECT_EQ(bailout_id_before, desc_before->bailout_id()); |
404 EXPECT_EQ(OutputFrameStateCombine::kPushOutput, | 404 EXPECT_EQ(OutputFrameStateCombine::kPushOutput, |
405 desc_before->state_combine().kind()); | 405 desc_before->state_combine().kind()); |
406 EXPECT_EQ(1u, desc_before->parameters_count()); | 406 EXPECT_EQ(1u, desc_before->parameters_count()); |
407 EXPECT_EQ(1u, desc_before->locals_count()); | 407 EXPECT_EQ(1u, desc_before->locals_count()); |
408 EXPECT_EQ(1u, desc_before->stack_count()); | 408 EXPECT_EQ(1u, desc_before->stack_count()); |
409 EXPECT_EQ(43, s.ToInt32(call_instr->InputAt(2))); | 409 EXPECT_EQ(43, s.ToInt32(call_instr->InputAt(2))); |
410 EXPECT_EQ(0, s.ToInt32(call_instr->InputAt(3))); | 410 EXPECT_EQ(0, s.ToInt32(call_instr->InputAt(3))); // This should be a context. |
411 EXPECT_EQ(44, s.ToInt32(call_instr->InputAt(4))); | 411 // We inserted 0 here. |
412 EXPECT_EQ(45, s.ToInt32(call_instr->InputAt(5))); | 412 EXPECT_EQ(0.5, s.ToFloat64(call_instr->InputAt(4))); |
| 413 EXPECT_TRUE(s.ToHeapObject(call_instr->InputAt(5))->IsUndefined()); |
| 414 EXPECT_EQ(kMachInt32, desc_before->GetType(0)); |
| 415 EXPECT_EQ(kMachAnyTagged, desc_before->GetType(1)); // context is always |
| 416 // tagged/any. |
| 417 EXPECT_EQ(kMachFloat64, desc_before->GetType(2)); |
| 418 EXPECT_EQ(kMachAnyTagged, desc_before->GetType(3)); |
413 | 419 |
414 // Function. | 420 // Function. |
415 EXPECT_EQ(function_node->id(), s.ToVreg(call_instr->InputAt(6))); | 421 EXPECT_EQ(function_node->id(), s.ToVreg(call_instr->InputAt(6))); |
416 // Context. | 422 // Context. |
417 EXPECT_EQ(context->id(), s.ToVreg(call_instr->InputAt(7))); | 423 EXPECT_EQ(context->id(), s.ToVreg(call_instr->InputAt(7))); |
418 | 424 |
419 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); | 425 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); |
420 | 426 |
421 EXPECT_EQ(index, s.size()); | 427 EXPECT_EQ(index, s.size()); |
422 } | 428 } |
(...skipping 17 matching lines...) Expand all Loading... |
440 Node* locals = m.NewNode(m.common()->StateValues(1), m.Int32Constant(64)); | 446 Node* locals = m.NewNode(m.common()->StateValues(1), m.Int32Constant(64)); |
441 Node* stack = m.NewNode(m.common()->StateValues(1), m.Int32Constant(65)); | 447 Node* stack = m.NewNode(m.common()->StateValues(1), m.Int32Constant(65)); |
442 Node* frame_state_parent = | 448 Node* frame_state_parent = |
443 m.NewNode(m.common()->FrameState(JS_FRAME, bailout_id_parent, | 449 m.NewNode(m.common()->FrameState(JS_FRAME, bailout_id_parent, |
444 OutputFrameStateCombine::Ignore()), | 450 OutputFrameStateCombine::Ignore()), |
445 parameters, locals, stack, context, m.UndefinedConstant()); | 451 parameters, locals, stack, context, m.UndefinedConstant()); |
446 | 452 |
447 Node* context2 = m.Int32Constant(46); | 453 Node* context2 = m.Int32Constant(46); |
448 Node* parameters2 = | 454 Node* parameters2 = |
449 m.NewNode(m.common()->StateValues(1), m.Int32Constant(43)); | 455 m.NewNode(m.common()->StateValues(1), m.Int32Constant(43)); |
450 Node* locals2 = m.NewNode(m.common()->StateValues(1), m.Int32Constant(44)); | 456 Node* locals2 = |
451 Node* stack2 = m.NewNode(m.common()->StateValues(1), m.Int32Constant(45)); | 457 m.NewNode(m.common()->StateValues(1), m.Float64Constant(0.25)); |
| 458 Node* stack2 = m.NewNode(m.common()->StateValues(2), m.Int32Constant(44), |
| 459 m.Int32Constant(45)); |
452 Node* frame_state_before = | 460 Node* frame_state_before = |
453 m.NewNode(m.common()->FrameState(JS_FRAME, bailout_id_before, | 461 m.NewNode(m.common()->FrameState(JS_FRAME, bailout_id_before, |
454 OutputFrameStateCombine::Push()), | 462 OutputFrameStateCombine::Push()), |
455 parameters2, locals2, stack2, context2, frame_state_parent); | 463 parameters2, locals2, stack2, context2, frame_state_parent); |
456 | 464 |
457 // Build the call. | 465 // Build the call. |
458 Node* call = m.CallFunctionStub0(function_node, receiver, context2, | 466 Node* call = m.CallFunctionStub0(function_node, receiver, context2, |
459 frame_state_before, CALL_AS_METHOD); | 467 frame_state_before, CALL_AS_METHOD); |
460 | 468 |
461 m.Return(call); | 469 m.Return(call); |
462 | 470 |
463 Stream s = m.Build(kAllExceptNopInstructions); | 471 Stream s = m.Build(kAllExceptNopInstructions); |
464 | 472 |
465 // Skip until kArchCallJSFunction. | 473 // Skip until kArchCallJSFunction. |
466 size_t index = 0; | 474 size_t index = 0; |
467 for (; index < s.size() && s[index]->arch_opcode() != kArchCallCodeObject; | 475 for (; index < s.size() && s[index]->arch_opcode() != kArchCallCodeObject; |
468 index++) { | 476 index++) { |
469 } | 477 } |
470 // Now we should have three instructions: call, return. | 478 // Now we should have three instructions: call, return. |
471 EXPECT_EQ(index + 2, s.size()); | 479 EXPECT_EQ(index + 2, s.size()); |
472 | 480 |
473 // Check the call instruction | 481 // Check the call instruction |
474 const Instruction* call_instr = s[index++]; | 482 const Instruction* call_instr = s[index++]; |
475 EXPECT_EQ(kArchCallCodeObject, call_instr->arch_opcode()); | 483 EXPECT_EQ(kArchCallCodeObject, call_instr->arch_opcode()); |
476 size_t num_operands = | 484 size_t num_operands = |
477 1 + // Code object. | 485 1 + // Code object. |
478 1 + // Frame state deopt id | 486 1 + // Frame state deopt id |
479 4 + // One input for each value in frame state + context. | 487 5 + // One input for each value in frame state + context. |
480 4 + // One input for each value in the parent frame state + context. | 488 4 + // One input for each value in the parent frame state + context. |
481 1 + // Function. | 489 1 + // Function. |
482 1; // Context. | 490 1; // Context. |
483 EXPECT_EQ(num_operands, call_instr->InputCount()); | 491 EXPECT_EQ(num_operands, call_instr->InputCount()); |
484 // Code object. | 492 // Code object. |
485 EXPECT_TRUE(call_instr->InputAt(0)->IsImmediate()); | 493 EXPECT_TRUE(call_instr->InputAt(0)->IsImmediate()); |
486 | 494 |
487 // Deoptimization id. | 495 // Deoptimization id. |
488 int32_t deopt_id_before = s.ToInt32(call_instr->InputAt(1)); | 496 int32_t deopt_id_before = s.ToInt32(call_instr->InputAt(1)); |
489 FrameStateDescriptor* desc_before = | 497 FrameStateDescriptor* desc_before = |
490 s.GetFrameStateDescriptor(deopt_id_before); | 498 s.GetFrameStateDescriptor(deopt_id_before); |
| 499 FrameStateDescriptor* desc_before_outer = desc_before->outer_state(); |
491 EXPECT_EQ(bailout_id_before, desc_before->bailout_id()); | 500 EXPECT_EQ(bailout_id_before, desc_before->bailout_id()); |
| 501 EXPECT_EQ(1u, desc_before_outer->parameters_count()); |
| 502 EXPECT_EQ(1u, desc_before_outer->locals_count()); |
| 503 EXPECT_EQ(1u, desc_before_outer->stack_count()); |
| 504 // Values from parent environment. |
| 505 EXPECT_EQ(63, s.ToInt32(call_instr->InputAt(2))); |
| 506 EXPECT_EQ(kMachInt32, desc_before_outer->GetType(0)); |
| 507 // Context: |
| 508 EXPECT_EQ(66, s.ToInt32(call_instr->InputAt(3))); |
| 509 EXPECT_EQ(kMachAnyTagged, desc_before_outer->GetType(1)); |
| 510 EXPECT_EQ(64, s.ToInt32(call_instr->InputAt(4))); |
| 511 EXPECT_EQ(kMachInt32, desc_before_outer->GetType(2)); |
| 512 EXPECT_EQ(65, s.ToInt32(call_instr->InputAt(5))); |
| 513 EXPECT_EQ(kMachInt32, desc_before_outer->GetType(3)); |
| 514 // Values from the nested frame. |
492 EXPECT_EQ(1u, desc_before->parameters_count()); | 515 EXPECT_EQ(1u, desc_before->parameters_count()); |
493 EXPECT_EQ(1u, desc_before->locals_count()); | 516 EXPECT_EQ(1u, desc_before->locals_count()); |
494 EXPECT_EQ(1u, desc_before->stack_count()); | 517 EXPECT_EQ(2u, desc_before->stack_count()); |
495 EXPECT_EQ(63, s.ToInt32(call_instr->InputAt(2))); | |
496 // Context: | |
497 EXPECT_EQ(66, s.ToInt32(call_instr->InputAt(3))); | |
498 EXPECT_EQ(64, s.ToInt32(call_instr->InputAt(4))); | |
499 EXPECT_EQ(65, s.ToInt32(call_instr->InputAt(5))); | |
500 // Values from parent environment should follow. | |
501 EXPECT_EQ(43, s.ToInt32(call_instr->InputAt(6))); | 518 EXPECT_EQ(43, s.ToInt32(call_instr->InputAt(6))); |
| 519 EXPECT_EQ(kMachInt32, desc_before->GetType(0)); |
502 EXPECT_EQ(46, s.ToInt32(call_instr->InputAt(7))); | 520 EXPECT_EQ(46, s.ToInt32(call_instr->InputAt(7))); |
503 EXPECT_EQ(44, s.ToInt32(call_instr->InputAt(8))); | 521 EXPECT_EQ(kMachAnyTagged, desc_before->GetType(1)); |
504 EXPECT_EQ(45, s.ToInt32(call_instr->InputAt(9))); | 522 EXPECT_EQ(0.25, s.ToFloat64(call_instr->InputAt(8))); |
| 523 EXPECT_EQ(kMachFloat64, desc_before->GetType(2)); |
| 524 EXPECT_EQ(44, s.ToInt32(call_instr->InputAt(9))); |
| 525 EXPECT_EQ(kMachInt32, desc_before->GetType(3)); |
| 526 EXPECT_EQ(45, s.ToInt32(call_instr->InputAt(10))); |
| 527 EXPECT_EQ(kMachInt32, desc_before->GetType(4)); |
505 | 528 |
506 // Function. | 529 // Function. |
507 EXPECT_EQ(function_node->id(), s.ToVreg(call_instr->InputAt(10))); | 530 EXPECT_EQ(function_node->id(), s.ToVreg(call_instr->InputAt(11))); |
508 // Context. | 531 // Context. |
509 EXPECT_EQ(context2->id(), s.ToVreg(call_instr->InputAt(11))); | 532 EXPECT_EQ(context2->id(), s.ToVreg(call_instr->InputAt(12))); |
510 // Continuation. | 533 // Continuation. |
511 | 534 |
512 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); | 535 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); |
513 EXPECT_EQ(index, s.size()); | 536 EXPECT_EQ(index, s.size()); |
514 } | 537 } |
515 | 538 |
516 } // namespace compiler | 539 } // namespace compiler |
517 } // namespace internal | 540 } // namespace internal |
518 } // namespace v8 | 541 } // namespace v8 |
OLD | NEW |