| 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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 381 } |
| 382 | 382 |
| 383 // Tests covering BytecodePeepholeOptimizer::UpdateLastAndCurrentBytecodes(). | 383 // Tests covering BytecodePeepholeOptimizer::UpdateLastAndCurrentBytecodes(). |
| 384 | 384 |
| 385 TEST_F(BytecodePeepholeOptimizerTest, MergeLoadICStar) { | 385 TEST_F(BytecodePeepholeOptimizerTest, MergeLoadICStar) { |
| 386 const uint32_t operands[] = { | 386 const uint32_t operands[] = { |
| 387 static_cast<uint32_t>(Register(31).ToOperand()), 32, 33, | 387 static_cast<uint32_t>(Register(31).ToOperand()), 32, 33, |
| 388 static_cast<uint32_t>(Register(256).ToOperand())}; | 388 static_cast<uint32_t>(Register(256).ToOperand())}; |
| 389 const int expected_operand_count = static_cast<int>(arraysize(operands)); | 389 const int expected_operand_count = static_cast<int>(arraysize(operands)); |
| 390 | 390 |
| 391 BytecodeNode first(Bytecode::kLoadIC, operands[0], operands[1], operands[2], | 391 BytecodeNode first(Bytecode::kLdaNamedProperty, operands[0], operands[1], |
| 392 OperandScale::kSingle); | 392 operands[2], OperandScale::kSingle); |
| 393 BytecodeNode second(Bytecode::kStar, operands[3], OperandScale::kDouble); | 393 BytecodeNode second(Bytecode::kStar, operands[3], OperandScale::kDouble); |
| 394 BytecodeNode third(Bytecode::kReturn); | 394 BytecodeNode third(Bytecode::kReturn); |
| 395 optimizer()->Write(&first); | 395 optimizer()->Write(&first); |
| 396 optimizer()->Write(&second); | 396 optimizer()->Write(&second); |
| 397 CHECK_EQ(write_count(), 1); | 397 CHECK_EQ(write_count(), 1); |
| 398 CHECK_EQ(last_written().bytecode(), Bytecode::kLdrNamedProperty); | 398 CHECK_EQ(last_written().bytecode(), Bytecode::kLdrNamedProperty); |
| 399 CHECK_EQ(last_written().operand_count(), expected_operand_count); | 399 CHECK_EQ(last_written().operand_count(), expected_operand_count); |
| 400 for (int i = 0; i < expected_operand_count; ++i) { | 400 for (int i = 0; i < expected_operand_count; ++i) { |
| 401 CHECK_EQ(last_written().operand(i), operands[i]); | 401 CHECK_EQ(last_written().operand(i), operands[i]); |
| 402 } | 402 } |
| 403 CHECK_EQ(last_written().operand_scale(), | 403 CHECK_EQ(last_written().operand_scale(), |
| 404 std::max(first.operand_scale(), second.operand_scale())); | 404 std::max(first.operand_scale(), second.operand_scale())); |
| 405 optimizer()->Write(&third); | 405 optimizer()->Write(&third); |
| 406 CHECK_EQ(write_count(), 2); | 406 CHECK_EQ(write_count(), 2); |
| 407 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar); | 407 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar); |
| 408 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]); | 408 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]); |
| 409 optimizer()->FlushBasicBlock(); | 409 optimizer()->FlushBasicBlock(); |
| 410 CHECK_EQ(last_written().bytecode(), third.bytecode()); | 410 CHECK_EQ(last_written().bytecode(), third.bytecode()); |
| 411 } | 411 } |
| 412 | 412 |
| 413 TEST_F(BytecodePeepholeOptimizerTest, MergeKeyedLoadICStar) { | 413 TEST_F(BytecodePeepholeOptimizerTest, MergeLdaKeyedPropertyStar) { |
| 414 const uint32_t operands[] = {static_cast<uint32_t>(Register(31).ToOperand()), | 414 const uint32_t operands[] = {static_cast<uint32_t>(Register(31).ToOperand()), |
| 415 9999997, | 415 9999997, |
| 416 static_cast<uint32_t>(Register(1).ToOperand())}; | 416 static_cast<uint32_t>(Register(1).ToOperand())}; |
| 417 const int expected_operand_count = static_cast<int>(arraysize(operands)); | 417 const int expected_operand_count = static_cast<int>(arraysize(operands)); |
| 418 | 418 |
| 419 BytecodeNode first(Bytecode::kKeyedLoadIC, operands[0], operands[1], | 419 BytecodeNode first(Bytecode::kLdaKeyedProperty, operands[0], operands[1], |
| 420 OperandScale::kQuadruple); | 420 OperandScale::kQuadruple); |
| 421 BytecodeNode second(Bytecode::kStar, operands[2], OperandScale::kSingle); | 421 BytecodeNode second(Bytecode::kStar, operands[2], OperandScale::kSingle); |
| 422 BytecodeNode third(Bytecode::kReturn); | 422 BytecodeNode third(Bytecode::kReturn); |
| 423 optimizer()->Write(&first); | 423 optimizer()->Write(&first); |
| 424 optimizer()->Write(&second); | 424 optimizer()->Write(&second); |
| 425 CHECK_EQ(write_count(), 1); | 425 CHECK_EQ(write_count(), 1); |
| 426 CHECK_EQ(last_written().bytecode(), Bytecode::kLdrKeyedProperty); | 426 CHECK_EQ(last_written().bytecode(), Bytecode::kLdrKeyedProperty); |
| 427 CHECK_EQ(last_written().operand_count(), expected_operand_count); | 427 CHECK_EQ(last_written().operand_count(), expected_operand_count); |
| 428 for (int i = 0; i < expected_operand_count; ++i) { | 428 for (int i = 0; i < expected_operand_count; ++i) { |
| 429 CHECK_EQ(last_written().operand(i), operands[i]); | 429 CHECK_EQ(last_written().operand(i), operands[i]); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 CHECK_EQ(write_count(), 2); | 515 CHECK_EQ(write_count(), 2); |
| 516 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar); | 516 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar); |
| 517 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]); | 517 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]); |
| 518 optimizer()->FlushBasicBlock(); | 518 optimizer()->FlushBasicBlock(); |
| 519 CHECK_EQ(last_written().bytecode(), third.bytecode()); | 519 CHECK_EQ(last_written().bytecode(), third.bytecode()); |
| 520 } | 520 } |
| 521 | 521 |
| 522 } // namespace interpreter | 522 } // namespace interpreter |
| 523 } // namespace internal | 523 } // namespace internal |
| 524 } // namespace v8 | 524 } // namespace v8 |
| OLD | NEW |