| 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 "src/compiler/pipeline.h" | 6 #include "src/compiler/pipeline.h" |
| 7 #include "test/unittests/compiler/instruction-sequence-unittest.h" | 7 #include "test/unittests/compiler/instruction-sequence-unittest.h" |
| 8 | 8 |
| 9 namespace v8 { | 9 namespace v8 { |
| 10 namespace internal { | 10 namespace internal { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 move_optimizer.Run(); | 54 move_optimizer.Run(); |
| 55 if (FLAG_trace_turbo) { | 55 if (FLAG_trace_turbo) { |
| 56 OFStream os(stdout); | 56 OFStream os(stdout); |
| 57 PrintableInstructionSequence printable = {config(), sequence()}; | 57 PrintableInstructionSequence printable = {config(), sequence()}; |
| 58 os << "----- Instruction sequence after move optimization -----\n" | 58 os << "----- Instruction sequence after move optimization -----\n" |
| 59 << printable; | 59 << printable; |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 bool DoesRegisterAllocation() override { return false; } |
| 65 |
| 64 InstructionOperand ConvertMoveArg(TestOperand op) { | 66 InstructionOperand ConvertMoveArg(TestOperand op) { |
| 65 CHECK_EQ(kNoValue, op.vreg_.value_); | 67 CHECK_EQ(kNoValue, op.vreg_.value_); |
| 66 CHECK_NE(kNoValue, op.value_); | 68 CHECK_NE(kNoValue, op.value_); |
| 67 switch (op.type_) { | 69 switch (op.type_) { |
| 68 case kConstant: | 70 case kConstant: |
| 69 return ConstantOperand(op.value_); | 71 return ConstantOperand(op.value_); |
| 70 case kFixedSlot: | 72 case kFixedSlot: |
| 71 return AllocatedOperand(LocationOperand::STACK_SLOT, | 73 return AllocatedOperand(LocationOperand::STACK_SLOT, |
| 72 MachineRepresentation::kWord32, op.value_); | 74 MachineRepresentation::kWord32, op.value_); |
| 73 case kFixedRegister: | 75 case kFixedRegister: { |
| 74 CHECK(0 <= op.value_ && op.value_ < num_general_registers()); | 76 MachineRepresentation rep = GetCanonicalRep(op); |
| 75 return AllocatedOperand(LocationOperand::REGISTER, | 77 CHECK(0 <= op.value_ && op.value_ < GetNumRegs(rep)); |
| 76 MachineRepresentation::kWord32, op.value_); | 78 return AllocatedOperand(LocationOperand::REGISTER, rep, op.value_); |
| 77 case kExplicit: | 79 } |
| 78 CHECK(0 <= op.value_ && op.value_ < num_general_registers()); | 80 case kExplicit: { |
| 79 return ExplicitOperand(LocationOperand::REGISTER, | 81 MachineRepresentation rep = GetCanonicalRep(op); |
| 80 MachineRepresentation::kWord32, op.value_); | 82 CHECK(0 <= op.value_ && op.value_ < GetNumRegs(rep)); |
| 83 return ExplicitOperand(LocationOperand::REGISTER, rep, op.value_); |
| 84 } |
| 81 default: | 85 default: |
| 82 break; | 86 break; |
| 83 } | 87 } |
| 84 CHECK(false); | 88 CHECK(false); |
| 85 return InstructionOperand(); | 89 return InstructionOperand(); |
| 86 } | 90 } |
| 87 }; | 91 }; |
| 88 | 92 |
| 89 | 93 |
| 90 TEST_F(MoveOptimizerTest, RemovesRedundant) { | 94 TEST_F(MoveOptimizerTest, RemovesRedundant) { |
| 91 StartBlock(); | 95 StartBlock(); |
| 92 auto first_instr = EmitNop(); | 96 auto first_instr = EmitNop(); |
| 93 AddMove(first_instr, Reg(0), Reg(1)); | 97 AddMove(first_instr, Reg(0), Reg(1)); |
| 94 auto last_instr = EmitNop(); | 98 auto last_instr = EmitNop(); |
| 95 AddMove(last_instr, Reg(1), Reg(0)); | 99 AddMove(last_instr, Reg(1), Reg(0)); |
| 100 |
| 101 AddMove(first_instr, FPReg(kFloat64, 0), FPReg(kFloat64, 1)); |
| 102 AddMove(last_instr, FPReg(kFloat64, 1), FPReg(kFloat64, 0)); |
| 103 |
| 96 EndBlock(Last()); | 104 EndBlock(Last()); |
| 97 | 105 |
| 98 Optimize(); | 106 Optimize(); |
| 99 | 107 |
| 100 CHECK_EQ(0, NonRedundantSize(first_instr->parallel_moves()[0])); | 108 CHECK_EQ(0, NonRedundantSize(first_instr->parallel_moves()[0])); |
| 101 auto move = last_instr->parallel_moves()[0]; | 109 auto move = last_instr->parallel_moves()[0]; |
| 102 CHECK_EQ(1, NonRedundantSize(move)); | 110 CHECK_EQ(2, NonRedundantSize(move)); |
| 103 CHECK(Contains(move, Reg(0), Reg(1))); | 111 CHECK(Contains(move, Reg(0), Reg(1))); |
| 112 CHECK(Contains(move, FPReg(kFloat64, 0), FPReg(kFloat64, 1))); |
| 104 } | 113 } |
| 105 | 114 |
| 106 | 115 |
| 107 TEST_F(MoveOptimizerTest, RemovesRedundantExplicit) { | 116 TEST_F(MoveOptimizerTest, RemovesRedundantExplicit) { |
| 108 int first_reg_index = | 117 int first_reg_index = |
| 109 RegisterConfiguration::Turbofan()->GetAllocatableGeneralCode(0); | 118 RegisterConfiguration::Turbofan()->GetAllocatableGeneralCode(0); |
| 110 int second_reg_index = | 119 int second_reg_index = |
| 111 RegisterConfiguration::Turbofan()->GetAllocatableGeneralCode(1); | 120 RegisterConfiguration::Turbofan()->GetAllocatableGeneralCode(1); |
| 112 | 121 |
| 113 StartBlock(); | 122 StartBlock(); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 ParallelMove* b2_move = last_move_b2->parallel_moves()[0]; | 327 ParallelMove* b2_move = last_move_b2->parallel_moves()[0]; |
| 319 CHECK_EQ(1, NonRedundantSize(b2_move)); | 328 CHECK_EQ(1, NonRedundantSize(b2_move)); |
| 320 CHECK(Contains(b1_move, Reg(0), Reg(1))); | 329 CHECK(Contains(b1_move, Reg(0), Reg(1))); |
| 321 } | 330 } |
| 322 | 331 |
| 323 TEST_F(MoveOptimizerTest, ClobberedDestinationsAreEliminated) { | 332 TEST_F(MoveOptimizerTest, ClobberedDestinationsAreEliminated) { |
| 324 StartBlock(); | 333 StartBlock(); |
| 325 EmitNop(); | 334 EmitNop(); |
| 326 Instruction* first_instr = LastInstruction(); | 335 Instruction* first_instr = LastInstruction(); |
| 327 AddMove(first_instr, Reg(0), Reg(1)); | 336 AddMove(first_instr, Reg(0), Reg(1)); |
| 328 EmitOI(Reg(1), 0, nullptr); | 337 AddMove(first_instr, FPReg(kFloat64, 0), FPReg(kFloat64, 1)); |
| 338 EmitOOI(Reg(1), FPReg(kFloat64, 1), 0, nullptr); |
| 329 Instruction* last_instr = LastInstruction(); | 339 Instruction* last_instr = LastInstruction(); |
| 330 EndBlock(); | 340 EndBlock(); |
| 331 Optimize(); | 341 Optimize(); |
| 332 | 342 |
| 333 ParallelMove* first_move = first_instr->parallel_moves()[0]; | 343 ParallelMove* first_move = first_instr->parallel_moves()[0]; |
| 334 CHECK_EQ(0, NonRedundantSize(first_move)); | 344 CHECK_EQ(0, NonRedundantSize(first_move)); |
| 335 | 345 |
| 336 ParallelMove* last_move = last_instr->parallel_moves()[0]; | 346 ParallelMove* last_move = last_instr->parallel_moves()[0]; |
| 337 CHECK_EQ(0, NonRedundantSize(last_move)); | 347 CHECK_EQ(0, NonRedundantSize(last_move)); |
| 338 } | 348 } |
| 339 | 349 |
| 340 } // namespace compiler | 350 } // namespace compiler |
| 341 } // namespace internal | 351 } // namespace internal |
| 342 } // namespace v8 | 352 } // namespace v8 |
| OLD | NEW |