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

Side by Side Diff: test/unittests/compiler/register-allocator-unittest.cc

Issue 1242123006: [turbofan] Deferred block spilling heuristic - first step. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 months 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
OLDNEW
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 "src/compiler/pipeline.h" 5 #include "src/compiler/pipeline.h"
6 #include "test/unittests/compiler/instruction-sequence-unittest.h" 6 #include "test/unittests/compiler/instruction-sequence-unittest.h"
7 7
8 namespace v8 { 8 namespace v8 {
9 namespace internal { 9 namespace internal {
10 namespace compiler { 10 namespace compiler {
11 11
12
13 namespace {
14
15 // We can't just use the size of the moves collection, because of
16 // redundant moves which need to be discounted.
17 int GetMoveCount(const ParallelMove& moves) {
18 int move_count = 0;
19 for (auto move : moves) {
20 if (move->IsEliminated() || move->IsRedundant()) continue;
21 ++move_count;
22 }
23 return move_count;
24 }
25 }
26
27
12 class RegisterAllocatorTest : public InstructionSequenceTest { 28 class RegisterAllocatorTest : public InstructionSequenceTest {
13 public: 29 public:
14 void Allocate() { 30 void Allocate() {
15 WireBlocks(); 31 WireBlocks();
16 Pipeline::AllocateRegistersForTesting(config(), sequence(), true); 32 Pipeline::AllocateRegistersForTesting(config(), sequence(), true);
17 } 33 }
18 }; 34 };
19 35
20 36
21 TEST_F(RegisterAllocatorTest, CanAllocateThreeRegisters) { 37 TEST_F(RegisterAllocatorTest, CanAllocateThreeRegisters) {
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 StartBlock(); 501 StartBlock();
486 // Force c to split within to_spill's definition. 502 // Force c to split within to_spill's definition.
487 EmitI(Reg(c)); 503 EmitI(Reg(c));
488 EmitI(Reg(to_spill)); 504 EmitI(Reg(to_spill));
489 EndBlock(Last()); 505 EndBlock(Last());
490 506
491 Allocate(); 507 Allocate();
492 } 508 }
493 509
494 510
511 TEST_F(RegisterAllocatorTest, DeferredBlockSpill) {
512 StartBlock(); // B0
513 auto var = EmitOI(Reg(0));
514 EndBlock(Branch(Reg(var), 1, 2));
515
516 StartBlock(); // B1
517 EndBlock(Jump(3));
518
519 StartBlock(true); // B2
520 EmitCall(Slot(-1), Slot(var));
521 EndBlock();
522
523 StartBlock(); // B3
524 EmitNop();
525 EndBlock();
526
527 StartBlock(); // B4
528 Return(Reg(var, 0));
529 EndBlock();
530
531 Allocate();
532
533 int expect_0 = FLAG_turbo_greedy_regalloc ? 1 : 3;
534 int expect_1 = FLAG_turbo_greedy_regalloc ? 3 : 1;
Jarin 2015/07/22 12:59:36 Could you please explain what the magic constants
Mircea Trofin 2015/07/23 02:20:04 Done.
535
536 const ParallelMove* moves =
537 sequence()->InstructionAt(expect_0)->GetOrCreateParallelMove(
538 Instruction::START, zone());
539
540 EXPECT_EQ(0, GetMoveCount(*moves));
Jarin 2015/07/22 12:59:36 Please explain what you are checking here, this wi
Mircea Trofin 2015/07/23 02:20:04 Done, but please let me know if, still, the commen
541
542 moves = sequence()->InstructionAt(expect_1)->GetOrCreateParallelMove(
543 Instruction::START, zone());
544 EXPECT_EQ(1, GetMoveCount(*moves));
545 for (auto move : *moves) {
546 if (move->IsEliminated() || move->IsRedundant()) continue;
547 EXPECT_TRUE(move->source().IsRegister());
548 EXPECT_TRUE(move->destination().IsStackSlot());
549 }
550 }
551
552
495 namespace { 553 namespace {
496 554
497 enum class ParameterType { kFixedSlot, kSlot, kRegister, kFixedRegister }; 555 enum class ParameterType { kFixedSlot, kSlot, kRegister, kFixedRegister };
498 556
499 const ParameterType kParameterTypes[] = { 557 const ParameterType kParameterTypes[] = {
500 ParameterType::kFixedSlot, ParameterType::kSlot, ParameterType::kRegister, 558 ParameterType::kFixedSlot, ParameterType::kSlot, ParameterType::kRegister,
501 ParameterType::kFixedRegister}; 559 ParameterType::kFixedRegister};
502 560
503 class SlotConstraintTest : public RegisterAllocatorTest, 561 class SlotConstraintTest : public RegisterAllocatorTest,
504 public ::testing::WithParamInterface< 562 public ::testing::WithParamInterface<
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 INSTANTIATE_TEST_CASE_P( 626 INSTANTIATE_TEST_CASE_P(
569 RegisterAllocatorTest, SlotConstraintTest, 627 RegisterAllocatorTest, SlotConstraintTest,
570 ::testing::Combine(::testing::ValuesIn(kParameterTypes), 628 ::testing::Combine(::testing::ValuesIn(kParameterTypes),
571 ::testing::Range(0, SlotConstraintTest::kMaxVariant))); 629 ::testing::Range(0, SlotConstraintTest::kMaxVariant)));
572 630
573 #endif // GTEST_HAS_COMBINE 631 #endif // GTEST_HAS_COMBINE
574 632
575 } // namespace compiler 633 } // namespace compiler
576 } // namespace internal 634 } // namespace internal
577 } // namespace v8 635 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698