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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 optimizer()->Write(&first); | 347 optimizer()->Write(&first); |
348 CHECK_EQ(write_count(), 0); | 348 CHECK_EQ(write_count(), 0); |
349 optimizer()->Write(&second); | 349 optimizer()->Write(&second); |
350 CHECK_EQ(write_count(), 0); | 350 CHECK_EQ(write_count(), 0); |
351 optimizer()->FlushBasicBlock(); | 351 optimizer()->FlushBasicBlock(); |
352 CHECK_EQ(write_count(), 1); | 352 CHECK_EQ(write_count(), 1); |
353 second.source_info().Update(first.source_info()); | 353 second.source_info().Update(first.source_info()); |
354 CHECK_EQ(last_written(), second); | 354 CHECK_EQ(last_written(), second); |
355 } | 355 } |
356 | 356 |
| 357 // Tests covering BytecodePeepholeOptimizer::RewriteLastAndCurrent(). |
| 358 |
| 359 TEST_F(BytecodePeepholeOptimizerTest, MergeLoadICStar) { |
| 360 const uint32_t operands[] = { |
| 361 static_cast<uint32_t>(Register(31).ToOperand()), 32, 33, |
| 362 static_cast<uint32_t>(Register(256).ToOperand())}; |
| 363 const int expected_operand_count = static_cast<int>(arraysize(operands)); |
| 364 |
| 365 BytecodeNode first(Bytecode::kLdaNamedProperty, operands[0], operands[1], |
| 366 operands[2], OperandScale::kSingle); |
| 367 BytecodeNode second(Bytecode::kStar, operands[3], OperandScale::kDouble); |
| 368 BytecodeNode third(Bytecode::kReturn); |
| 369 optimizer()->Write(&first); |
| 370 optimizer()->Write(&second); |
| 371 CHECK_EQ(write_count(), 1); |
| 372 CHECK_EQ(last_written().bytecode(), Bytecode::kLdrNamedProperty); |
| 373 CHECK_EQ(last_written().operand_count(), expected_operand_count); |
| 374 for (int i = 0; i < expected_operand_count; ++i) { |
| 375 CHECK_EQ(last_written().operand(i), operands[i]); |
| 376 } |
| 377 CHECK_EQ(last_written().operand_scale(), |
| 378 std::max(first.operand_scale(), second.operand_scale())); |
| 379 optimizer()->Write(&third); |
| 380 CHECK_EQ(write_count(), 2); |
| 381 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar); |
| 382 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]); |
| 383 optimizer()->FlushBasicBlock(); |
| 384 CHECK_EQ(last_written().bytecode(), third.bytecode()); |
| 385 } |
| 386 |
| 387 TEST_F(BytecodePeepholeOptimizerTest, MergeKeyedLoadICStar) { |
| 388 const uint32_t operands[] = {static_cast<uint32_t>(Register(31).ToOperand()), |
| 389 9999997, |
| 390 static_cast<uint32_t>(Register(1).ToOperand())}; |
| 391 const int expected_operand_count = static_cast<int>(arraysize(operands)); |
| 392 |
| 393 BytecodeNode first(Bytecode::kLdaKeyedProperty, operands[0], operands[1], |
| 394 OperandScale::kQuadruple); |
| 395 BytecodeNode second(Bytecode::kStar, operands[2], OperandScale::kSingle); |
| 396 BytecodeNode third(Bytecode::kReturn); |
| 397 optimizer()->Write(&first); |
| 398 optimizer()->Write(&second); |
| 399 CHECK_EQ(write_count(), 1); |
| 400 CHECK_EQ(last_written().bytecode(), Bytecode::kLdrKeyedProperty); |
| 401 CHECK_EQ(last_written().operand_count(), expected_operand_count); |
| 402 for (int i = 0; i < expected_operand_count; ++i) { |
| 403 CHECK_EQ(last_written().operand(i), operands[i]); |
| 404 } |
| 405 CHECK_EQ(last_written().operand_scale(), |
| 406 std::max(first.operand_scale(), second.operand_scale())); |
| 407 optimizer()->Write(&third); |
| 408 CHECK_EQ(write_count(), 2); |
| 409 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar); |
| 410 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]); |
| 411 optimizer()->FlushBasicBlock(); |
| 412 CHECK_EQ(last_written().bytecode(), third.bytecode()); |
| 413 } |
| 414 |
| 415 TEST_F(BytecodePeepholeOptimizerTest, MergeLdaGlobalStar) { |
| 416 const uint32_t operands[] = {54321, 19191, |
| 417 static_cast<uint32_t>(Register(1).ToOperand())}; |
| 418 const int expected_operand_count = static_cast<int>(arraysize(operands)); |
| 419 |
| 420 BytecodeNode first(Bytecode::kLdaGlobal, operands[0], operands[1], |
| 421 OperandScale::kDouble); |
| 422 BytecodeNode second(Bytecode::kStar, operands[2], OperandScale::kSingle); |
| 423 BytecodeNode third(Bytecode::kReturn); |
| 424 optimizer()->Write(&first); |
| 425 optimizer()->Write(&second); |
| 426 CHECK_EQ(write_count(), 1); |
| 427 CHECK_EQ(last_written().bytecode(), Bytecode::kLdrGlobal); |
| 428 CHECK_EQ(last_written().operand_count(), expected_operand_count); |
| 429 for (int i = 0; i < expected_operand_count; ++i) { |
| 430 CHECK_EQ(last_written().operand(i), operands[i]); |
| 431 } |
| 432 CHECK_EQ(last_written().operand_scale(), |
| 433 std::max(first.operand_scale(), second.operand_scale())); |
| 434 optimizer()->Write(&third); |
| 435 CHECK_EQ(write_count(), 2); |
| 436 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar); |
| 437 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]); |
| 438 optimizer()->FlushBasicBlock(); |
| 439 CHECK_EQ(last_written().bytecode(), third.bytecode()); |
| 440 } |
| 441 |
| 442 TEST_F(BytecodePeepholeOptimizerTest, MergeLdaContextSlotStar) { |
| 443 const uint32_t operands[] = { |
| 444 static_cast<uint32_t>(Register(200000).ToOperand()), 55005500, |
| 445 static_cast<uint32_t>(Register(1).ToOperand())}; |
| 446 const int expected_operand_count = static_cast<int>(arraysize(operands)); |
| 447 |
| 448 BytecodeNode first(Bytecode::kLdaContextSlot, operands[0], operands[1], |
| 449 OperandScale::kQuadruple); |
| 450 BytecodeNode second(Bytecode::kStar, operands[2], OperandScale::kSingle); |
| 451 BytecodeNode third(Bytecode::kReturn); |
| 452 optimizer()->Write(&first); |
| 453 optimizer()->Write(&second); |
| 454 CHECK_EQ(write_count(), 1); |
| 455 CHECK_EQ(last_written().bytecode(), Bytecode::kLdrContextSlot); |
| 456 CHECK_EQ(last_written().operand_count(), expected_operand_count); |
| 457 for (int i = 0; i < expected_operand_count; ++i) { |
| 458 CHECK_EQ(last_written().operand(i), operands[i]); |
| 459 } |
| 460 CHECK_EQ(last_written().operand_scale(), |
| 461 std::max(first.operand_scale(), second.operand_scale())); |
| 462 optimizer()->Write(&third); |
| 463 CHECK_EQ(write_count(), 2); |
| 464 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar); |
| 465 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]); |
| 466 optimizer()->FlushBasicBlock(); |
| 467 CHECK_EQ(last_written().bytecode(), third.bytecode()); |
| 468 } |
| 469 |
| 470 TEST_F(BytecodePeepholeOptimizerTest, MergeLdaUndefinedStar) { |
| 471 const uint32_t operands[] = { |
| 472 static_cast<uint32_t>(Register(100000).ToOperand())}; |
| 473 const int expected_operand_count = static_cast<int>(arraysize(operands)); |
| 474 |
| 475 BytecodeNode first(Bytecode::kLdaUndefined); |
| 476 BytecodeNode second(Bytecode::kStar, operands[0], OperandScale::kQuadruple); |
| 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::kLdrUndefined); |
| 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 |
357 } // namespace interpreter | 496 } // namespace interpreter |
358 } // namespace internal | 497 } // namespace internal |
359 } // namespace v8 | 498 } // namespace v8 |
OLD | NEW |