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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/interpreter/bytecode-array-builder.h" | 7 #include "src/interpreter/bytecode-array-builder.h" |
8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
| 9 #include "src/interpreter/bytecode-register-allocator.h" |
9 #include "test/unittests/test-utils.h" | 10 #include "test/unittests/test-utils.h" |
10 | 11 |
11 namespace v8 { | 12 namespace v8 { |
12 namespace internal { | 13 namespace internal { |
13 namespace interpreter { | 14 namespace interpreter { |
14 | 15 |
15 class BytecodeArrayBuilderTest : public TestWithIsolateAndZone { | 16 class BytecodeArrayBuilderTest : public TestWithIsolateAndZone { |
16 public: | 17 public: |
17 BytecodeArrayBuilderTest() {} | 18 BytecodeArrayBuilderTest() {} |
18 ~BytecodeArrayBuilderTest() override {} | 19 ~BytecodeArrayBuilderTest() override {} |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 311 |
311 TEST_F(BytecodeArrayBuilderTest, FrameSizesLookGood) { | 312 TEST_F(BytecodeArrayBuilderTest, FrameSizesLookGood) { |
312 for (int locals = 0; locals < 5; locals++) { | 313 for (int locals = 0; locals < 5; locals++) { |
313 for (int contexts = 0; contexts < 4; contexts++) { | 314 for (int contexts = 0; contexts < 4; contexts++) { |
314 for (int temps = 0; temps < 3; temps++) { | 315 for (int temps = 0; temps < 3; temps++) { |
315 BytecodeArrayBuilder builder(isolate(), zone()); | 316 BytecodeArrayBuilder builder(isolate(), zone()); |
316 builder.set_parameter_count(0); | 317 builder.set_parameter_count(0); |
317 builder.set_locals_count(locals); | 318 builder.set_locals_count(locals); |
318 builder.set_context_count(contexts); | 319 builder.set_context_count(contexts); |
319 | 320 |
320 TemporaryRegisterScope temporaries(&builder); | 321 BytecodeRegisterAllocator temporaries(&builder); |
321 for (int i = 0; i < temps; i++) { | 322 for (int i = 0; i < temps; i++) { |
322 builder.StoreAccumulatorInRegister(temporaries.NewRegister()); | 323 builder.StoreAccumulatorInRegister(temporaries.NewRegister()); |
323 } | 324 } |
324 builder.Return(); | 325 builder.Return(); |
325 | 326 |
326 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(); | 327 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(); |
327 int total_registers = locals + contexts + temps; | 328 int total_registers = locals + contexts + temps; |
328 CHECK_EQ(the_array->frame_size(), total_registers * kPointerSize); | 329 CHECK_EQ(the_array->frame_size(), total_registers * kPointerSize); |
329 } | 330 } |
330 } | 331 } |
331 } | 332 } |
332 } | 333 } |
333 | 334 |
334 | 335 |
335 TEST_F(BytecodeArrayBuilderTest, TemporariesRecycled) { | |
336 BytecodeArrayBuilder builder(isolate(), zone()); | |
337 builder.set_parameter_count(0); | |
338 builder.set_locals_count(0); | |
339 builder.set_context_count(0); | |
340 builder.Return(); | |
341 | |
342 int first; | |
343 { | |
344 TemporaryRegisterScope temporaries(&builder); | |
345 first = temporaries.NewRegister().index(); | |
346 temporaries.NewRegister(); | |
347 temporaries.NewRegister(); | |
348 temporaries.NewRegister(); | |
349 } | |
350 | |
351 int second; | |
352 { | |
353 TemporaryRegisterScope temporaries(&builder); | |
354 second = temporaries.NewRegister().index(); | |
355 } | |
356 | |
357 CHECK_EQ(first, second); | |
358 } | |
359 | |
360 | |
361 TEST_F(BytecodeArrayBuilderTest, RegisterValues) { | 336 TEST_F(BytecodeArrayBuilderTest, RegisterValues) { |
362 int index = 1; | 337 int index = 1; |
363 uint8_t operand = static_cast<uint8_t>(-index); | 338 uint8_t operand = static_cast<uint8_t>(-index); |
364 | 339 |
365 Register the_register(index); | 340 Register the_register(index); |
366 CHECK_EQ(the_register.index(), index); | 341 CHECK_EQ(the_register.index(), index); |
367 | 342 |
368 int actual_operand = the_register.ToOperand(); | 343 int actual_operand = the_register.ToOperand(); |
369 CHECK_EQ(actual_operand, operand); | 344 CHECK_EQ(actual_operand, operand); |
370 | 345 |
(...skipping 13 matching lines...) Expand all Loading... |
384 CHECK_EQ(param9.index() - param0.index(), 9); | 359 CHECK_EQ(param9.index() - param0.index(), 9); |
385 } | 360 } |
386 | 361 |
387 | 362 |
388 TEST_F(BytecodeArrayBuilderTest, RegisterType) { | 363 TEST_F(BytecodeArrayBuilderTest, RegisterType) { |
389 BytecodeArrayBuilder builder(isolate(), zone()); | 364 BytecodeArrayBuilder builder(isolate(), zone()); |
390 builder.set_parameter_count(10); | 365 builder.set_parameter_count(10); |
391 builder.set_locals_count(3); | 366 builder.set_locals_count(3); |
392 builder.set_context_count(0); | 367 builder.set_context_count(0); |
393 | 368 |
394 TemporaryRegisterScope temporary_register_scope(&builder); | 369 BytecodeRegisterAllocator register_allocator(&builder); |
395 Register temp0 = temporary_register_scope.NewRegister(); | 370 Register temp0 = register_allocator.NewRegister(); |
396 Register param0(builder.Parameter(0)); | 371 Register param0(builder.Parameter(0)); |
397 Register param9(builder.Parameter(9)); | 372 Register param9(builder.Parameter(9)); |
398 Register temp1 = temporary_register_scope.NewRegister(); | 373 Register temp1 = register_allocator.NewRegister(); |
399 Register reg0(0); | 374 Register reg0(0); |
400 Register reg1(1); | 375 Register reg1(1); |
401 Register reg2(2); | 376 Register reg2(2); |
402 Register temp2 = temporary_register_scope.NewRegister(); | 377 Register temp2 = register_allocator.NewRegister(); |
403 CHECK_EQ(builder.RegisterIsParameterOrLocal(temp0), false); | 378 CHECK_EQ(builder.RegisterIsParameterOrLocal(temp0), false); |
404 CHECK_EQ(builder.RegisterIsParameterOrLocal(temp1), false); | 379 CHECK_EQ(builder.RegisterIsParameterOrLocal(temp1), false); |
405 CHECK_EQ(builder.RegisterIsParameterOrLocal(temp2), false); | 380 CHECK_EQ(builder.RegisterIsParameterOrLocal(temp2), false); |
406 CHECK_EQ(builder.RegisterIsParameterOrLocal(param0), true); | 381 CHECK_EQ(builder.RegisterIsParameterOrLocal(param0), true); |
407 CHECK_EQ(builder.RegisterIsParameterOrLocal(param9), true); | 382 CHECK_EQ(builder.RegisterIsParameterOrLocal(param9), true); |
408 CHECK_EQ(builder.RegisterIsParameterOrLocal(reg0), true); | 383 CHECK_EQ(builder.RegisterIsParameterOrLocal(reg0), true); |
409 CHECK_EQ(builder.RegisterIsParameterOrLocal(reg1), true); | 384 CHECK_EQ(builder.RegisterIsParameterOrLocal(reg1), true); |
410 CHECK_EQ(builder.RegisterIsParameterOrLocal(reg2), true); | 385 CHECK_EQ(builder.RegisterIsParameterOrLocal(reg2), true); |
411 } | 386 } |
412 | 387 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 } | 683 } |
709 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); | 684 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); |
710 iterator.Advance(); | 685 iterator.Advance(); |
711 CHECK(iterator.done()); | 686 CHECK(iterator.done()); |
712 } | 687 } |
713 | 688 |
714 | 689 |
715 } // namespace interpreter | 690 } // namespace interpreter |
716 } // namespace internal | 691 } // namespace internal |
717 } // namespace v8 | 692 } // namespace v8 |
OLD | NEW |