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/base/utils/random-number-generator.h" | 5 #include "src/base/utils/random-number-generator.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 #include "test/unittests/test-utils.h" | 8 #include "test/unittests/test-utils.h" |
9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
10 | 10 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 sequence()->AddConstant(vreg.value_, Constant(imm)); | 177 sequence()->AddConstant(vreg.value_, Constant(imm)); |
178 InstructionOperand* outputs[1]{ConstantOperand::Create(vreg.value_, zone())}; | 178 InstructionOperand* outputs[1]{ConstantOperand::Create(vreg.value_, zone())}; |
179 Emit(vreg.value_, kArchNop, 1, outputs); | 179 Emit(vreg.value_, kArchNop, 1, outputs); |
180 return vreg; | 180 return vreg; |
181 } | 181 } |
182 | 182 |
183 | 183 |
184 int InstructionSequenceTest::EmitNop() { return Emit(NewIndex(), kArchNop); } | 184 int InstructionSequenceTest::EmitNop() { return Emit(NewIndex(), kArchNop); } |
185 | 185 |
186 | 186 |
187 int InstructionSequenceTest::EmitI(TestOperand input_op_0) { | 187 static size_t CountInputs(size_t size, |
188 InstructionOperand* inputs[1]{ConvertInputOp(input_op_0)}; | 188 InstructionSequenceTest::TestOperand* inputs) { |
189 return Emit(NewIndex(), kArchNop, 0, nullptr, 1, inputs); | 189 size_t i = 0; |
| 190 for (; i < size; ++i) { |
| 191 if (inputs[i].type_ == InstructionSequenceTest::kInvalid) break; |
| 192 } |
| 193 return i; |
| 194 } |
| 195 |
| 196 |
| 197 int InstructionSequenceTest::EmitI(size_t input_size, TestOperand* inputs) { |
| 198 InstructionOperand** mapped_inputs = ConvertInputs(input_size, inputs); |
| 199 return Emit(NewIndex(), kArchNop, 0, nullptr, input_size, mapped_inputs); |
| 200 } |
| 201 |
| 202 |
| 203 int InstructionSequenceTest::EmitI(TestOperand input_op_0, |
| 204 TestOperand input_op_1, |
| 205 TestOperand input_op_2, |
| 206 TestOperand input_op_3) { |
| 207 TestOperand inputs[] = {input_op_0, input_op_1, input_op_2, input_op_3}; |
| 208 return EmitI(CountInputs(arraysize(inputs), inputs), inputs); |
190 } | 209 } |
191 | 210 |
192 | 211 |
193 InstructionSequenceTest::VReg InstructionSequenceTest::EmitOI( | 212 InstructionSequenceTest::VReg InstructionSequenceTest::EmitOI( |
194 TestOperand output_op, TestOperand input_op_0) { | 213 TestOperand output_op, size_t input_size, TestOperand* inputs) { |
195 VReg output_vreg = NewReg(); | 214 VReg output_vreg = NewReg(); |
196 InstructionOperand* outputs[1]{ConvertOutputOp(output_vreg, output_op)}; | 215 InstructionOperand* outputs[1]{ConvertOutputOp(output_vreg, output_op)}; |
197 InstructionOperand* inputs[1]{ConvertInputOp(input_op_0)}; | 216 InstructionOperand** mapped_inputs = ConvertInputs(input_size, inputs); |
198 Emit(output_vreg.value_, kArchNop, 1, outputs, 1, inputs); | 217 Emit(output_vreg.value_, kArchNop, 1, outputs, input_size, mapped_inputs); |
199 return output_vreg; | 218 return output_vreg; |
200 } | 219 } |
201 | 220 |
202 | 221 |
203 InstructionSequenceTest::VReg InstructionSequenceTest::EmitOII( | 222 InstructionSequenceTest::VReg InstructionSequenceTest::EmitOI( |
204 TestOperand output_op, TestOperand input_op_0, TestOperand input_op_1) { | 223 TestOperand output_op, TestOperand input_op_0, TestOperand input_op_1, |
205 VReg output_vreg = NewReg(); | 224 TestOperand input_op_2, TestOperand input_op_3) { |
206 InstructionOperand* outputs[1]{ConvertOutputOp(output_vreg, output_op)}; | 225 TestOperand inputs[] = {input_op_0, input_op_1, input_op_2, input_op_3}; |
207 InstructionOperand* inputs[2]{ConvertInputOp(input_op_0), | 226 return EmitOI(output_op, CountInputs(arraysize(inputs), inputs), inputs); |
208 ConvertInputOp(input_op_1)}; | |
209 Emit(output_vreg.value_, kArchNop, 1, outputs, 2, inputs); | |
210 return output_vreg; | |
211 } | 227 } |
212 | 228 |
213 | 229 |
214 InstructionSequenceTest::VReg InstructionSequenceTest::EmitCall( | 230 InstructionSequenceTest::VReg InstructionSequenceTest::EmitCall( |
215 TestOperand output_op, size_t input_size, TestOperand* inputs) { | 231 TestOperand output_op, size_t input_size, TestOperand* inputs) { |
216 VReg output_vreg = NewReg(); | 232 VReg output_vreg = NewReg(); |
217 InstructionOperand* outputs[1]{ConvertOutputOp(output_vreg, output_op)}; | 233 InstructionOperand* outputs[1]{ConvertOutputOp(output_vreg, output_op)}; |
218 CHECK(UnallocatedOperand::cast(outputs[0])->HasFixedPolicy()); | 234 CHECK(UnallocatedOperand::cast(outputs[0])->HasFixedPolicy()); |
219 InstructionOperand** mapped_inputs = | 235 InstructionOperand** mapped_inputs = ConvertInputs(input_size, inputs); |
220 zone()->NewArray<InstructionOperand*>(static_cast<int>(input_size)); | |
221 for (size_t i = 0; i < input_size; ++i) { | |
222 mapped_inputs[i] = ConvertInputOp(inputs[i]); | |
223 } | |
224 Emit(output_vreg.value_, kArchCallCodeObject, 1, outputs, input_size, | 236 Emit(output_vreg.value_, kArchCallCodeObject, 1, outputs, input_size, |
225 mapped_inputs, 0, nullptr, true); | 237 mapped_inputs, 0, nullptr, true); |
226 return output_vreg; | 238 return output_vreg; |
227 } | 239 } |
228 | 240 |
229 | 241 |
230 InstructionSequenceTest::VReg InstructionSequenceTest::EmitCall( | 242 InstructionSequenceTest::VReg InstructionSequenceTest::EmitCall( |
231 TestOperand output_op, TestOperand input_op_0, TestOperand input_op_1, | 243 TestOperand output_op, TestOperand input_op_0, TestOperand input_op_1, |
232 TestOperand input_op_2, TestOperand input_op_3) { | 244 TestOperand input_op_2, TestOperand input_op_3) { |
233 TestOperand inputs[] = {input_op_0, input_op_1, input_op_2, input_op_3}; | 245 TestOperand inputs[] = {input_op_0, input_op_1, input_op_2, input_op_3}; |
234 size_t size = 0; | 246 return EmitCall(output_op, CountInputs(arraysize(inputs), inputs), inputs); |
235 for (; size < arraysize(inputs); ++size) { | |
236 if (inputs[size].type_ == kInvalid) break; | |
237 } | |
238 return EmitCall(output_op, size, inputs); | |
239 } | 247 } |
240 | 248 |
241 | 249 |
242 const Instruction* InstructionSequenceTest::GetInstruction( | 250 const Instruction* InstructionSequenceTest::GetInstruction( |
243 int instruction_index) { | 251 int instruction_index) { |
244 auto it = instructions_.find(instruction_index); | 252 auto it = instructions_.find(instruction_index); |
245 CHECK(it != instructions_.end()); | 253 CHECK(it != instructions_.end()); |
246 return it->second; | 254 return it->second; |
247 } | 255 } |
248 | 256 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 316 |
309 | 317 |
310 InstructionOperand* InstructionSequenceTest::Unallocated( | 318 InstructionOperand* InstructionSequenceTest::Unallocated( |
311 TestOperand op, UnallocatedOperand::BasicPolicy policy, int index) { | 319 TestOperand op, UnallocatedOperand::BasicPolicy policy, int index) { |
312 auto unallocated = new (zone()) UnallocatedOperand(policy, index); | 320 auto unallocated = new (zone()) UnallocatedOperand(policy, index); |
313 unallocated->set_virtual_register(op.vreg_.value_); | 321 unallocated->set_virtual_register(op.vreg_.value_); |
314 return unallocated; | 322 return unallocated; |
315 } | 323 } |
316 | 324 |
317 | 325 |
| 326 InstructionOperand** InstructionSequenceTest::ConvertInputs( |
| 327 size_t input_size, TestOperand* inputs) { |
| 328 InstructionOperand** mapped_inputs = |
| 329 zone()->NewArray<InstructionOperand*>(static_cast<int>(input_size)); |
| 330 for (size_t i = 0; i < input_size; ++i) { |
| 331 mapped_inputs[i] = ConvertInputOp(inputs[i]); |
| 332 } |
| 333 return mapped_inputs; |
| 334 } |
| 335 |
| 336 |
318 InstructionOperand* InstructionSequenceTest::ConvertInputOp(TestOperand op) { | 337 InstructionOperand* InstructionSequenceTest::ConvertInputOp(TestOperand op) { |
319 if (op.type_ == kImmediate) { | 338 if (op.type_ == kImmediate) { |
320 CHECK_EQ(op.vreg_.value_, kNoValue); | 339 CHECK_EQ(op.vreg_.value_, kNoValue); |
321 return ImmediateOperand::Create(op.value_, zone()); | 340 return ImmediateOperand::Create(op.value_, zone()); |
322 } | 341 } |
323 CHECK_NE(op.vreg_.value_, kNoValue); | 342 CHECK_NE(op.vreg_.value_, kNoValue); |
324 switch (op.type_) { | 343 switch (op.type_) { |
325 case kNone: | 344 case kNone: |
326 return Unallocated(op, UnallocatedOperand::NONE, | 345 return Unallocated(op, UnallocatedOperand::NONE, |
327 UnallocatedOperand::USED_AT_START); | 346 UnallocatedOperand::USED_AT_START); |
| 347 case kUnique: |
| 348 return Unallocated(op, UnallocatedOperand::NONE); |
| 349 case kUniqueRegister: |
| 350 return Unallocated(op, UnallocatedOperand::MUST_HAVE_REGISTER); |
328 case kRegister: | 351 case kRegister: |
329 return Unallocated(op, UnallocatedOperand::MUST_HAVE_REGISTER, | 352 return Unallocated(op, UnallocatedOperand::MUST_HAVE_REGISTER, |
330 UnallocatedOperand::USED_AT_START); | 353 UnallocatedOperand::USED_AT_START); |
331 case kFixedRegister: | 354 case kFixedRegister: |
332 CHECK(0 <= op.value_ && op.value_ < num_general_registers_); | 355 CHECK(0 <= op.value_ && op.value_ < num_general_registers_); |
333 return Unallocated(op, UnallocatedOperand::FIXED_REGISTER, op.value_); | 356 return Unallocated(op, UnallocatedOperand::FIXED_REGISTER, op.value_); |
334 case kFixedSlot: | 357 case kFixedSlot: |
335 return Unallocated(op, UnallocatedOperand::FIXED_SLOT, op.value_); | 358 return Unallocated(op, UnallocatedOperand::FIXED_SLOT, op.value_); |
336 default: | 359 default: |
337 break; | 360 break; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 466 |
444 int InstructionSequenceTest::AddInstruction(int instruction_index, | 467 int InstructionSequenceTest::AddInstruction(int instruction_index, |
445 Instruction* instruction) { | 468 Instruction* instruction) { |
446 sequence()->AddInstruction(instruction); | 469 sequence()->AddInstruction(instruction); |
447 return instruction_index; | 470 return instruction_index; |
448 } | 471 } |
449 | 472 |
450 } // namespace compiler | 473 } // namespace compiler |
451 } // namespace internal | 474 } // namespace internal |
452 } // namespace v8 | 475 } // namespace v8 |
OLD | NEW |