OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/factory.h" | 7 #include "src/factory.h" |
8 #include "src/interpreter/bytecode-peephole-optimizer.h" | 8 #include "src/interpreter/bytecode-peephole-optimizer.h" |
9 #include "src/interpreter/constant-array-builder.h" | 9 #include "src/interpreter/constant-array-builder.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 optimizer()->Write(&first); | 373 optimizer()->Write(&first); |
374 CHECK_EQ(write_count(), 0); | 374 CHECK_EQ(write_count(), 0); |
375 optimizer()->Write(&second); | 375 optimizer()->Write(&second); |
376 CHECK_EQ(write_count(), 0); | 376 CHECK_EQ(write_count(), 0); |
377 optimizer()->FlushBasicBlock(); | 377 optimizer()->FlushBasicBlock(); |
378 CHECK_EQ(write_count(), 1); | 378 CHECK_EQ(write_count(), 1); |
379 second.source_info().Update(first.source_info()); | 379 second.source_info().Update(first.source_info()); |
380 CHECK_EQ(last_written(), second); | 380 CHECK_EQ(last_written(), second); |
381 } | 381 } |
382 | 382 |
| 383 // Tests covering BytecodePeepholeOptimizer::UpdateLastAndCurrentBytecodes(). |
| 384 |
| 385 TEST_F(BytecodePeepholeOptimizerTest, MergeLoadICStar) { |
| 386 const uint32_t operands[] = { |
| 387 static_cast<uint32_t>(Register(31).ToOperand()), 32, 33, |
| 388 static_cast<uint32_t>(Register(256).ToOperand())}; |
| 389 const int expected_operand_count = static_cast<int>(arraysize(operands)); |
| 390 |
| 391 BytecodeNode first(Bytecode::kLoadIC, operands[0], operands[1], operands[2], |
| 392 OperandScale::kSingle); |
| 393 BytecodeNode second(Bytecode::kStar, operands[3], OperandScale::kDouble); |
| 394 BytecodeNode third(Bytecode::kReturn); |
| 395 optimizer()->Write(&first); |
| 396 optimizer()->Write(&second); |
| 397 CHECK_EQ(write_count(), 1); |
| 398 CHECK_EQ(last_written().bytecode(), Bytecode::kLdrNamedProperty); |
| 399 CHECK_EQ(last_written().operand_count(), expected_operand_count); |
| 400 for (int i = 0; i < expected_operand_count; ++i) { |
| 401 CHECK_EQ(last_written().operand(i), operands[i]); |
| 402 } |
| 403 CHECK_EQ(last_written().operand_scale(), |
| 404 std::max(first.operand_scale(), second.operand_scale())); |
| 405 optimizer()->Write(&third); |
| 406 CHECK_EQ(write_count(), 2); |
| 407 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar); |
| 408 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]); |
| 409 optimizer()->FlushBasicBlock(); |
| 410 CHECK_EQ(last_written().bytecode(), third.bytecode()); |
| 411 } |
| 412 |
| 413 TEST_F(BytecodePeepholeOptimizerTest, MergeKeyedLoadICStar) { |
| 414 const uint32_t operands[] = {static_cast<uint32_t>(Register(31).ToOperand()), |
| 415 9999997, |
| 416 static_cast<uint32_t>(Register(1).ToOperand())}; |
| 417 const int expected_operand_count = static_cast<int>(arraysize(operands)); |
| 418 |
| 419 BytecodeNode first(Bytecode::kKeyedLoadIC, operands[0], operands[1], |
| 420 OperandScale::kQuadruple); |
| 421 BytecodeNode second(Bytecode::kStar, operands[2], OperandScale::kSingle); |
| 422 BytecodeNode third(Bytecode::kReturn); |
| 423 optimizer()->Write(&first); |
| 424 optimizer()->Write(&second); |
| 425 CHECK_EQ(write_count(), 1); |
| 426 CHECK_EQ(last_written().bytecode(), Bytecode::kLdrKeyedProperty); |
| 427 CHECK_EQ(last_written().operand_count(), expected_operand_count); |
| 428 for (int i = 0; i < expected_operand_count; ++i) { |
| 429 CHECK_EQ(last_written().operand(i), operands[i]); |
| 430 } |
| 431 CHECK_EQ(last_written().operand_scale(), |
| 432 std::max(first.operand_scale(), second.operand_scale())); |
| 433 optimizer()->Write(&third); |
| 434 CHECK_EQ(write_count(), 2); |
| 435 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar); |
| 436 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]); |
| 437 optimizer()->FlushBasicBlock(); |
| 438 CHECK_EQ(last_written().bytecode(), third.bytecode()); |
| 439 } |
| 440 |
| 441 TEST_F(BytecodePeepholeOptimizerTest, MergeLdaGlobalStar) { |
| 442 const uint32_t operands[] = {54321, 19191, |
| 443 static_cast<uint32_t>(Register(1).ToOperand())}; |
| 444 const int expected_operand_count = static_cast<int>(arraysize(operands)); |
| 445 |
| 446 BytecodeNode first(Bytecode::kLdaGlobal, operands[0], operands[1], |
| 447 OperandScale::kDouble); |
| 448 BytecodeNode second(Bytecode::kStar, operands[2], OperandScale::kSingle); |
| 449 BytecodeNode third(Bytecode::kReturn); |
| 450 optimizer()->Write(&first); |
| 451 optimizer()->Write(&second); |
| 452 CHECK_EQ(write_count(), 1); |
| 453 CHECK_EQ(last_written().bytecode(), Bytecode::kLdrGlobal); |
| 454 CHECK_EQ(last_written().operand_count(), expected_operand_count); |
| 455 for (int i = 0; i < expected_operand_count; ++i) { |
| 456 CHECK_EQ(last_written().operand(i), operands[i]); |
| 457 } |
| 458 CHECK_EQ(last_written().operand_scale(), |
| 459 std::max(first.operand_scale(), second.operand_scale())); |
| 460 optimizer()->Write(&third); |
| 461 CHECK_EQ(write_count(), 2); |
| 462 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar); |
| 463 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]); |
| 464 optimizer()->FlushBasicBlock(); |
| 465 CHECK_EQ(last_written().bytecode(), third.bytecode()); |
| 466 } |
| 467 |
| 468 TEST_F(BytecodePeepholeOptimizerTest, MergeLdaContextSlotStar) { |
| 469 const uint32_t operands[] = { |
| 470 static_cast<uint32_t>(Register(200000).ToOperand()), 55005500, |
| 471 static_cast<uint32_t>(Register(1).ToOperand())}; |
| 472 const int expected_operand_count = static_cast<int>(arraysize(operands)); |
| 473 |
| 474 BytecodeNode first(Bytecode::kLdaContextSlot, operands[0], operands[1], |
| 475 OperandScale::kQuadruple); |
| 476 BytecodeNode second(Bytecode::kStar, operands[2], OperandScale::kSingle); |
| 477 BytecodeNode third(Bytecode::kReturn); |
| 478 optimizer()->Write(&first); |
| 479 optimizer()->Write(&second); |
| 480 CHECK_EQ(write_count(), 1); |
| 481 CHECK_EQ(last_written().bytecode(), Bytecode::kLdrContextSlot); |
| 482 CHECK_EQ(last_written().operand_count(), expected_operand_count); |
| 483 for (int i = 0; i < expected_operand_count; ++i) { |
| 484 CHECK_EQ(last_written().operand(i), operands[i]); |
| 485 } |
| 486 CHECK_EQ(last_written().operand_scale(), |
| 487 std::max(first.operand_scale(), second.operand_scale())); |
| 488 optimizer()->Write(&third); |
| 489 CHECK_EQ(write_count(), 2); |
| 490 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar); |
| 491 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]); |
| 492 optimizer()->FlushBasicBlock(); |
| 493 CHECK_EQ(last_written().bytecode(), third.bytecode()); |
| 494 } |
| 495 |
| 496 TEST_F(BytecodePeepholeOptimizerTest, MergeLdaUndefinedStar) { |
| 497 const uint32_t operands[] = { |
| 498 static_cast<uint32_t>(Register(100000).ToOperand())}; |
| 499 const int expected_operand_count = static_cast<int>(arraysize(operands)); |
| 500 |
| 501 BytecodeNode first(Bytecode::kLdaUndefined); |
| 502 BytecodeNode second(Bytecode::kStar, operands[0], OperandScale::kQuadruple); |
| 503 BytecodeNode third(Bytecode::kReturn); |
| 504 optimizer()->Write(&first); |
| 505 optimizer()->Write(&second); |
| 506 CHECK_EQ(write_count(), 1); |
| 507 CHECK_EQ(last_written().bytecode(), Bytecode::kLdrUndefined); |
| 508 CHECK_EQ(last_written().operand_count(), expected_operand_count); |
| 509 for (int i = 0; i < expected_operand_count; ++i) { |
| 510 CHECK_EQ(last_written().operand(i), operands[i]); |
| 511 } |
| 512 CHECK_EQ(last_written().operand_scale(), |
| 513 std::max(first.operand_scale(), second.operand_scale())); |
| 514 optimizer()->Write(&third); |
| 515 CHECK_EQ(write_count(), 2); |
| 516 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar); |
| 517 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]); |
| 518 optimizer()->FlushBasicBlock(); |
| 519 CHECK_EQ(last_written().bytecode(), third.bytecode()); |
| 520 } |
| 521 |
383 } // namespace interpreter | 522 } // namespace interpreter |
384 } // namespace internal | 523 } // namespace internal |
385 } // namespace v8 | 524 } // namespace v8 |
OLD | NEW |