| 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 #ifndef V8_UNITTESTS_COMPILER_INSTRUCTION_SEQUENCE_UNITTEST_H_ | 5 #ifndef V8_UNITTESTS_COMPILER_INSTRUCTION_SEQUENCE_UNITTEST_H_ |
| 6 #define V8_UNITTESTS_COMPILER_INSTRUCTION_SEQUENCE_UNITTEST_H_ | 6 #define V8_UNITTESTS_COMPILER_INSTRUCTION_SEQUENCE_UNITTEST_H_ |
| 7 | 7 |
| 8 #include "src/compiler/instruction.h" | 8 #include "src/compiler/instruction.h" |
| 9 #include "test/unittests/test-utils.h" | 9 #include "test/unittests/test-utils.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 | 11 |
| 12 namespace v8 { | 12 namespace v8 { |
| 13 namespace internal { | 13 namespace internal { |
| 14 namespace compiler { | 14 namespace compiler { |
| 15 | 15 |
| 16 class InstructionSequenceTest : public TestWithIsolateAndZone { | 16 class InstructionSequenceTest : public TestWithIsolateAndZone { |
| 17 public: | 17 public: |
| 18 static const int kDefaultNRegs = 4; | 18 static const int kDefaultNRegs = 4; |
| 19 static const int kNoValue = kMinInt; | 19 static const int kNoValue = kMinInt; |
| 20 | 20 |
| 21 typedef BasicBlock::RpoNumber Rpo; | 21 typedef BasicBlock::RpoNumber Rpo; |
| 22 | 22 |
| 23 struct VReg { | 23 struct VReg { |
| 24 VReg() : value_(kNoValue) {} | 24 VReg() : value_(kNoValue) {} |
| 25 VReg(PhiInstruction* phi) : value_(phi->virtual_register()) {} // NOLINT | 25 VReg(PhiInstruction* phi) : value_(phi->virtual_register()) {} // NOLINT |
| 26 explicit VReg(int value) : value_(value) {} | 26 explicit VReg(int value) : value_(value) {} |
| 27 int value_; | 27 int value_; |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 typedef std::pair<VReg, VReg> VRegPair; |
| 31 |
| 30 enum TestOperandType { | 32 enum TestOperandType { |
| 31 kInvalid, | 33 kInvalid, |
| 32 kSameAsFirst, | 34 kSameAsFirst, |
| 33 kRegister, | 35 kRegister, |
| 34 kFixedRegister, | 36 kFixedRegister, |
| 35 kSlot, | 37 kSlot, |
| 36 kFixedSlot, | 38 kFixedSlot, |
| 37 kImmediate, | 39 kImmediate, |
| 38 kNone, | 40 kNone, |
| 39 kConstant, | 41 kConstant, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 120 |
| 119 InstructionSequenceTest(); | 121 InstructionSequenceTest(); |
| 120 | 122 |
| 121 void SetNumRegs(int num_general_registers, int num_double_registers); | 123 void SetNumRegs(int num_general_registers, int num_double_registers); |
| 122 RegisterConfiguration* config(); | 124 RegisterConfiguration* config(); |
| 123 InstructionSequence* sequence(); | 125 InstructionSequence* sequence(); |
| 124 | 126 |
| 125 void StartLoop(int loop_blocks); | 127 void StartLoop(int loop_blocks); |
| 126 void EndLoop(); | 128 void EndLoop(); |
| 127 void StartBlock(); | 129 void StartBlock(); |
| 128 int EndBlock(BlockCompletion completion = FallThrough()); | 130 Instruction* EndBlock(BlockCompletion completion = FallThrough()); |
| 129 | 131 |
| 130 TestOperand Imm(int32_t imm = 0); | 132 TestOperand Imm(int32_t imm = 0); |
| 131 VReg Define(TestOperand output_op); | 133 VReg Define(TestOperand output_op); |
| 132 VReg Parameter(TestOperand output_op = Reg()) { return Define(output_op); } | 134 VReg Parameter(TestOperand output_op = Reg()) { return Define(output_op); } |
| 133 | 135 |
| 134 int Return(TestOperand input_op_0); | 136 Instruction* Return(TestOperand input_op_0); |
| 135 int Return(VReg vreg) { return Return(Reg(vreg, 0)); } | 137 Instruction* Return(VReg vreg) { return Return(Reg(vreg, 0)); } |
| 136 | 138 |
| 137 PhiInstruction* Phi(VReg incoming_vreg_0 = VReg(), | 139 PhiInstruction* Phi(VReg incoming_vreg_0 = VReg(), |
| 138 VReg incoming_vreg_1 = VReg(), | 140 VReg incoming_vreg_1 = VReg(), |
| 139 VReg incoming_vreg_2 = VReg(), | 141 VReg incoming_vreg_2 = VReg(), |
| 140 VReg incoming_vreg_3 = VReg()); | 142 VReg incoming_vreg_3 = VReg()); |
| 141 PhiInstruction* Phi(VReg incoming_vreg_0, size_t input_count); | 143 PhiInstruction* Phi(VReg incoming_vreg_0, size_t input_count); |
| 142 void SetInput(PhiInstruction* phi, size_t input, VReg vreg); | 144 void SetInput(PhiInstruction* phi, size_t input, VReg vreg); |
| 143 | 145 |
| 144 VReg DefineConstant(int32_t imm = 0); | 146 VReg DefineConstant(int32_t imm = 0); |
| 145 int EmitNop(); | 147 Instruction* EmitNop(); |
| 146 int EmitI(size_t input_size, TestOperand* inputs); | 148 Instruction* EmitI(size_t input_size, TestOperand* inputs); |
| 147 int EmitI(TestOperand input_op_0 = TestOperand(), | 149 Instruction* EmitI(TestOperand input_op_0 = TestOperand(), |
| 148 TestOperand input_op_1 = TestOperand(), | 150 TestOperand input_op_1 = TestOperand(), |
| 149 TestOperand input_op_2 = TestOperand(), | 151 TestOperand input_op_2 = TestOperand(), |
| 150 TestOperand input_op_3 = TestOperand()); | 152 TestOperand input_op_3 = TestOperand()); |
| 151 VReg EmitOI(TestOperand output_op, size_t input_size, TestOperand* inputs); | 153 VReg EmitOI(TestOperand output_op, size_t input_size, TestOperand* inputs); |
| 152 VReg EmitOI(TestOperand output_op, TestOperand input_op_0 = TestOperand(), | 154 VReg EmitOI(TestOperand output_op, TestOperand input_op_0 = TestOperand(), |
| 153 TestOperand input_op_1 = TestOperand(), | 155 TestOperand input_op_1 = TestOperand(), |
| 154 TestOperand input_op_2 = TestOperand(), | 156 TestOperand input_op_2 = TestOperand(), |
| 155 TestOperand input_op_3 = TestOperand()); | 157 TestOperand input_op_3 = TestOperand()); |
| 158 VRegPair EmitOOI(TestOperand output_op_0, TestOperand output_op_1, |
| 159 size_t input_size, TestOperand* inputs); |
| 160 VRegPair EmitOOI(TestOperand output_op_0, TestOperand output_op_1, |
| 161 TestOperand input_op_0 = TestOperand(), |
| 162 TestOperand input_op_1 = TestOperand(), |
| 163 TestOperand input_op_2 = TestOperand(), |
| 164 TestOperand input_op_3 = TestOperand()); |
| 156 VReg EmitCall(TestOperand output_op, size_t input_size, TestOperand* inputs); | 165 VReg EmitCall(TestOperand output_op, size_t input_size, TestOperand* inputs); |
| 157 VReg EmitCall(TestOperand output_op, TestOperand input_op_0 = TestOperand(), | 166 VReg EmitCall(TestOperand output_op, TestOperand input_op_0 = TestOperand(), |
| 158 TestOperand input_op_1 = TestOperand(), | 167 TestOperand input_op_1 = TestOperand(), |
| 159 TestOperand input_op_2 = TestOperand(), | 168 TestOperand input_op_2 = TestOperand(), |
| 160 TestOperand input_op_3 = TestOperand()); | 169 TestOperand input_op_3 = TestOperand()); |
| 161 | 170 |
| 162 // Get defining instruction vreg or value returned at instruction creation | |
| 163 // time when there is no return value. | |
| 164 const Instruction* GetInstruction(int instruction_index); | |
| 165 | |
| 166 InstructionBlock* current_block() const { return current_block_; } | 171 InstructionBlock* current_block() const { return current_block_; } |
| 167 int num_general_registers() const { return num_general_registers_; } | 172 int num_general_registers() const { return num_general_registers_; } |
| 168 int num_double_registers() const { return num_double_registers_; } | 173 int num_double_registers() const { return num_double_registers_; } |
| 169 | 174 |
| 170 // Called after all instructions have been inserted. | 175 // Called after all instructions have been inserted. |
| 171 void WireBlocks(); | 176 void WireBlocks(); |
| 172 | 177 |
| 173 private: | 178 private: |
| 174 VReg NewReg() { return VReg(sequence()->NextVirtualRegister()); } | 179 VReg NewReg() { return VReg(sequence()->NextVirtualRegister()); } |
| 175 int NewIndex() { return current_instruction_index_--; } | |
| 176 | 180 |
| 177 static TestOperand Invalid() { return TestOperand(kInvalid, VReg()); } | 181 static TestOperand Invalid() { return TestOperand(kInvalid, VReg()); } |
| 178 | 182 |
| 179 int EmitBranch(TestOperand input_op); | 183 Instruction* EmitBranch(TestOperand input_op); |
| 180 int EmitFallThrough(); | 184 Instruction* EmitFallThrough(); |
| 181 int EmitJump(); | 185 Instruction* EmitJump(); |
| 182 Instruction* NewInstruction(InstructionCode code, size_t outputs_size, | 186 Instruction* NewInstruction(InstructionCode code, size_t outputs_size, |
| 183 InstructionOperand* outputs, | 187 InstructionOperand* outputs, |
| 184 size_t inputs_size = 0, | 188 size_t inputs_size = 0, |
| 185 InstructionOperand* inputs = nullptr, | 189 InstructionOperand* inputs = nullptr, |
| 186 size_t temps_size = 0, | 190 size_t temps_size = 0, |
| 187 InstructionOperand* temps = nullptr); | 191 InstructionOperand* temps = nullptr); |
| 188 InstructionOperand Unallocated(TestOperand op, | 192 InstructionOperand Unallocated(TestOperand op, |
| 189 UnallocatedOperand::ExtendedPolicy policy); | 193 UnallocatedOperand::ExtendedPolicy policy); |
| 190 InstructionOperand Unallocated(TestOperand op, | 194 InstructionOperand Unallocated(TestOperand op, |
| 191 UnallocatedOperand::ExtendedPolicy policy, | 195 UnallocatedOperand::ExtendedPolicy policy, |
| 192 UnallocatedOperand::Lifetime lifetime); | 196 UnallocatedOperand::Lifetime lifetime); |
| 193 InstructionOperand Unallocated(TestOperand op, | 197 InstructionOperand Unallocated(TestOperand op, |
| 194 UnallocatedOperand::ExtendedPolicy policy, | 198 UnallocatedOperand::ExtendedPolicy policy, |
| 195 int index); | 199 int index); |
| 196 InstructionOperand Unallocated(TestOperand op, | 200 InstructionOperand Unallocated(TestOperand op, |
| 197 UnallocatedOperand::BasicPolicy policy, | 201 UnallocatedOperand::BasicPolicy policy, |
| 198 int index); | 202 int index); |
| 199 InstructionOperand* ConvertInputs(size_t input_size, TestOperand* inputs); | 203 InstructionOperand* ConvertInputs(size_t input_size, TestOperand* inputs); |
| 200 InstructionOperand ConvertInputOp(TestOperand op); | 204 InstructionOperand ConvertInputOp(TestOperand op); |
| 201 InstructionOperand ConvertOutputOp(VReg vreg, TestOperand op); | 205 InstructionOperand ConvertOutputOp(VReg vreg, TestOperand op); |
| 202 InstructionBlock* NewBlock(); | 206 InstructionBlock* NewBlock(); |
| 203 void WireBlock(size_t block_offset, int jump_offset); | 207 void WireBlock(size_t block_offset, int jump_offset); |
| 204 | 208 |
| 205 int Emit(int instruction_index, InstructionCode code, size_t outputs_size = 0, | 209 Instruction* Emit(InstructionCode code, size_t outputs_size = 0, |
| 206 InstructionOperand* outputs = nullptr, size_t inputs_size = 0, | 210 InstructionOperand* outputs = nullptr, |
| 207 InstructionOperand* inputs = nullptr, size_t temps_size = 0, | 211 size_t inputs_size = 0, |
| 208 InstructionOperand* temps = nullptr, bool is_call = false); | 212 InstructionOperand* inputs = nullptr, size_t temps_size = 0, |
| 213 InstructionOperand* temps = nullptr, bool is_call = false); |
| 209 | 214 |
| 210 int AddInstruction(int instruction_index, Instruction* instruction); | 215 Instruction* AddInstruction(Instruction* instruction); |
| 211 | 216 |
| 212 struct LoopData { | 217 struct LoopData { |
| 213 Rpo loop_header_; | 218 Rpo loop_header_; |
| 214 int expected_blocks_; | 219 int expected_blocks_; |
| 215 }; | 220 }; |
| 216 | 221 |
| 217 typedef std::vector<LoopData> LoopBlocks; | 222 typedef std::vector<LoopData> LoopBlocks; |
| 218 typedef std::map<int, const Instruction*> Instructions; | 223 typedef std::map<int, const Instruction*> Instructions; |
| 219 typedef std::vector<BlockCompletion> Completions; | 224 typedef std::vector<BlockCompletion> Completions; |
| 220 | 225 |
| 221 SmartPointer<RegisterConfiguration> config_; | 226 SmartPointer<RegisterConfiguration> config_; |
| 222 InstructionSequence* sequence_; | 227 InstructionSequence* sequence_; |
| 223 int num_general_registers_; | 228 int num_general_registers_; |
| 224 int num_double_registers_; | 229 int num_double_registers_; |
| 225 | 230 |
| 226 // Block building state. | 231 // Block building state. |
| 227 InstructionBlocks instruction_blocks_; | 232 InstructionBlocks instruction_blocks_; |
| 228 Instructions instructions_; | 233 Instructions instructions_; |
| 229 int current_instruction_index_; | |
| 230 Completions completions_; | 234 Completions completions_; |
| 231 LoopBlocks loop_blocks_; | 235 LoopBlocks loop_blocks_; |
| 232 InstructionBlock* current_block_; | 236 InstructionBlock* current_block_; |
| 233 bool block_returns_; | 237 bool block_returns_; |
| 234 }; | 238 }; |
| 235 | 239 |
| 236 } // namespace compiler | 240 } // namespace compiler |
| 237 } // namespace internal | 241 } // namespace internal |
| 238 } // namespace v8 | 242 } // namespace v8 |
| 239 | 243 |
| 240 #endif // V8_UNITTESTS_COMPILER_INSTRUCTION_SEQUENCE_UNITTEST_H_ | 244 #endif // V8_UNITTESTS_COMPILER_INSTRUCTION_SEQUENCE_UNITTEST_H_ |
| OLD | NEW |