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

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: TEMP 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 const int var_def_index = 1;
534 const int call_index = 3;
535 int expect_no_moves = FLAG_turbo_greedy_regalloc ? var_def_index : call_index;
536 int expect_spill_move =
537 FLAG_turbo_greedy_regalloc ? call_index : var_def_index;
538
539 const ParallelMove* moves =
540 sequence()
541 ->InstructionAt(expect_no_moves)
542 ->GetOrCreateParallelMove(Instruction::START, zone());
543
544 // We should have no parallel moves at the "expect_no_moves" position.
545 EXPECT_EQ(0, GetMoveCount(*moves));
546
547 moves = sequence()
548 ->InstructionAt(expect_spill_move)
549 ->GetOrCreateParallelMove(Instruction::START, zone());
550 EXPECT_EQ(1, GetMoveCount(*moves));
551 for (auto move : *moves) {
552 if (move->IsEliminated() || move->IsRedundant()) continue;
553 EXPECT_TRUE(move->source().IsRegister());
554 EXPECT_TRUE(move->destination().IsStackSlot());
555 }
556 }
557
558
495 namespace { 559 namespace {
496 560
497 enum class ParameterType { kFixedSlot, kSlot, kRegister, kFixedRegister }; 561 enum class ParameterType { kFixedSlot, kSlot, kRegister, kFixedRegister };
498 562
499 const ParameterType kParameterTypes[] = { 563 const ParameterType kParameterTypes[] = {
500 ParameterType::kFixedSlot, ParameterType::kSlot, ParameterType::kRegister, 564 ParameterType::kFixedSlot, ParameterType::kSlot, ParameterType::kRegister,
501 ParameterType::kFixedRegister}; 565 ParameterType::kFixedRegister};
502 566
503 class SlotConstraintTest : public RegisterAllocatorTest, 567 class SlotConstraintTest : public RegisterAllocatorTest,
504 public ::testing::WithParamInterface< 568 public ::testing::WithParamInterface<
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 INSTANTIATE_TEST_CASE_P( 632 INSTANTIATE_TEST_CASE_P(
569 RegisterAllocatorTest, SlotConstraintTest, 633 RegisterAllocatorTest, SlotConstraintTest,
570 ::testing::Combine(::testing::ValuesIn(kParameterTypes), 634 ::testing::Combine(::testing::ValuesIn(kParameterTypes),
571 ::testing::Range(0, SlotConstraintTest::kMaxVariant))); 635 ::testing::Range(0, SlotConstraintTest::kMaxVariant)));
572 636
573 #endif // GTEST_HAS_COMBINE 637 #endif // GTEST_HAS_COMBINE
574 638
575 } // namespace compiler 639 } // namespace compiler
576 } // namespace internal 640 } // namespace internal
577 } // namespace v8 641 } // namespace v8
OLDNEW
« src/compiler/greedy-allocator.cc ('K') | « test/unittests/compiler/instruction-sequence-unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698