| OLD | NEW |
| 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/move-optimizer.h" | 5 #include "src/compiler/move-optimizer.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 class MoveOptimizerTest : public InstructionSequenceTest { | 12 class MoveOptimizerTest : public InstructionSequenceTest { |
| 13 public: | 13 public: |
| 14 GapInstruction* LastGap() { | 14 GapInstruction* LastGap() { |
| 15 auto instruction = sequence()->instructions().back(); | 15 return GapInstruction::cast(*(sequence()->instructions().rbegin() + 1)); |
| 16 if (!instruction->IsGapMoves()) { | |
| 17 instruction = *(sequence()->instructions().rbegin() + 1); | |
| 18 } | |
| 19 return GapInstruction::cast(instruction); | |
| 20 } | 16 } |
| 21 | 17 |
| 22 void AddMove(GapInstruction* gap, TestOperand from, TestOperand to, | 18 void AddMove(GapInstruction* gap, TestOperand from, TestOperand to, |
| 23 GapInstruction::InnerPosition pos = GapInstruction::START) { | 19 GapInstruction::InnerPosition pos = GapInstruction::START) { |
| 24 auto parallel_move = gap->GetOrCreateParallelMove(pos, zone()); | 20 auto parallel_move = gap->GetOrCreateParallelMove(pos, zone()); |
| 25 parallel_move->AddMove(ConvertMoveArg(from), ConvertMoveArg(to), zone()); | 21 parallel_move->AddMove(ConvertMoveArg(from), ConvertMoveArg(to), zone()); |
| 26 } | 22 } |
| 27 | 23 |
| 28 int NonRedundantSize(ParallelMove* move) { | 24 int NonRedundantSize(ParallelMove* move) { |
| 29 int i = 0; | 25 int i = 0; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 break; | 79 break; |
| 84 } | 80 } |
| 85 CHECK(false); | 81 CHECK(false); |
| 86 return nullptr; | 82 return nullptr; |
| 87 } | 83 } |
| 88 }; | 84 }; |
| 89 | 85 |
| 90 | 86 |
| 91 TEST_F(MoveOptimizerTest, RemovesRedundant) { | 87 TEST_F(MoveOptimizerTest, RemovesRedundant) { |
| 92 StartBlock(); | 88 StartBlock(); |
| 89 EmitNop(); |
| 93 AddMove(LastGap(), Reg(0), Reg(1)); | 90 AddMove(LastGap(), Reg(0), Reg(1)); |
| 94 EmitNop(); | 91 EmitNop(); |
| 95 AddMove(LastGap(), Reg(1), Reg(0)); | 92 AddMove(LastGap(), Reg(1), Reg(0)); |
| 96 EmitNop(); | |
| 97 EndBlock(Last()); | 93 EndBlock(Last()); |
| 98 | 94 |
| 99 Optimize(); | 95 Optimize(); |
| 100 | 96 |
| 101 auto gap = LastGap(); | 97 auto gap = LastGap(); |
| 102 auto move = gap->parallel_moves()[0]; | 98 auto move = gap->parallel_moves()[0]; |
| 103 CHECK_EQ(1, NonRedundantSize(move)); | 99 CHECK_EQ(1, NonRedundantSize(move)); |
| 104 CHECK(Contains(move, Reg(0), Reg(1))); | 100 CHECK(Contains(move, Reg(0), Reg(1))); |
| 105 } | 101 } |
| 106 | 102 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 124 move = gap->parallel_moves()[1]; | 120 move = gap->parallel_moves()[1]; |
| 125 CHECK_EQ(3, NonRedundantSize(move)); | 121 CHECK_EQ(3, NonRedundantSize(move)); |
| 126 CHECK(Contains(move, Reg(0), Slot(0))); | 122 CHECK(Contains(move, Reg(0), Slot(0))); |
| 127 CHECK(Contains(move, Reg(0), Slot(1))); | 123 CHECK(Contains(move, Reg(0), Slot(1))); |
| 128 CHECK(Contains(move, Reg(0), Slot(2))); | 124 CHECK(Contains(move, Reg(0), Slot(2))); |
| 129 } | 125 } |
| 130 | 126 |
| 131 } // namespace compiler | 127 } // namespace compiler |
| 132 } // namespace internal | 128 } // namespace internal |
| 133 } // namespace v8 | 129 } // namespace v8 |
| OLD | NEW |