Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: test/unittests/interpreter/bytecode-peephole-optimizer-unittest.cc

Issue 2489513005: [Interpreter] Remove all Ldr style bytecodes and replace with Star lookahead. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/unittests/interpreter/bytecode-array-builder-unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-label.h" 8 #include "src/interpreter/bytecode-label.h"
9 #include "src/interpreter/bytecode-peephole-optimizer.h" 9 #include "src/interpreter/bytecode-peephole-optimizer.h"
10 #include "src/objects-inl.h" 10 #include "src/objects-inl.h"
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 optimizer()->Write(&second); 314 optimizer()->Write(&second);
315 CHECK_EQ(write_count(), 0); 315 CHECK_EQ(write_count(), 0);
316 Flush(); 316 Flush();
317 CHECK_EQ(write_count(), 1); 317 CHECK_EQ(write_count(), 1);
318 BytecodeNode expected(Bytecode::kStackCheck, source_info); 318 BytecodeNode expected(Bytecode::kStackCheck, source_info);
319 CHECK_EQ(last_written(), expected); 319 CHECK_EQ(last_written(), expected);
320 } 320 }
321 321
322 // Tests covering BytecodePeepholeOptimizer::UpdateLastAndCurrentBytecodes(). 322 // Tests covering BytecodePeepholeOptimizer::UpdateLastAndCurrentBytecodes().
323 323
324 TEST_F(BytecodePeepholeOptimizerTest, MergeLdaGlobalStar) {
325 const uint32_t operands[] = {19191,
326 static_cast<uint32_t>(Register(1).ToOperand())};
327 const int expected_operand_count = static_cast<int>(arraysize(operands));
328
329 BytecodeNode first(Bytecode::kLdaGlobal, operands[0]);
330 BytecodeNode second(Bytecode::kStar, operands[1]);
331 BytecodeNode third(Bytecode::kReturn);
332 optimizer()->Write(&first);
333 optimizer()->Write(&second);
334 CHECK_EQ(write_count(), 1);
335 CHECK_EQ(last_written().bytecode(), Bytecode::kLdrGlobal);
336 CHECK_EQ(last_written().operand_count(), expected_operand_count);
337 for (int i = 0; i < expected_operand_count; ++i) {
338 CHECK_EQ(last_written().operand(i), operands[i]);
339 }
340 optimizer()->Write(&third);
341 CHECK_EQ(write_count(), 2);
342 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar);
343 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]);
344 Flush();
345 CHECK_EQ(last_written().bytecode(), third.bytecode());
346 }
347
348 TEST_F(BytecodePeepholeOptimizerTest, MergeLdaContextSlotStar) {
349 const uint32_t operands[] = {
350 static_cast<uint32_t>(Register(200000).ToOperand()), 55005500,
351 static_cast<uint32_t>(Register(0).ToOperand()),
352 static_cast<uint32_t>(Register(1).ToOperand())};
353 const int expected_operand_count = static_cast<int>(arraysize(operands));
354
355 BytecodeNode first(Bytecode::kLdaContextSlot, operands[0], operands[1],
356 operands[2]);
357 BytecodeNode second(Bytecode::kStar, operands[3]);
358 BytecodeNode third(Bytecode::kReturn);
359 optimizer()->Write(&first);
360 optimizer()->Write(&second);
361 CHECK_EQ(write_count(), 1);
362 CHECK_EQ(last_written().bytecode(), Bytecode::kLdrContextSlot);
363 CHECK_EQ(last_written().operand_count(), expected_operand_count);
364 for (int i = 0; i < expected_operand_count; ++i) {
365 CHECK_EQ(last_written().operand(i), operands[i]);
366 }
367 optimizer()->Write(&third);
368 CHECK_EQ(write_count(), 2);
369 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar);
370 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]);
371 Flush();
372 CHECK_EQ(last_written().bytecode(), third.bytecode());
373 }
374
375 TEST_F(BytecodePeepholeOptimizerTest, MergeLdaUndefinedStar) {
376 const uint32_t operands[] = {
377 static_cast<uint32_t>(Register(100000).ToOperand())};
378 const int expected_operand_count = static_cast<int>(arraysize(operands));
379
380 BytecodeNode first(Bytecode::kLdaUndefined);
381 BytecodeNode second(Bytecode::kStar, operands[0]);
382 BytecodeNode third(Bytecode::kReturn);
383 optimizer()->Write(&first);
384 optimizer()->Write(&second);
385 CHECK_EQ(write_count(), 1);
386 CHECK_EQ(last_written().bytecode(), Bytecode::kLdrUndefined);
387 CHECK_EQ(last_written().operand_count(), expected_operand_count);
388 for (int i = 0; i < expected_operand_count; ++i) {
389 CHECK_EQ(last_written().operand(i), operands[i]);
390 }
391 optimizer()->Write(&third);
392 CHECK_EQ(write_count(), 2);
393 CHECK_EQ(last_written().bytecode(), Bytecode::kLdar);
394 CHECK_EQ(last_written().operand(0), operands[expected_operand_count - 1]);
395 Flush();
396 CHECK_EQ(last_written().bytecode(), third.bytecode());
397 }
398
399 TEST_F(BytecodePeepholeOptimizerTest, MergeLdaSmiWithBinaryOp) { 324 TEST_F(BytecodePeepholeOptimizerTest, MergeLdaSmiWithBinaryOp) {
400 Bytecode operator_replacement_pairs[][2] = { 325 Bytecode operator_replacement_pairs[][2] = {
401 {Bytecode::kAdd, Bytecode::kAddSmi}, 326 {Bytecode::kAdd, Bytecode::kAddSmi},
402 {Bytecode::kSub, Bytecode::kSubSmi}, 327 {Bytecode::kSub, Bytecode::kSubSmi},
403 {Bytecode::kBitwiseAnd, Bytecode::kBitwiseAndSmi}, 328 {Bytecode::kBitwiseAnd, Bytecode::kBitwiseAndSmi},
404 {Bytecode::kBitwiseOr, Bytecode::kBitwiseOrSmi}, 329 {Bytecode::kBitwiseOr, Bytecode::kBitwiseOrSmi},
405 {Bytecode::kShiftLeft, Bytecode::kShiftLeftSmi}, 330 {Bytecode::kShiftLeft, Bytecode::kShiftLeftSmi},
406 {Bytecode::kShiftRight, Bytecode::kShiftRightSmi}}; 331 {Bytecode::kShiftRight, Bytecode::kShiftRightSmi}};
407 332
408 for (auto operator_replacement : operator_replacement_pairs) { 333 for (auto operator_replacement : operator_replacement_pairs) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 CHECK_EQ(last_written().operand(0), 0); 399 CHECK_EQ(last_written().operand(0), 0);
475 CHECK_EQ(last_written().operand(1), reg_operand); 400 CHECK_EQ(last_written().operand(1), reg_operand);
476 CHECK_EQ(last_written().operand(2), idx_operand); 401 CHECK_EQ(last_written().operand(2), idx_operand);
477 Reset(); 402 Reset();
478 } 403 }
479 } 404 }
480 405
481 } // namespace interpreter 406 } // namespace interpreter
482 } // namespace internal 407 } // namespace internal
483 } // namespace v8 408 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/interpreter/bytecode-array-builder-unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698