OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 if (count > 0) { | 506 if (count > 0) { |
507 Comment cmnt(masm(), "[ Allocate space for locals"); | 507 Comment cmnt(masm(), "[ Allocate space for locals"); |
508 // The locals are initialized to a constant (the undefined value), but | 508 // The locals are initialized to a constant (the undefined value), but |
509 // we sync them with the actual frame to allocate space for spilling | 509 // we sync them with the actual frame to allocate space for spilling |
510 // them later. First sync everything above the stack pointer so we can | 510 // them later. First sync everything above the stack pointer so we can |
511 // use pushes to allocate and initialize the locals. | 511 // use pushes to allocate and initialize the locals. |
512 SyncRange(stack_pointer_ + 1, element_count() - 1); | 512 SyncRange(stack_pointer_ + 1, element_count() - 1); |
513 Handle<Object> undefined = Factory::undefined_value(); | 513 Handle<Object> undefined = Factory::undefined_value(); |
514 FrameElement initial_value = | 514 FrameElement initial_value = |
515 FrameElement::ConstantElement(undefined, FrameElement::SYNCED); | 515 FrameElement::ConstantElement(undefined, FrameElement::SYNCED); |
516 Result temp = cgen()->allocator()->Allocate(); | 516 if (count == 1) { |
517 ASSERT(temp.is_valid()); | 517 __ push(Immediate(undefined)); |
518 __ Set(temp.reg(), Immediate(undefined)); | 518 } else if (count < kLocalVarBound) { |
| 519 // For less locals the unrolled loop is more compact. |
| 520 Result temp = cgen()->allocator()->Allocate(); |
| 521 ASSERT(temp.is_valid()); |
| 522 __ Set(temp.reg(), Immediate(undefined)); |
| 523 for (int i = 0; i < count; i++) { |
| 524 __ push(temp.reg()); |
| 525 } |
| 526 } else { |
| 527 // For more locals a loop in generated code is more compact. |
| 528 Label alloc_locals_loop; |
| 529 Result cnt = cgen()->allocator()->Allocate(); |
| 530 Result tmp = cgen()->allocator()->Allocate(); |
| 531 ASSERT(cnt.is_valid()); |
| 532 ASSERT(tmp.is_valid()); |
| 533 __ mov(cnt.reg(), Immediate(count)); |
| 534 __ mov(tmp.reg(), Immediate(undefined)); |
| 535 __ bind(&alloc_locals_loop); |
| 536 __ push(tmp.reg()); |
| 537 __ dec(cnt.reg()); |
| 538 __ j(not_zero, &alloc_locals_loop); |
| 539 } |
519 for (int i = 0; i < count; i++) { | 540 for (int i = 0; i < count; i++) { |
520 elements_.Add(initial_value); | 541 elements_.Add(initial_value); |
521 stack_pointer_++; | 542 stack_pointer_++; |
522 __ push(temp.reg()); | |
523 } | 543 } |
524 } | 544 } |
525 } | 545 } |
526 | 546 |
527 | 547 |
528 void VirtualFrame::SaveContextRegister() { | 548 void VirtualFrame::SaveContextRegister() { |
529 ASSERT(elements_[context_index()].is_memory()); | 549 ASSERT(elements_[context_index()].is_memory()); |
530 __ mov(Operand(ebp, fp_relative(context_index())), esi); | 550 __ mov(Operand(ebp, fp_relative(context_index())), esi); |
531 } | 551 } |
532 | 552 |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 ASSERT(stack_pointer_ == element_count() - 1); | 1096 ASSERT(stack_pointer_ == element_count() - 1); |
1077 elements_.Add(FrameElement::MemoryElement()); | 1097 elements_.Add(FrameElement::MemoryElement()); |
1078 stack_pointer_++; | 1098 stack_pointer_++; |
1079 __ push(immediate); | 1099 __ push(immediate); |
1080 } | 1100 } |
1081 | 1101 |
1082 | 1102 |
1083 #undef __ | 1103 #undef __ |
1084 | 1104 |
1085 } } // namespace v8::internal | 1105 } } // namespace v8::internal |
OLD | NEW |